Skip to content

Commit

Permalink
Removed deprecated APIs in text and number helpers [#5156 state:resol…
Browse files Browse the repository at this point in the history
…ved]

They're deprecated since 2008. It's time to get rid of them.

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
lukaszx0 authored and josevalim committed Jul 26, 2010
1 parent f70c0b3 commit da84527
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 91 deletions.
48 changes: 4 additions & 44 deletions actionpack/lib/action_view/helpers/number_helper.rb
Expand Up @@ -186,14 +186,7 @@ def number_to_percentage(number, options = {})
# number_with_delimiter(12345678.05, :locale => :fr) # => 12 345 678,05 # number_with_delimiter(12345678.05, :locale => :fr) # => 12 345 678,05
# number_with_delimiter(98765432.98, :delimiter => " ", :separator => ",") # number_with_delimiter(98765432.98, :delimiter => " ", :separator => ",")
# # => 98 765 432,98 # # => 98 765 432,98
# def number_with_delimiter(number, options = {})
# You can still use <tt>number_with_delimiter</tt> with the old API that accepts the
# +delimiter+ as its optional second and the +separator+ as its
# optional third parameter:
# number_with_delimiter(12345678, " ") # => 12 345 678
# number_with_delimiter(12345678.05, ".", ",") # => 12.345.678,05
def number_with_delimiter(number, *args)
options = args.extract_options!
options.symbolize_keys! options.symbolize_keys!


begin begin
Expand All @@ -207,14 +200,6 @@ def number_with_delimiter(number, *args)
end end


defaults = I18n.translate(:'number.format', :locale => options[:locale], :default => {}) defaults = I18n.translate(:'number.format', :locale => options[:locale], :default => {})

unless args.empty?
ActiveSupport::Deprecation.warn('number_with_delimiter takes an option hash ' +
'instead of separate delimiter and precision arguments.', caller)
options[:delimiter] ||= args[0] if args[0]
options[:separator] ||= args[1] if args[1]
end

options = options.reverse_merge(defaults) options = options.reverse_merge(defaults)


parts = number.to_s.split('.') parts = number.to_s.split('.')
Expand Down Expand Up @@ -249,13 +234,7 @@ def number_with_delimiter(number, *args)
# number_with_precision(389.32314, :precision => 4, :significant => true) # => 389.3 # number_with_precision(389.32314, :precision => 4, :significant => true) # => 389.3
# number_with_precision(1111.2345, :precision => 2, :separator => ',', :delimiter => '.') # number_with_precision(1111.2345, :precision => 2, :separator => ',', :delimiter => '.')
# # => 1.111,23 # # => 1.111,23
# def number_with_precision(number, options = {})
# You can still use <tt>number_with_precision</tt> with the old API that accepts the
# +precision+ as its optional second parameter:
# number_with_precision(111.2345, 2) # => 111.23
def number_with_precision(number, *args)

options = args.extract_options!
options.symbolize_keys! options.symbolize_keys!


number = begin number = begin
Expand All @@ -272,13 +251,6 @@ def number_with_precision(number, *args)
precision_defaults = I18n.translate(:'number.precision.format', :locale => options[:locale], :default => {}) precision_defaults = I18n.translate(:'number.precision.format', :locale => options[:locale], :default => {})
defaults = defaults.merge(precision_defaults) defaults = defaults.merge(precision_defaults)


#Backwards compatibility
unless args.empty?
ActiveSupport::Deprecation.warn('number_with_precision takes an option hash ' +
'instead of a separate precision argument.', caller)
options[:precision] ||= args[0] if args[0]
end

options = options.reverse_merge(defaults) # Allow the user to unset default values: Eg.: :significant => false options = options.reverse_merge(defaults) # Allow the user to unset default values: Eg.: :significant => false
precision = options.delete :precision precision = options.delete :precision
significant = options.delete :significant significant = options.delete :significant
Expand Down Expand Up @@ -337,13 +309,7 @@ def number_with_precision(number, *args)
# <tt>:strip_insignificant_zeros</tt> to +false+ to change that): # <tt>:strip_insignificant_zeros</tt> to +false+ to change that):
# number_to_human_size(1234567890123, :precision => 5) # => "1.1229 TB" # number_to_human_size(1234567890123, :precision => 5) # => "1.1229 TB"
# number_to_human_size(524288000, :precision=>5) # => "500 MB" # number_to_human_size(524288000, :precision=>5) # => "500 MB"
# def number_to_human_size(number, options = {})
# You can still use <tt>number_to_human_size</tt> with the old API that accepts the
# +precision+ as its optional second parameter:
# number_to_human_size(1234567, 1) # => 1 MB
# number_to_human_size(483989, 2) # => 470 KB
def number_to_human_size(number, *args)
options = args.extract_options!
options.symbolize_keys! options.symbolize_keys!


number = begin number = begin
Expand All @@ -359,13 +325,7 @@ def number_to_human_size(number, *args)
defaults = I18n.translate(:'number.format', :locale => options[:locale], :default => {}) defaults = I18n.translate(:'number.format', :locale => options[:locale], :default => {})
human = I18n.translate(:'number.human.format', :locale => options[:locale], :default => {}) human = I18n.translate(:'number.human.format', :locale => options[:locale], :default => {})
defaults = defaults.merge(human) defaults = defaults.merge(human)


unless args.empty?
ActiveSupport::Deprecation.warn('number_to_human_size takes an option hash ' +
'instead of a separate precision argument.', caller)
options[:precision] ||= args[0] if args[0]
end

options = options.reverse_merge(defaults) options = options.reverse_merge(defaults)
#for backwards compatibility with those that didn't add strip_insignificant_zeros to their locale files #for backwards compatibility with those that didn't add strip_insignificant_zeros to their locale files
options[:strip_insignificant_zeros] = true if not options.key?(:strip_insignificant_zeros) options[:strip_insignificant_zeros] = true if not options.key?(:strip_insignificant_zeros)
Expand Down
21 changes: 1 addition & 20 deletions actionpack/lib/action_view/helpers/text_helper.rb
Expand Up @@ -61,27 +61,8 @@ def safe_concat(string)
# #
# truncate("<p>Once upon a time in a world far far away</p>") # truncate("<p>Once upon a time in a world far far away</p>")
# # => "<p>Once upon a time in a wo..." # # => "<p>Once upon a time in a wo..."
# def truncate(text, options = {})
# You can still use <tt>truncate</tt> with the old API that accepts the
# +length+ as its optional second and the +ellipsis+ as its
# optional third parameter:
# truncate("Once upon a time in a world far far away", 14)
# # => "Once upon a..."
#
# truncate("And they found that many people were sleeping better.", 25, "... (continued)")
# # => "And they f... (continued)"
def truncate(text, *args)
options = args.extract_options!
unless args.empty?
ActiveSupport::Deprecation.warn('truncate takes an option hash instead of separate ' +
'length and omission arguments', caller)

options[:length] = args[0] || 30
options[:omission] = args[1] || "..."
end

options.reverse_merge!(:length => 30) options.reverse_merge!(:length => 30)

text.truncate(options.delete(:length), options) if text text.truncate(options.delete(:length), options) if text
end end


Expand Down
27 changes: 0 additions & 27 deletions actionpack/test/template/number_helper_test.rb
Expand Up @@ -82,16 +82,6 @@ def test_number_with_delimiter_with_options_hash
assert_equal '12.345.678,05', number_with_delimiter(12345678.05, :delimiter => '.', :separator => ',') assert_equal '12.345.678,05', number_with_delimiter(12345678.05, :delimiter => '.', :separator => ',')
end end


def test_number_with_delimiter_old_api
silence_deprecation_warnings
assert_equal '12 345 678', number_with_delimiter(12345678, " ")
assert_equal '12-345-678.05', number_with_delimiter(12345678.05, '-')
assert_equal '12.345.678,05', number_with_delimiter(12345678.05, '.', ',')
assert_equal '12,345,678.05', number_with_delimiter(12345678.05, ',', '.')
assert_equal '12 345 678-05', number_with_delimiter(12345678.05, ',', '.', :delimiter => ' ', :separator => '-')
restore_deprecation_warnings
end

def test_number_with_precision def test_number_with_precision
assert_equal("111.235", number_with_precision(111.2346)) assert_equal("111.235", number_with_precision(111.2346))
assert_equal("31.83", number_with_precision(31.825, :precision => 2)) assert_equal("31.83", number_with_precision(31.825, :precision => 2))
Expand Down Expand Up @@ -146,15 +136,6 @@ def test_number_with_precision_with_significant_true_and_zero_precision
assert_equal "12", number_with_precision("12.3", :precision => 0, :significant => true ) assert_equal "12", number_with_precision("12.3", :precision => 0, :significant => true )
end end


def test_number_with_precision_old_api
silence_deprecation_warnings
assert_equal("31.8250", number_with_precision(31.825, 4))
assert_equal("111.235", number_with_precision(111.2346, 3))
assert_equal("111.00", number_with_precision(111, 2))
assert_equal("111.000", number_with_precision(111, 2, :precision =>3))
restore_deprecation_warnings
end

def test_number_to_human_size def test_number_to_human_size
assert_equal '0 Bytes', number_to_human_size(0) assert_equal '0 Bytes', number_to_human_size(0)
assert_equal '1 Byte', number_to_human_size(1) assert_equal '1 Byte', number_to_human_size(1)
Expand Down Expand Up @@ -202,14 +183,6 @@ def test_number_to_human_size_with_custom_delimiter_and_separator
assert_equal '1.000,1 TB', number_to_human_size(terabytes(1000.1), :precision => 5, :delimiter => '.', :separator => ',') assert_equal '1.000,1 TB', number_to_human_size(terabytes(1000.1), :precision => 5, :delimiter => '.', :separator => ',')
end end


def test_number_to_human_size_old_api
silence_deprecation_warnings
assert_equal '1.3143 KB', number_to_human_size(kilobytes(1.3143), 4, :significant => false)
assert_equal '10.45 KB', number_to_human_size(kilobytes(10.453), 4)
assert_equal '10 KB', number_to_human_size(kilobytes(10.453), 4, :precision => 2)
restore_deprecation_warnings
end

def test_number_to_human def test_number_to_human
assert_equal '123', number_to_human(123) assert_equal '123', number_to_human(123)
assert_equal '1.23 Thousand', number_to_human(1234) assert_equal '1.23 Thousand', number_to_human(1234)
Expand Down

0 comments on commit da84527

Please sign in to comment.