aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorHongli Lai (Phusion) <hongli@phusion.nl>2008-12-09 01:38:17 +0100
committerHongli Lai (Phusion) <hongli@phusion.nl>2008-12-09 01:38:17 +0100
commit13c6c3cfc59ff0b400b294dce15f32752b0fb5f5 (patch)
tree052ac9c8f4adb91a4b32e3b2a97b1bc6bdace2e6 /activesupport
parentccb96f2297e8783165cba764e9b5d51e1a15ff87 (diff)
parent4e60eebae05aeec65e4894e3901c9d61c9b32910 (diff)
downloadrails-13c6c3cfc59ff0b400b294dce15f32752b0fb5f5.tar.gz
rails-13c6c3cfc59ff0b400b294dce15f32752b0fb5f5.tar.bz2
rails-13c6c3cfc59ff0b400b294dce15f32752b0fb5f5.zip
Merge commit 'origin/master' into savepoints
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG4
-rw-r--r--activesupport/lib/active_support/buffered_logger.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/array/conversions.rb19
-rw-r--r--activesupport/lib/active_support/core_ext/exception.rb19
-rw-r--r--activesupport/lib/active_support/core_ext/logger.rb2
-rw-r--r--activesupport/lib/active_support/inflector.rb2
-rw-r--r--activesupport/lib/active_support/locale/en.yml5
-rw-r--r--activesupport/lib/active_support/multibyte/chars.rb8
-rw-r--r--activesupport/test/core_ext/array_ext_test.rb19
-rw-r--r--activesupport/test/i18n_test.rb21
-rw-r--r--activesupport/test/multibyte_chars_test.rb4
11 files changed, 70 insertions, 35 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index d142f21d61..0e796d802c 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,9 @@
*2.3.0 [Edge]*
+* Multibyte: add multibyte-safe Chars#ord rather than falling back to String#ord. #1483 [Jason Cheow]
+
+* I18n support for Array#to_sentence. Introduces support.array.words_connector, .two_words_connector, and .last_word_connector translation keys. #1397 [Akira Matsuda]
+
* Added ActiveSupport::OrderedHash#each_key and ActiveSupport::OrderedHash#each_value #1410 [Christoffer Sawicki]
* Added ActiveSupport::MessageVerifier and MessageEncryptor to aid users who need to store signed and/or encrypted messages. [Koz]
diff --git a/activesupport/lib/active_support/buffered_logger.rb b/activesupport/lib/active_support/buffered_logger.rb
index 77e0b1d33f..b2c863c893 100644
--- a/activesupport/lib/active_support/buffered_logger.rb
+++ b/activesupport/lib/active_support/buffered_logger.rb
@@ -13,6 +13,8 @@ module ActiveSupport
MAX_BUFFER_SIZE = 1000
+ ##
+ # :singleton-method:
# Set to false to disable the silencer
cattr_accessor :silencer
self.silencer = true
diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb
index f0d6591135..69d35dafd3 100644
--- a/activesupport/lib/active_support/core_ext/array/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/array/conversions.rb
@@ -3,15 +3,16 @@ module ActiveSupport #:nodoc:
module Array #:nodoc:
module Conversions
# Converts the array to a comma-separated sentence where the last element is joined by the connector word. Options:
- # * <tt>:connector</tt> - The word used to join the last element in arrays with two or more elements (default: "and")
- # * <tt>:skip_last_comma</tt> - Set to true to return "a, b and c" instead of "a, b, and c".
+ # * <tt>:words_connector</tt> - The sign or word used to join the elements in arrays with two or more elements (default: ", ")
+ # * <tt>:two_words_connector</tt> - The sign or word used to join the elements in arrays with two elements (default: " and ")
+ # * <tt>:last_word_connector</tt> - The sign or word used to join the last element in arrays with three or more elements (default: ", and ")
def to_sentence(options = {})
- options.assert_valid_keys(:connector, :skip_last_comma, :locale)
+ options.assert_valid_keys(:words_connector, :two_words_connector, :last_word_connector, :locale)
- default = I18n.translate(:'support.array.sentence_connector', :locale => options[:locale])
- default_skip_last_comma = I18n.translate(:'support.array.skip_last_comma', :locale => options[:locale])
- options.reverse_merge! :connector => default, :skip_last_comma => default_skip_last_comma
- options[:connector] = "#{options[:connector]} " unless options[:connector].nil? || options[:connector].strip == ''
+ default_words_connector = I18n.translate(:'support.array.words_connector', :locale => options[:locale])
+ default_two_words_connector = I18n.translate(:'support.array.two_words_connector', :locale => options[:locale])
+ default_last_word_connector = I18n.translate(:'support.array.last_word_connector', :locale => options[:locale])
+ options.reverse_merge! :words_connector => default_words_connector, :two_words_connector => default_two_words_connector, :last_word_connector => default_last_word_connector
case length
when 0
@@ -19,9 +20,9 @@ module ActiveSupport #:nodoc:
when 1
self[0].to_s
when 2
- "#{self[0]} #{options[:connector]}#{self[1]}"
+ "#{self[0]}#{options[:two_words_connector]}#{self[1]}"
else
- "#{self[0...-1].join(', ')}#{options[:skip_last_comma] ? '' : ','} #{options[:connector]}#{self[-1]}"
+ "#{self[0...-1].join(options[:words_connector])}#{options[:last_word_connector]}#{self[-1]}"
end
end
diff --git a/activesupport/lib/active_support/core_ext/exception.rb b/activesupport/lib/active_support/core_ext/exception.rb
index 73470cbe05..cde0df4153 100644
--- a/activesupport/lib/active_support/core_ext/exception.rb
+++ b/activesupport/lib/active_support/core_ext/exception.rb
@@ -11,10 +11,11 @@ class Exception # :nodoc:
def clean_message
Pathname.clean_within message
end
-
+
TraceSubstitutions = []
- FrameworkRegexp = /generated|vendor|dispatch|ruby|script\/\w+/
-
+ FrameworkStart = /action_controller\/dispatcher\.rb/.freeze
+ FrameworkRegexp = /generated|vendor|dispatch|ruby|script\/\w+/.freeze
+
def clean_backtrace
backtrace.collect do |line|
Pathname.clean_within(TraceSubstitutions.inject(line) do |result, (regexp, sub)|
@@ -22,20 +23,22 @@ class Exception # :nodoc:
end)
end
end
-
+
def application_backtrace
+ before_framework_frame = nil
before_application_frame = true
-
+
trace = clean_backtrace.reject do |line|
+ before_framework_frame ||= (line =~ FrameworkStart)
non_app_frame = (line =~ FrameworkRegexp)
before_application_frame = false unless non_app_frame
- non_app_frame && ! before_application_frame
+ before_framework_frame || (non_app_frame && !before_application_frame)
end
-
+
# If we didn't find any application frames, return an empty app trace.
before_application_frame ? [] : trace
end
-
+
def framework_backtrace
clean_backtrace.grep FrameworkRegexp
end
diff --git a/activesupport/lib/active_support/core_ext/logger.rb b/activesupport/lib/active_support/core_ext/logger.rb
index c622554860..24fe7294c9 100644
--- a/activesupport/lib/active_support/core_ext/logger.rb
+++ b/activesupport/lib/active_support/core_ext/logger.rb
@@ -30,6 +30,8 @@ require 'logger'
#
# Note: This logger is deprecated in favor of ActiveSupport::BufferedLogger
class Logger
+ ##
+ # :singleton-method:
# Set to false to disable the silencer
cattr_accessor :silencer
self.silencer = true
diff --git a/activesupport/lib/active_support/inflector.rb b/activesupport/lib/active_support/inflector.rb
index 683af4556e..4921b99677 100644
--- a/activesupport/lib/active_support/inflector.rb
+++ b/activesupport/lib/active_support/inflector.rb
@@ -254,7 +254,7 @@ module ActiveSupport
# @person = Person.find(1)
# # => #<Person id: 1, name: "Donald E. Knuth">
#
- # <%= link_to(@person.name, person_path %>
+ # <%= link_to(@person.name, person_path(@person)) %>
# # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a>
def parameterize(string, sep = '-')
re_sep = Regexp.escape(sep)
diff --git a/activesupport/lib/active_support/locale/en.yml b/activesupport/lib/active_support/locale/en.yml
index 92132cacd5..e604c9ee8c 100644
--- a/activesupport/lib/active_support/locale/en.yml
+++ b/activesupport/lib/active_support/locale/en.yml
@@ -28,5 +28,6 @@ en:
# Used in array.to_sentence.
support:
array:
- sentence_connector: "and"
- skip_last_comma: false
+ words_connector: ", "
+ two_words_connector: " and "
+ last_word_connector: ", and "
diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb
index be9c6d3567..a00b165222 100644
--- a/activesupport/lib/active_support/multibyte/chars.rb
+++ b/activesupport/lib/active_support/multibyte/chars.rb
@@ -344,6 +344,14 @@ module ActiveSupport #:nodoc:
end
alias_method :[], :slice
+ # Converts first character in the string to Unicode value
+ #
+ # Example:
+ # 'こんにちは'.mb_chars.ord #=> 12371
+ def ord
+ self.class.u_unpack(@wrapped_string)[0]
+ end
+
# Convert characters in the string to uppercase.
#
# Example:
diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb
index 01b243cdb5..93f4482307 100644
--- a/activesupport/test/core_ext/array_ext_test.rb
+++ b/activesupport/test/core_ext/array_ext_test.rb
@@ -55,21 +55,22 @@ class ArrayExtToSentenceTests < Test::Unit::TestCase
assert_equal "one, two, and three", ['one', 'two', 'three'].to_sentence
end
- def test_to_sentence_with_connector
- assert_equal "one, two, and also three", ['one', 'two', 'three'].to_sentence(:connector => 'and also')
- assert_equal "one, two, three", ['one', 'two', 'three'].to_sentence(:connector => '')
- assert_equal "one, two, three", ['one', 'two', 'three'].to_sentence(:connector => nil)
- assert_equal "one, two, three", ['one', 'two', 'three'].to_sentence(:connector => ' ')
- assert_equal "one, two, and three", ['one', 'two', 'three'].to_sentence(:connector => 'and ')
+ def test_to_sentence_with_words_connector
+ assert_equal "one two, and three", ['one', 'two', 'three'].to_sentence(:words_connector => ' ')
+ assert_equal "one & two, and three", ['one', 'two', 'three'].to_sentence(:words_connector => ' & ')
+ assert_equal "onetwo, and three", ['one', 'two', 'three'].to_sentence(:words_connector => nil)
end
- def test_to_sentence_with_skip_last_comma
- assert_equal "one, two, and three", ['one', 'two', 'three'].to_sentence(:skip_last_comma => false)
+ def test_to_sentence_with_last_word_connector
+ assert_equal "one, two, and also three", ['one', 'two', 'three'].to_sentence(:last_word_connector => ', and also ')
+ assert_equal "one, twothree", ['one', 'two', 'three'].to_sentence(:last_word_connector => nil)
+ assert_equal "one, two three", ['one', 'two', 'three'].to_sentence(:last_word_connector => ' ')
+ assert_equal "one, two and three", ['one', 'two', 'three'].to_sentence(:last_word_connector => ' and ')
end
def test_two_elements
assert_equal "one and two", ['one', 'two'].to_sentence
- assert_equal "one two", ['one', 'two'].to_sentence(:connector => '')
+ assert_equal "one two", ['one', 'two'].to_sentence(:two_words_connector => ' ')
end
def test_one_element
diff --git a/activesupport/test/i18n_test.rb b/activesupport/test/i18n_test.rb
index cfb8c76d52..7535f4ad7a 100644
--- a/activesupport/test/i18n_test.rb
+++ b/activesupport/test/i18n_test.rb
@@ -71,19 +71,28 @@ class I18nTest < Test::Unit::TestCase
assert_equal 'pm', I18n.translate(:'time.pm')
end
- def test_sentence_connector
- assert_equal 'and', I18n.translate(:'support.array.sentence_connector')
+ def test_words_connector
+ assert_equal ', ', I18n.translate(:'support.array.words_connector')
end
- def test_skip_last_comma
- assert_equal false, I18n.translate(:'support.array.skip_last_comma')
+ def test_two_words_connector
+ assert_equal ' and ', I18n.translate(:'support.array.two_words_connector')
+ end
+
+ def test_last_word_connector
+ assert_equal ', and ', I18n.translate(:'support.array.last_word_connector')
end
def test_to_sentence
+ default_two_words_connector = I18n.translate(:'support.array.two_words_connector')
+ default_last_word_connector = I18n.translate(:'support.array.last_word_connector')
assert_equal 'a, b, and c', %w[a b c].to_sentence
- I18n.backend.store_translations 'en', :support => { :array => { :skip_last_comma => true } }
+ I18n.backend.store_translations 'en', :support => { :array => { :two_words_connector => ' & ' } }
+ assert_equal 'a & b', %w[a b].to_sentence
+ I18n.backend.store_translations 'en', :support => { :array => { :last_word_connector => ' and ' } }
assert_equal 'a, b and c', %w[a b c].to_sentence
ensure
- I18n.backend.store_translations 'en', :support => { :array => { :skip_last_comma => false } }
+ I18n.backend.store_translations 'en', :support => { :array => { :two_words_connector => default_two_words_connector } }
+ I18n.backend.store_translations 'en', :support => { :array => { :last_word_connector => default_last_word_connector } }
end
end
diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb
index ca2af9b986..067c461837 100644
--- a/activesupport/test/multibyte_chars_test.rb
+++ b/activesupport/test/multibyte_chars_test.rb
@@ -397,6 +397,10 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase
assert_raise(ArgumentError) { @chars.slice(1, 1, 1) }
end
+ def test_ord_should_return_unicode_value_for_first_character
+ assert_equal 12371, @chars.ord
+ end
+
def test_upcase_should_upcase_ascii_characters
assert_equal '', ''.mb_chars.upcase
assert_equal 'ABC', 'aBc'.mb_chars.upcase