actionview 7.1.2 → 8.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +51 -382
- data/lib/action_view/base.rb +25 -11
- data/lib/action_view/cache_expiry.rb +9 -3
- data/lib/action_view/dependency_tracker/erb_tracker.rb +36 -27
- data/lib/action_view/dependency_tracker/ruby_tracker.rb +43 -0
- data/lib/action_view/dependency_tracker/wildcard_resolver.rb +32 -0
- data/lib/action_view/dependency_tracker.rb +2 -1
- data/lib/action_view/digestor.rb +6 -2
- data/lib/action_view/gem_version.rb +2 -2
- data/lib/action_view/helpers/asset_tag_helper.rb +18 -6
- data/lib/action_view/helpers/atom_feed_helper.rb +0 -2
- data/lib/action_view/helpers/cache_helper.rb +14 -6
- data/lib/action_view/helpers/csrf_helper.rb +1 -1
- data/lib/action_view/helpers/date_helper.rb +3 -3
- data/lib/action_view/helpers/form_helper.rb +282 -273
- data/lib/action_view/helpers/form_options_helper.rb +23 -21
- data/lib/action_view/helpers/form_tag_helper.rb +104 -69
- data/lib/action_view/helpers/number_helper.rb +35 -329
- data/lib/action_view/helpers/output_safety_helper.rb +5 -6
- data/lib/action_view/helpers/rendering_helper.rb +160 -50
- data/lib/action_view/helpers/sanitize_helper.rb +31 -14
- data/lib/action_view/helpers/tag_helper.rb +196 -19
- data/lib/action_view/helpers/tags/collection_check_boxes.rb +4 -3
- data/lib/action_view/helpers/tags/collection_helpers.rb +2 -1
- data/lib/action_view/helpers/text_helper.rb +125 -69
- data/lib/action_view/helpers/url_helper.rb +6 -80
- data/lib/action_view/layouts.rb +11 -13
- data/lib/action_view/log_subscriber.rb +8 -4
- data/lib/action_view/railtie.rb +0 -1
- data/lib/action_view/record_identifier.rb +1 -1
- data/lib/action_view/render_parser/prism_render_parser.rb +139 -0
- data/lib/action_view/{ripper_ast_parser.rb → render_parser/ripper_render_parser.rb} +162 -10
- data/lib/action_view/render_parser.rb +21 -169
- data/lib/action_view/renderer/abstract_renderer.rb +1 -1
- data/lib/action_view/renderer/partial_renderer.rb +2 -2
- data/lib/action_view/renderer/renderer.rb +32 -38
- data/lib/action_view/renderer/streaming_template_renderer.rb +0 -1
- data/lib/action_view/renderer/template_renderer.rb +3 -3
- data/lib/action_view/rendering.rb +6 -7
- data/lib/action_view/template/error.rb +11 -0
- data/lib/action_view/template/handlers/erb.rb +45 -37
- data/lib/action_view/template/renderable.rb +7 -1
- data/lib/action_view/template/resolver.rb +0 -3
- data/lib/action_view/template.rb +46 -12
- data/lib/action_view/test_case.rb +14 -16
- data/lib/action_view/unbound_template.rb +4 -4
- data/lib/action_view.rb +1 -1
- metadata +17 -19
- data/lib/action_view/dependency_tracker/ripper_tracker.rb +0 -59
- data/lib/assets/compiled/rails-ujs.js +0 -777
|
@@ -24,42 +24,14 @@ module ActionView
|
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
#
|
|
28
|
-
# 123-9876). You can customize the format in the +options+ hash.
|
|
27
|
+
# Delegates to ActiveSupport::NumberHelper#number_to_phone.
|
|
29
28
|
#
|
|
30
|
-
#
|
|
29
|
+
# Additionally, supports a +:raise+ option that will cause
|
|
30
|
+
# InvalidNumberError to be raised if +number+ is not a valid number:
|
|
31
31
|
#
|
|
32
|
-
#
|
|
33
|
-
#
|
|
34
|
-
# (defaults to "-").
|
|
35
|
-
# * <tt>:extension</tt> - Specifies an extension to add to the
|
|
36
|
-
# end of the generated number.
|
|
37
|
-
# * <tt>:country_code</tt> - Sets the country code for the phone
|
|
38
|
-
# number.
|
|
39
|
-
# * <tt>:pattern</tt> - Specifies how the number is divided into three
|
|
40
|
-
# groups with the custom regexp to override the default format.
|
|
41
|
-
# * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when
|
|
42
|
-
# the argument is invalid.
|
|
32
|
+
# number_to_phone("12x34") # => "12x34"
|
|
33
|
+
# number_to_phone("12x34", raise: true) # => InvalidNumberError
|
|
43
34
|
#
|
|
44
|
-
# ==== Examples
|
|
45
|
-
#
|
|
46
|
-
# number_to_phone(5551234) # => 555-1234
|
|
47
|
-
# number_to_phone("5551234") # => 555-1234
|
|
48
|
-
# number_to_phone(1235551234) # => 123-555-1234
|
|
49
|
-
# number_to_phone(1235551234, area_code: true) # => (123) 555-1234
|
|
50
|
-
# number_to_phone(1235551234, delimiter: " ") # => 123 555 1234
|
|
51
|
-
# number_to_phone(1235551234, area_code: true, extension: 555) # => (123) 555-1234 x 555
|
|
52
|
-
# number_to_phone(1235551234, country_code: 1) # => +1-123-555-1234
|
|
53
|
-
# number_to_phone("123a456") # => 123a456
|
|
54
|
-
# number_to_phone("1234a567", raise: true) # => InvalidNumberError
|
|
55
|
-
#
|
|
56
|
-
# number_to_phone(1235551234, country_code: 1, extension: 1343, delimiter: ".")
|
|
57
|
-
# # => +1.123.555.1234 x 1343
|
|
58
|
-
#
|
|
59
|
-
# number_to_phone(75561234567, pattern: /(\d{1,4})(\d{4})(\d{4})$/, area_code: true)
|
|
60
|
-
# # => "(755) 6123-4567"
|
|
61
|
-
# number_to_phone(13312345678, pattern: /(\d{3})(\d{4})(\d{4})$/)
|
|
62
|
-
# # => "133-1234-5678"
|
|
63
35
|
def number_to_phone(number, options = {})
|
|
64
36
|
return unless number
|
|
65
37
|
options = options.symbolize_keys
|
|
@@ -68,339 +40,73 @@ module ActionView
|
|
|
68
40
|
ERB::Util.html_escape(ActiveSupport::NumberHelper.number_to_phone(number, options))
|
|
69
41
|
end
|
|
70
42
|
|
|
71
|
-
#
|
|
72
|
-
# can customize the format in the +options+ hash.
|
|
73
|
-
#
|
|
74
|
-
# The currency unit and number formatting of the current locale will be used
|
|
75
|
-
# unless otherwise specified in the provided options. No currency conversion
|
|
76
|
-
# is performed. If the user is given a way to change their locale, they will
|
|
77
|
-
# also be able to change the relative value of the currency displayed with
|
|
78
|
-
# this helper. If your application will ever support multiple locales, you
|
|
79
|
-
# may want to specify a constant <tt>:locale</tt> option or consider
|
|
80
|
-
# using a library capable of currency conversion.
|
|
43
|
+
# Delegates to ActiveSupport::NumberHelper#number_to_currency.
|
|
81
44
|
#
|
|
82
|
-
#
|
|
45
|
+
# Additionally, supports a +:raise+ option that will cause
|
|
46
|
+
# InvalidNumberError to be raised if +number+ is not a valid number:
|
|
83
47
|
#
|
|
84
|
-
#
|
|
85
|
-
# (
|
|
86
|
-
# * <tt>:precision</tt> - Sets the level of precision (defaults
|
|
87
|
-
# to 2).
|
|
88
|
-
# * <tt>:unit</tt> - Sets the denomination of the currency
|
|
89
|
-
# (defaults to "$").
|
|
90
|
-
# * <tt>:separator</tt> - Sets the separator between the units
|
|
91
|
-
# (defaults to ".").
|
|
92
|
-
# * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults
|
|
93
|
-
# to ",").
|
|
94
|
-
# * <tt>:format</tt> - Sets the format for non-negative numbers
|
|
95
|
-
# (defaults to "%u%n"). Fields are <tt>%u</tt> for the
|
|
96
|
-
# currency, and <tt>%n</tt> for the number.
|
|
97
|
-
# * <tt>:negative_format</tt> - Sets the format for negative
|
|
98
|
-
# numbers (defaults to prepending a hyphen to the formatted
|
|
99
|
-
# number given by <tt>:format</tt>). Accepts the same fields
|
|
100
|
-
# than <tt>:format</tt>, except <tt>%n</tt> is here the
|
|
101
|
-
# absolute value of the number.
|
|
102
|
-
# * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when
|
|
103
|
-
# the argument is invalid.
|
|
104
|
-
# * <tt>:strip_insignificant_zeros</tt> - If +true+ removes
|
|
105
|
-
# insignificant zeros after the decimal separator (defaults to
|
|
106
|
-
# +false+).
|
|
48
|
+
# number_to_currency("12x34") # => "$12x34"
|
|
49
|
+
# number_to_currency("12x34", raise: true) # => InvalidNumberError
|
|
107
50
|
#
|
|
108
|
-
# ==== Examples
|
|
109
|
-
#
|
|
110
|
-
# number_to_currency(1234567890.50) # => $1,234,567,890.50
|
|
111
|
-
# number_to_currency(1234567890.506) # => $1,234,567,890.51
|
|
112
|
-
# number_to_currency(1234567890.506, precision: 3) # => $1,234,567,890.506
|
|
113
|
-
# number_to_currency(1234567890.506, locale: :fr) # => 1 234 567 890,51 €
|
|
114
|
-
# number_to_currency("123a456") # => $123a456
|
|
115
|
-
#
|
|
116
|
-
# number_to_currency("123a456", raise: true) # => InvalidNumberError
|
|
117
|
-
#
|
|
118
|
-
# number_to_currency(-0.456789, precision: 0)
|
|
119
|
-
# # => "$0"
|
|
120
|
-
# number_to_currency(-1234567890.50, negative_format: "(%u%n)")
|
|
121
|
-
# # => ($1,234,567,890.50)
|
|
122
|
-
# number_to_currency(1234567890.50, unit: "R$", separator: ",", delimiter: "")
|
|
123
|
-
# # => R$1234567890,50
|
|
124
|
-
# number_to_currency(1234567890.50, unit: "R$", separator: ",", delimiter: "", format: "%n %u")
|
|
125
|
-
# # => 1234567890,50 R$
|
|
126
|
-
# number_to_currency(1234567890.50, strip_insignificant_zeros: true)
|
|
127
|
-
# # => "$1,234,567,890.5"
|
|
128
51
|
def number_to_currency(number, options = {})
|
|
129
52
|
delegate_number_helper_method(:number_to_currency, number, options)
|
|
130
53
|
end
|
|
131
54
|
|
|
132
|
-
#
|
|
133
|
-
# customize the format in the +options+ hash.
|
|
134
|
-
#
|
|
135
|
-
# ==== Options
|
|
55
|
+
# Delegates to ActiveSupport::NumberHelper#number_to_percentage.
|
|
136
56
|
#
|
|
137
|
-
#
|
|
138
|
-
#
|
|
139
|
-
# * <tt>:precision</tt> - Sets the precision of the number
|
|
140
|
-
# (defaults to 3).
|
|
141
|
-
# * <tt>:significant</tt> - If +true+, precision will be the number
|
|
142
|
-
# of significant_digits. If +false+, the number of fractional
|
|
143
|
-
# digits (defaults to +false+).
|
|
144
|
-
# * <tt>:separator</tt> - Sets the separator between the
|
|
145
|
-
# fractional and integer digits (defaults to ".").
|
|
146
|
-
# * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults
|
|
147
|
-
# to "").
|
|
148
|
-
# * <tt>:strip_insignificant_zeros</tt> - If +true+ removes
|
|
149
|
-
# insignificant zeros after the decimal separator (defaults to
|
|
150
|
-
# +false+).
|
|
151
|
-
# * <tt>:format</tt> - Specifies the format of the percentage
|
|
152
|
-
# string The number field is <tt>%n</tt> (defaults to "%n%").
|
|
153
|
-
# * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when
|
|
154
|
-
# the argument is invalid.
|
|
57
|
+
# Additionally, supports a +:raise+ option that will cause
|
|
58
|
+
# InvalidNumberError to be raised if +number+ is not a valid number:
|
|
155
59
|
#
|
|
156
|
-
#
|
|
60
|
+
# number_to_percentage("99x") # => "99x%"
|
|
61
|
+
# number_to_percentage("99x", raise: true) # => InvalidNumberError
|
|
157
62
|
#
|
|
158
|
-
# number_to_percentage(100) # => 100.000%
|
|
159
|
-
# number_to_percentage("98") # => 98.000%
|
|
160
|
-
# number_to_percentage(100, precision: 0) # => 100%
|
|
161
|
-
# number_to_percentage(1000, delimiter: '.', separator: ',') # => 1.000,000%
|
|
162
|
-
# number_to_percentage(302.24398923423, precision: 5) # => 302.24399%
|
|
163
|
-
# number_to_percentage(1000, locale: :fr) # => 1 000,000%
|
|
164
|
-
# number_to_percentage("98a") # => 98a%
|
|
165
|
-
# number_to_percentage(100, format: "%n %") # => 100.000 %
|
|
166
|
-
#
|
|
167
|
-
# number_to_percentage("98a", raise: true) # => InvalidNumberError
|
|
168
63
|
def number_to_percentage(number, options = {})
|
|
169
64
|
delegate_number_helper_method(:number_to_percentage, number, options)
|
|
170
65
|
end
|
|
171
66
|
|
|
172
|
-
#
|
|
173
|
-
# (e.g., 12,324). You can customize the format in the +options+
|
|
174
|
-
# hash.
|
|
175
|
-
#
|
|
176
|
-
# ==== Options
|
|
177
|
-
#
|
|
178
|
-
# * <tt>:locale</tt> - Sets the locale to be used for formatting
|
|
179
|
-
# (defaults to current locale).
|
|
180
|
-
# * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults
|
|
181
|
-
# to ",").
|
|
182
|
-
# * <tt>:separator</tt> - Sets the separator between the
|
|
183
|
-
# fractional and integer digits (defaults to ".").
|
|
184
|
-
# * <tt>:delimiter_pattern</tt> - Sets a custom regular expression used for
|
|
185
|
-
# deriving the placement of delimiter. Helpful when using currency formats
|
|
186
|
-
# like INR.
|
|
187
|
-
# * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when
|
|
188
|
-
# the argument is invalid.
|
|
189
|
-
#
|
|
190
|
-
# ==== Examples
|
|
67
|
+
# Delegates to ActiveSupport::NumberHelper#number_to_delimited.
|
|
191
68
|
#
|
|
192
|
-
#
|
|
193
|
-
#
|
|
194
|
-
# number_with_delimiter(12345678.05) # => 12,345,678.05
|
|
195
|
-
# number_with_delimiter(12345678, delimiter: ".") # => 12.345.678
|
|
196
|
-
# number_with_delimiter(12345678, delimiter: ",") # => 12,345,678
|
|
197
|
-
# number_with_delimiter(12345678.05, separator: " ") # => 12,345,678 05
|
|
198
|
-
# number_with_delimiter(12345678.05, locale: :fr) # => 12 345 678,05
|
|
199
|
-
# number_with_delimiter("112a") # => 112a
|
|
200
|
-
# number_with_delimiter(98765432.98, delimiter: " ", separator: ",")
|
|
201
|
-
# # => 98 765 432,98
|
|
69
|
+
# Additionally, supports a +:raise+ option that will cause
|
|
70
|
+
# InvalidNumberError to be raised if +number+ is not a valid number:
|
|
202
71
|
#
|
|
203
|
-
# number_with_delimiter("
|
|
204
|
-
#
|
|
72
|
+
# number_with_delimiter("12x34") # => "12x34"
|
|
73
|
+
# number_with_delimiter("12x34", raise: true) # => InvalidNumberError
|
|
205
74
|
#
|
|
206
|
-
# number_with_delimiter("112a", raise: true) # => raise InvalidNumberError
|
|
207
75
|
def number_with_delimiter(number, options = {})
|
|
208
76
|
delegate_number_helper_method(:number_to_delimited, number, options)
|
|
209
77
|
end
|
|
210
78
|
|
|
211
|
-
#
|
|
212
|
-
# <tt>:precision</tt> (e.g., 112.32 has a precision of 2 if
|
|
213
|
-
# +:significant+ is +false+, and 5 if +:significant+ is +true+).
|
|
214
|
-
# You can customize the format in the +options+ hash.
|
|
215
|
-
#
|
|
216
|
-
# ==== Options
|
|
217
|
-
#
|
|
218
|
-
# * <tt>:locale</tt> - Sets the locale to be used for formatting
|
|
219
|
-
# (defaults to current locale).
|
|
220
|
-
# * <tt>:precision</tt> - Sets the precision of the number
|
|
221
|
-
# (defaults to 3).
|
|
222
|
-
# * <tt>:significant</tt> - If +true+, precision will be the number
|
|
223
|
-
# of significant_digits. If +false+, the number of fractional
|
|
224
|
-
# digits (defaults to +false+).
|
|
225
|
-
# * <tt>:separator</tt> - Sets the separator between the
|
|
226
|
-
# fractional and integer digits (defaults to ".").
|
|
227
|
-
# * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults
|
|
228
|
-
# to "").
|
|
229
|
-
# * <tt>:strip_insignificant_zeros</tt> - If +true+ removes
|
|
230
|
-
# insignificant zeros after the decimal separator (defaults to
|
|
231
|
-
# +false+).
|
|
232
|
-
# * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when
|
|
233
|
-
# the argument is invalid.
|
|
234
|
-
#
|
|
235
|
-
# ==== Examples
|
|
79
|
+
# Delegates to ActiveSupport::NumberHelper#number_to_rounded.
|
|
236
80
|
#
|
|
237
|
-
#
|
|
238
|
-
#
|
|
239
|
-
# number_with_precision(13, precision: 5) # => 13.00000
|
|
240
|
-
# number_with_precision(389.32314, precision: 0) # => 389
|
|
241
|
-
# number_with_precision(111.2345, significant: true) # => 111
|
|
242
|
-
# number_with_precision(111.2345, precision: 1, significant: true) # => 100
|
|
243
|
-
# number_with_precision(13, precision: 5, significant: true) # => 13.000
|
|
244
|
-
# number_with_precision(111.234, locale: :fr) # => 111,234
|
|
81
|
+
# Additionally, supports a +:raise+ option that will cause
|
|
82
|
+
# InvalidNumberError to be raised if +number+ is not a valid number:
|
|
245
83
|
#
|
|
246
|
-
# number_with_precision(
|
|
247
|
-
# # =>
|
|
84
|
+
# number_with_precision("12x34") # => "12x34"
|
|
85
|
+
# number_with_precision("12x34", raise: true) # => InvalidNumberError
|
|
248
86
|
#
|
|
249
|
-
# number_with_precision(389.32314, precision: 4, significant: true) # => 389.3
|
|
250
|
-
# number_with_precision(1111.2345, precision: 2, separator: ',', delimiter: '.')
|
|
251
|
-
# # => 1.111,23
|
|
252
87
|
def number_with_precision(number, options = {})
|
|
253
88
|
delegate_number_helper_method(:number_to_rounded, number, options)
|
|
254
89
|
end
|
|
255
90
|
|
|
256
|
-
#
|
|
257
|
-
# representation (e.g., giving it 1500 yields 1.46 KB). This
|
|
258
|
-
# method is useful for reporting file sizes to users. You can
|
|
259
|
-
# customize the format in the +options+ hash.
|
|
91
|
+
# Delegates to ActiveSupport::NumberHelper#number_to_human_size.
|
|
260
92
|
#
|
|
261
|
-
#
|
|
262
|
-
#
|
|
93
|
+
# Additionally, supports a +:raise+ option that will cause
|
|
94
|
+
# InvalidNumberError to be raised if +number+ is not a valid number:
|
|
263
95
|
#
|
|
264
|
-
#
|
|
96
|
+
# number_to_human_size("12x34") # => "12x34"
|
|
97
|
+
# number_to_human_size("12x34", raise: true) # => InvalidNumberError
|
|
265
98
|
#
|
|
266
|
-
# * <tt>:locale</tt> - Sets the locale to be used for formatting
|
|
267
|
-
# (defaults to current locale).
|
|
268
|
-
# * <tt>:precision</tt> - Sets the precision of the number
|
|
269
|
-
# (defaults to 3).
|
|
270
|
-
# * <tt>:significant</tt> - If +true+, precision will be the number
|
|
271
|
-
# of significant_digits. If +false+, the number of fractional
|
|
272
|
-
# digits (defaults to +true+)
|
|
273
|
-
# * <tt>:separator</tt> - Sets the separator between the
|
|
274
|
-
# fractional and integer digits (defaults to ".").
|
|
275
|
-
# * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults
|
|
276
|
-
# to "").
|
|
277
|
-
# * <tt>:strip_insignificant_zeros</tt> - If +true+ removes
|
|
278
|
-
# insignificant zeros after the decimal separator (defaults to
|
|
279
|
-
# +true+)
|
|
280
|
-
# * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when
|
|
281
|
-
# the argument is invalid.
|
|
282
|
-
#
|
|
283
|
-
# ==== Examples
|
|
284
|
-
#
|
|
285
|
-
# number_to_human_size(123) # => 123 Bytes
|
|
286
|
-
# number_to_human_size(1234) # => 1.21 KB
|
|
287
|
-
# number_to_human_size(12345) # => 12.1 KB
|
|
288
|
-
# number_to_human_size(1234567) # => 1.18 MB
|
|
289
|
-
# number_to_human_size(1234567890) # => 1.15 GB
|
|
290
|
-
# number_to_human_size(1234567890123) # => 1.12 TB
|
|
291
|
-
# number_to_human_size(1234567890123456) # => 1.1 PB
|
|
292
|
-
# number_to_human_size(1234567890123456789) # => 1.07 EB
|
|
293
|
-
# number_to_human_size(1234567, precision: 2) # => 1.2 MB
|
|
294
|
-
# number_to_human_size(483989, precision: 2) # => 470 KB
|
|
295
|
-
# number_to_human_size(1234567, precision: 2, separator: ',') # => 1,2 MB
|
|
296
|
-
# number_to_human_size(1234567890123, precision: 5) # => "1.1228 TB"
|
|
297
|
-
# number_to_human_size(524288000, precision: 5) # => "500 MB"
|
|
298
99
|
def number_to_human_size(number, options = {})
|
|
299
100
|
delegate_number_helper_method(:number_to_human_size, number, options)
|
|
300
101
|
end
|
|
301
102
|
|
|
302
|
-
#
|
|
303
|
-
# is more readable by humans (e.g.: 1200000000 becomes "1.2
|
|
304
|
-
# Billion"). This is useful for numbers that can get very large
|
|
305
|
-
# (and too hard to read).
|
|
306
|
-
#
|
|
307
|
-
# See <tt>number_to_human_size</tt> if you want to print a file
|
|
308
|
-
# size.
|
|
309
|
-
#
|
|
310
|
-
# You can also define your own unit-quantifier names if you want
|
|
311
|
-
# to use other decimal units (e.g.: 1500 becomes "1.5
|
|
312
|
-
# kilometers", 0.150 becomes "150 milliliters", etc). You may
|
|
313
|
-
# define a wide range of unit quantifiers, even fractional ones
|
|
314
|
-
# (centi, deci, mili, etc).
|
|
315
|
-
#
|
|
316
|
-
# ==== Options
|
|
317
|
-
#
|
|
318
|
-
# * <tt>:locale</tt> - Sets the locale to be used for formatting
|
|
319
|
-
# (defaults to current locale).
|
|
320
|
-
# * <tt>:precision</tt> - Sets the precision of the number
|
|
321
|
-
# (defaults to 3).
|
|
322
|
-
# * <tt>:significant</tt> - If +true+, precision will be the number
|
|
323
|
-
# of significant_digits. If +false+, the number of fractional
|
|
324
|
-
# digits (defaults to +true+)
|
|
325
|
-
# * <tt>:separator</tt> - Sets the separator between the
|
|
326
|
-
# fractional and integer digits (defaults to ".").
|
|
327
|
-
# * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults
|
|
328
|
-
# to "").
|
|
329
|
-
# * <tt>:strip_insignificant_zeros</tt> - If +true+ removes
|
|
330
|
-
# insignificant zeros after the decimal separator (defaults to
|
|
331
|
-
# +true+)
|
|
332
|
-
# * <tt>:units</tt> - A Hash of unit quantifier names. Or a
|
|
333
|
-
# string containing an i18n scope where to find this hash. It
|
|
334
|
-
# might have the following keys:
|
|
335
|
-
# * *integers*: <tt>:unit</tt>, <tt>:ten</tt>,
|
|
336
|
-
# <tt>:hundred</tt>, <tt>:thousand</tt>, <tt>:million</tt>,
|
|
337
|
-
# <tt>:billion</tt>, <tt>:trillion</tt>,
|
|
338
|
-
# <tt>:quadrillion</tt>
|
|
339
|
-
# * *fractionals*: <tt>:deci</tt>, <tt>:centi</tt>,
|
|
340
|
-
# <tt>:mili</tt>, <tt>:micro</tt>, <tt>:nano</tt>,
|
|
341
|
-
# <tt>:pico</tt>, <tt>:femto</tt>
|
|
342
|
-
# * <tt>:format</tt> - Sets the format of the output string
|
|
343
|
-
# (defaults to "%n %u"). The field types are:
|
|
344
|
-
# * %u - The quantifier (ex.: 'thousand')
|
|
345
|
-
# * %n - The number
|
|
346
|
-
# * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when
|
|
347
|
-
# the argument is invalid.
|
|
348
|
-
#
|
|
349
|
-
# ==== Examples
|
|
350
|
-
#
|
|
351
|
-
# number_to_human(123) # => "123"
|
|
352
|
-
# number_to_human(1234) # => "1.23 Thousand"
|
|
353
|
-
# number_to_human(12345) # => "12.3 Thousand"
|
|
354
|
-
# number_to_human(1234567) # => "1.23 Million"
|
|
355
|
-
# number_to_human(1234567890) # => "1.23 Billion"
|
|
356
|
-
# number_to_human(1234567890123) # => "1.23 Trillion"
|
|
357
|
-
# number_to_human(1234567890123456) # => "1.23 Quadrillion"
|
|
358
|
-
# number_to_human(1234567890123456789) # => "1230 Quadrillion"
|
|
359
|
-
# number_to_human(489939, precision: 2) # => "490 Thousand"
|
|
360
|
-
# number_to_human(489939, precision: 4) # => "489.9 Thousand"
|
|
361
|
-
# number_to_human(1234567, precision: 4,
|
|
362
|
-
# significant: false) # => "1.2346 Million"
|
|
363
|
-
# number_to_human(1234567, precision: 1,
|
|
364
|
-
# separator: ',',
|
|
365
|
-
# significant: false) # => "1,2 Million"
|
|
366
|
-
#
|
|
367
|
-
# number_to_human(500000000, precision: 5) # => "500 Million"
|
|
368
|
-
# number_to_human(12345012345, significant: false) # => "12.345 Billion"
|
|
369
|
-
#
|
|
370
|
-
# Non-significant zeros after the decimal separator are stripped
|
|
371
|
-
# out by default (set <tt>:strip_insignificant_zeros</tt> to
|
|
372
|
-
# +false+ to change that):
|
|
373
|
-
#
|
|
374
|
-
# number_to_human(12.00001) # => "12"
|
|
375
|
-
# number_to_human(12.00001, strip_insignificant_zeros: false) # => "12.0"
|
|
376
|
-
#
|
|
377
|
-
# ==== Custom Unit Quantifiers
|
|
378
|
-
#
|
|
379
|
-
# You can also use your own custom unit quantifiers:
|
|
380
|
-
#
|
|
381
|
-
# number_to_human(500000, units: {unit: "ml", thousand: "lt"}) # => "500 lt"
|
|
382
|
-
#
|
|
383
|
-
# If in your I18n locale you have:
|
|
384
|
-
# distance:
|
|
385
|
-
# centi:
|
|
386
|
-
# one: "centimeter"
|
|
387
|
-
# other: "centimeters"
|
|
388
|
-
# unit:
|
|
389
|
-
# one: "meter"
|
|
390
|
-
# other: "meters"
|
|
391
|
-
# thousand:
|
|
392
|
-
# one: "kilometer"
|
|
393
|
-
# other: "kilometers"
|
|
394
|
-
# billion: "gazillion-distance"
|
|
103
|
+
# Delegates to ActiveSupport::NumberHelper#number_to_human.
|
|
395
104
|
#
|
|
396
|
-
#
|
|
105
|
+
# Additionally, supports a +:raise+ option that will cause
|
|
106
|
+
# InvalidNumberError to be raised if +number+ is not a valid number:
|
|
397
107
|
#
|
|
398
|
-
# number_to_human(
|
|
399
|
-
# number_to_human(
|
|
400
|
-
# number_to_human(54393498000, units: :distance) # => "54.4 gazillion-distance"
|
|
401
|
-
# number_to_human(343, units: :distance, precision: 1) # => "300 meters"
|
|
402
|
-
# number_to_human(1, units: :distance) # => "1 meter"
|
|
403
|
-
# number_to_human(0.34, units: :distance) # => "34 centimeters"
|
|
108
|
+
# number_to_human("12x34") # => "12x34"
|
|
109
|
+
# number_to_human("12x34", raise: true) # => InvalidNumberError
|
|
404
110
|
#
|
|
405
111
|
def number_to_human(number, options = {})
|
|
406
112
|
delegate_number_helper_method(:number_to_human, number, options)
|
|
@@ -24,11 +24,11 @@ module ActionView # :nodoc:
|
|
|
24
24
|
# the supplied separator, are HTML escaped unless they are HTML
|
|
25
25
|
# safe, and the returned string is marked as HTML safe.
|
|
26
26
|
#
|
|
27
|
-
# safe_join([
|
|
28
|
-
# # => "<p>foo</p><br
|
|
27
|
+
# safe_join([tag.p("foo"), "<p>bar</p>"], "<br>")
|
|
28
|
+
# # => "<p>foo</p><br><p>bar</p>"
|
|
29
29
|
#
|
|
30
|
-
# safe_join([
|
|
31
|
-
# # => "<p>foo</p><br
|
|
30
|
+
# safe_join([tag.p("foo"), tag.p("bar")], tag.br)
|
|
31
|
+
# # => "<p>foo</p><br><p>bar</p>"
|
|
32
32
|
#
|
|
33
33
|
def safe_join(array, sep = $,)
|
|
34
34
|
sep = ERB::Util.unwrapped_html_escape(sep)
|
|
@@ -38,8 +38,7 @@ module ActionView # :nodoc:
|
|
|
38
38
|
|
|
39
39
|
# Converts the array to a comma-separated sentence where the last element is
|
|
40
40
|
# joined by the connector word. This is the html_safe-aware version of
|
|
41
|
-
# ActiveSupport's
|
|
42
|
-
#
|
|
41
|
+
# ActiveSupport's Array#to_sentence.
|
|
43
42
|
def to_sentence(array, options = {})
|
|
44
43
|
options.assert_valid_keys(:words_connector, :two_words_connector, :last_word_connector, :locale)
|
|
45
44
|
|