From 7faa620fd697fe7323487e893596bc761e8d8b33 Mon Sep 17 00:00:00 2001 From: "Mark J. Titorenko" Date: Tue, 8 May 2012 15:37:18 +0100 Subject: Fix NumberHelper options wrapping to prevent verbatim blocks being rendered instead of line continuations. While I'm at it, wrap long comment lines consistently. Conflicts: actionpack/lib/action_view/helpers/number_helper.rb There was just one conflict related to the addition of the :format option to number_to_percentage. --- .../lib/action_view/helpers/number_helper.rb | 249 +++++++++++++-------- 1 file changed, 159 insertions(+), 90 deletions(-) (limited to 'actionpack/lib/action_view/helpers') diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb index b5e33dc0fc..2f372bd111 100644 --- a/actionpack/lib/action_view/helpers/number_helper.rb +++ b/actionpack/lib/action_view/helpers/number_helper.rb @@ -29,17 +29,20 @@ module ActionView end end - # Formats a +number+ into a US phone number (e.g., (555) 123-9876). You can customize the format - # in the +options+ hash. + # Formats a +number+ into a US phone number (e.g., (555) + # 123-9876). You can customize the format in the +options+ hash. # # ==== Options # - # * :area_code - Adds parentheses around the area code. - # * :delimiter - Specifies the delimiter to use (defaults to "-"). - # * :extension - Specifies an extension to add to the end of the - # generated number. - # * :country_code - Sets the country code for the phone number. - # * :raise - If true, raises +InvalidNumberError+ when the argument is invalid. + # * :area_code - Adds parentheses around the area code. + # * :delimiter - Specifies the delimiter to use + # (defaults to "-"). + # * :extension - Specifies an extension to add to the + # end of the generated number. + # * :country_code - Sets the country code for the phone + # number. + # * :raise - If true, raises +InvalidNumberError+ when + # the argument is invalid. # # ==== Examples # @@ -86,24 +89,31 @@ module ActionView ERB::Util.html_escape(str.join) end - # Formats a +number+ into a currency string (e.g., $13.65). You can customize the format - # in the +options+ hash. + # Formats a +number+ into a currency string (e.g., $13.65). You + # can customize the format in the +options+ hash. # # ==== Options # - # * :locale - Sets the locale to be used for formatting (defaults to current locale). - # * :precision - Sets the level of precision (defaults to 2). - # * :unit - Sets the denomination of the currency (defaults to "$"). - # * :separator - Sets the separator between the units (defaults to "."). - # * :delimiter - Sets the thousands delimiter (defaults to ","). - # * :format - Sets the format for non-negative numbers (defaults to "%u%n"). - # Fields are %u for the currency, and %n - # for the number. - # * :negative_format - Sets the format for negative numbers (defaults to prepending - # an hyphen to the formatted number given by :format). - # Accepts the same fields than :format, except - # %n is here the absolute value of the number. - # * :raise - If true, raises +InvalidNumberError+ when the argument is invalid. + # * :locale - Sets the locale to be used for formatting + # (defaults to current locale). + # * :precision - Sets the level of precision (defaults + # to 2). + # * :unit - Sets the denomination of the currency + # (defaults to "$"). + # * :separator - Sets the separator between the units + # (defaults to "."). + # * :delimiter - Sets the thousands delimiter (defaults + # to ","). + # * :format - Sets the format for non-negative numbers + # (defaults to "%u%n"). Fields are %u for the + # currency, and %n for the number. + # * :negative_format - Sets the format for negative + # numbers (defaults to prepending an hyphen to the formatted + # number given by :format). Accepts the same fields + # than :format, except %n is here the + # absolute value of the number. + # * :raise - If true, raises +InvalidNumberError+ when + # the argument is invalid. # # ==== Examples # @@ -156,21 +166,27 @@ module ActionView end - # Formats a +number+ as a percentage string (e.g., 65%). You can customize the format in the +options+ hash. + # Formats a +number+ as a percentage string (e.g., 65%). You can + # customize the format in the +options+ hash. # # ==== Options # - # * :locale - Sets the locale to be used for formatting (defaults to current - # locale). - # * :precision - Sets the precision of the number (defaults to 3). - # * :significant - If +true+, precision will be the # of significant_digits. If +false+, - # the # of fractional digits (defaults to +false+). - # * :separator - Sets the separator between the fractional and integer digits (defaults - # to "."). - # * :delimiter - Sets the thousands delimiter (defaults to ""). - # * :strip_insignificant_zeros - If +true+ removes insignificant zeros after the decimal separator - # (defaults to +false+). - # * :raise - If true, raises +InvalidNumberError+ when the argument is invalid. + # * :locale - Sets the locale to be used for formatting + # (defaults to current locale). + # * :precision - Sets the precision of the number + # (defaults to 3). + # * :significant - If +true+, precision will be the # + # of significant_digits. If +false+, the # of fractional + # digits (defaults to +false+). + # * :separator - Sets the separator between the + # fractional and integer digits (defaults to "."). + # * :delimiter - Sets the thousands delimiter (defaults + # to ""). + # * :strip_insignificant_zeros - If +true+ removes + # insignificant zeros after the decimal separator (defaults to + # +false+). + # * :raise - If true, raises +InvalidNumberError+ when + # the argument is invalid. # # ==== Examples # @@ -205,15 +221,20 @@ module ActionView end end - # Formats a +number+ with grouped thousands using +delimiter+ (e.g., 12,324). You can - # customize the format in the +options+ hash. + # Formats a +number+ with grouped thousands using +delimiter+ + # (e.g., 12,324). You can customize the format in the +options+ + # hash. # # ==== Options # - # * :locale - Sets the locale to be used for formatting (defaults to current locale). - # * :delimiter - Sets the thousands delimiter (defaults to ","). - # * :separator - Sets the separator between the fractional and integer digits (defaults to "."). - # * :raise - If true, raises +InvalidNumberError+ when the argument is invalid. + # * :locale - Sets the locale to be used for formatting + # (defaults to current locale). + # * :delimiter - Sets the thousands delimiter (defaults + # to ","). + # * :separator - Sets the separator between the + # fractional and integer digits (defaults to "."). + # * :raise - If true, raises +InvalidNumberError+ when + # the argument is invalid. # # ==== Examples # @@ -251,23 +272,32 @@ module ActionView end - # Formats a +number+ with the specified level of :precision (e.g., 112.32 has a precision - # of 2 if +:significant+ is +false+, and 5 if +:significant+ is +true+). + # Formats a +number+ with the specified level of + # :precision (e.g., 112.32 has a precision of 2 if + # +:significant+ is +false+, and 5 if +:significant+ is +true+). # You can customize the format in the +options+ hash. # # ==== Options - # * :locale - Sets the locale to be used for formatting (defaults to current locale). - # * :precision - Sets the precision of the number (defaults to 3). - # * :significant - If +true+, precision will be the # of significant_digits. If +false+, - # the # of fractional digits (defaults to +false+). - # * :separator - Sets the separator between the fractional and integer digits (defaults - # to "."). - # * :delimiter - Sets the thousands delimiter (defaults to ""). - # * :strip_insignificant_zeros - If +true+ removes insignificant zeros after the decimal separator - # (defaults to +false+). - # * :raise - If true, raises +InvalidNumberError+ when the argument is invalid. + # + # * :locale - Sets the locale to be used for formatting + # (defaults to current locale). + # * :precision - Sets the precision of the number + # (defaults to 3). + # * :significant - If +true+, precision will be the # + # of significant_digits. If +false+, the # of fractional + # digits (defaults to +false+). + # * :separator - Sets the separator between the + # fractional and integer digits (defaults to "."). + # * :delimiter - Sets the thousands delimiter (defaults + # to ""). + # * :strip_insignificant_zeros - If +true+ removes + # insignificant zeros after the decimal separator (defaults to + # +false+). + # * :raise - If true, raises +InvalidNumberError+ when + # the argument is invalid. # # ==== Examples + # # number_with_precision(111.2345) # => 111.235 # number_with_precision(111.2345, :precision => 2) # => 111.23 # number_with_precision(13, :precision => 5) # => 13.00000 @@ -330,23 +360,37 @@ module ActionView STORAGE_UNITS = [:byte, :kb, :mb, :gb, :tb].freeze - # Formats the bytes in +number+ into a more understandable representation - # (e.g., giving it 1500 yields 1.5 KB). This method is useful for - # reporting file sizes to users. You can customize the - # format in the +options+ hash. + # Formats the bytes in +number+ into a more understandable + # representation (e.g., giving it 1500 yields 1.5 KB). This + # method is useful for reporting file sizes to users. You can + # customize the format in the +options+ hash. # - # See number_to_human if you want to pretty-print a generic number. + # See number_to_human if you want to pretty-print a + # generic number. # # ==== Options - # * :locale - Sets the locale to be used for formatting (defaults to current locale). - # * :precision - Sets the precision of the number (defaults to 3). - # * :significant - If +true+, precision will be the # of significant_digits. If +false+, the # of fractional digits (defaults to +true+) - # * :separator - Sets the separator between the fractional and integer digits (defaults to "."). - # * :delimiter - Sets the thousands delimiter (defaults to ""). - # * :strip_insignificant_zeros - If +true+ removes insignificant zeros after the decimal separator (defaults to +true+) - # * :prefix - If +:si+ formats the number using the SI prefix (defaults to :binary) - # * :raise - If true, raises +InvalidNumberError+ when the argument is invalid. + # + # * :locale - Sets the locale to be used for formatting + # (defaults to current locale). + # * :precision - Sets the precision of the number + # (defaults to 3). + # * :significant - If +true+, precision will be the # + # of significant_digits. If +false+, the # of fractional + # digits (defaults to +true+) + # * :separator - Sets the separator between the + # fractional and integer digits (defaults to "."). + # * :delimiter - Sets the thousands delimiter (defaults + # to ""). + # * :strip_insignificant_zeros - If +true+ removes + # insignificant zeros after the decimal separator (defaults to + # +true+) + # * :prefix - If +:si+ formats the number using the SI + # prefix (defaults to :binary) + # * :raise - If true, raises +InvalidNumberError+ when + # the argument is invalid. + # # ==== Examples + # # number_to_human_size(123) # => 123 Bytes # number_to_human_size(1234) # => 1.21 KB # number_to_human_size(12345) # => 12.1 KB @@ -357,8 +401,10 @@ module ActionView # number_to_human_size(483989, :precision => 2) # => 470 KB # number_to_human_size(1234567, :precision => 2, :separator => ',') # => 1,2 MB # - # Non-significant zeros after the fractional separator are stripped out by default (set - # :strip_insignificant_zeros to +false+ to change that): + # Non-significant zeros after the fractional separator are + # stripped out by default (set + # :strip_insignificant_zeros to +false+ to change + # that): # number_to_human_size(1234567890123, :precision => 5) # => "1.1229 TB" # number_to_human_size(524288000, :precision => 5) # => "500 MB" def number_to_human_size(number, options = {}) @@ -406,33 +452,55 @@ module ActionView DECIMAL_UNITS = {0 => :unit, 1 => :ten, 2 => :hundred, 3 => :thousand, 6 => :million, 9 => :billion, 12 => :trillion, 15 => :quadrillion, -1 => :deci, -2 => :centi, -3 => :mili, -6 => :micro, -9 => :nano, -12 => :pico, -15 => :femto}.freeze - # Pretty prints (formats and approximates) a number in a way it is more readable by humans - # (eg.: 1200000000 becomes "1.2 Billion"). This is useful for numbers that - # can get very large (and too hard to read). + # Pretty prints (formats and approximates) a number in a way it + # is more readable by humans (eg.: 1200000000 becomes "1.2 + # Billion"). This is useful for numbers that can get very large + # (and too hard to read). # - # See number_to_human_size if you want to print a file size. + # See number_to_human_size if you want to print a file + # size. # - # You can also define you own unit-quantifier names if you want to use other decimal units - # (eg.: 1500 becomes "1.5 kilometers", 0.150 becomes "150 milliliters", etc). You may define - # a wide range of unit quantifiers, even fractional ones (centi, deci, mili, etc). + # You can also define you own unit-quantifier names if you want + # to use other decimal units (eg.: 1500 becomes "1.5 + # kilometers", 0.150 becomes "150 milliliters", etc). You may + # define a wide range of unit quantifiers, even fractional ones + # (centi, deci, mili, etc). # # ==== Options - # * :locale - Sets the locale to be used for formatting (defaults to current locale). - # * :precision - Sets the precision of the number (defaults to 3). - # * :significant - If +true+, precision will be the # of significant_digits. If +false+, the # of fractional digits (defaults to +true+) - # * :separator - Sets the separator between the fractional and integer digits (defaults to "."). - # * :delimiter - Sets the thousands delimiter (defaults to ""). - # * :strip_insignificant_zeros - If +true+ removes insignificant zeros after the decimal separator (defaults to +true+) - # * :units - A Hash of unit quantifier names. Or a string containing an i18n scope where to find this hash. It might have the following keys: - # * *integers*: :unit, :ten, :hundred, :thousand, :million, :billion, :trillion, :quadrillion - # * *fractionals*: :deci, :centi, :mili, :micro, :nano, :pico, :femto - # * :format - Sets the format of the output string (defaults to "%n %u"). The field types are: - # %u The quantifier (ex.: 'thousand') - # %n The number - # * :raise - If true, raises +InvalidNumberError+ when the argument is invalid. # + # * :locale - Sets the locale to be used for formatting + # (defaults to current locale). + # * :precision - Sets the precision of the number + # (defaults to 3). + # * :significant - If +true+, precision will be the # + # of significant_digits. If +false+, the # of fractional + # digits (defaults to +true+) + # * :separator - Sets the separator between the + # fractional and integer digits (defaults to "."). + # * :delimiter - Sets the thousands delimiter (defaults + # to ""). + # * :strip_insignificant_zeros - If +true+ removes + # insignificant zeros after the decimal separator (defaults to + # +true+) + # * :units - A Hash of unit quantifier names. Or a + # string containing an i18n scope where to find this hash. It + # might have the following keys: + # * *integers*: :unit, :ten, + # *:hundred, :thousand, :million, + # *:billion, :trillion, + # *:quadrillion + # * *fractionals*: :deci, :centi, + # *:mili, :micro, :nano, + # *:pico, :femto + # * :format - Sets the format of the output string + # (defaults to "%n %u"). The field types are: + # * %u - The quantifier (ex.: 'thousand') + # * %n - The number + # * :raise - If true, raises +InvalidNumberError+ when + # the argument is invalid. # # ==== Examples + # # number_to_human(123) # => "123" # number_to_human(1234) # => "1.23 Thousand" # number_to_human(12345) # => "12.3 Thousand" @@ -449,8 +517,9 @@ module ActionView # :separator => ',', # :significant => false) # => "1,2 Million" # - # Unsignificant zeros after the decimal separator are stripped out by default (set - # :strip_insignificant_zeros to +false+ to change that): + # Non-significant zeros after the decimal separator are stripped + # out by default (set :strip_insignificant_zeros to + # +false+ to change that): # number_to_human(12345012345, :significant_digits => 6) # => "12.345 Billion" # number_to_human(500000000, :precision => 5) # => "500 Million" # -- cgit v1.2.3