actionview 7.0.8.7 → 7.0.9
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 +7 -0
- data/lib/action_view/gem_version.rb +2 -2
- data/lib/action_view/helpers/asset_tag_helper.rb +4 -4
- data/lib/action_view/helpers/form_helper.rb +7 -3
- data/lib/action_view/helpers/number_helper.rb +35 -329
- data/lib/action_view/helpers/sanitize_helper.rb +23 -12
- data/lib/action_view/helpers/text_helper.rb +122 -68
- data/lib/action_view/layouts.rb +2 -2
- data/lib/action_view/template.rb +2 -2
- metadata +12 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8a0267390880c963b6766d2d4cc29cc425b1973f30f8a9de8eaada4cadf9cea7
|
|
4
|
+
data.tar.gz: 4cbef355e28b2eef193075f0d7e2054e53a966f1031d2dbbfc23f1d09465d80d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 24ef119b1e6ccba5673fb17899c0ce8f6d6e532f0a4e73f002c986c70fa0801afa9278fbabeda4874946e98c38f511ae9f47c81946e900d8c5465b50d2b3b45e
|
|
7
|
+
data.tar.gz: 8a7db3249f7296506224decd96c793c02741c7b93d76f699c36b36495c16eb657c04c5d6f147e24c6e70ad8209730c91c118ce89eaea6e1045d944990c54b869
|
data/CHANGELOG.md
CHANGED
|
@@ -354,8 +354,8 @@ module ActionView
|
|
|
354
354
|
# You can add HTML attributes using the +options+. The +options+ supports
|
|
355
355
|
# additional keys for convenience and conformance:
|
|
356
356
|
#
|
|
357
|
-
# * <tt>:size</tt> - Supplied as "{
|
|
358
|
-
# width="30"
|
|
357
|
+
# * <tt>:size</tt> - Supplied as <tt>"#{width}x#{height}"</tt> or <tt>"#{number}"</tt>, so <tt>"30x45"</tt> becomes
|
|
358
|
+
# <tt>width="30" height="45"</tt>, and <tt>"50"</tt> becomes <tt>width="50" height="50"</tt>.
|
|
359
359
|
# <tt>:size</tt> will be ignored if the value is not in the correct format.
|
|
360
360
|
# * <tt>:srcset</tt> - If supplied as a hash or array of <tt>[source, descriptor]</tt>
|
|
361
361
|
# pairs, each image path will be expanded before the list is formatted as a string.
|
|
@@ -426,8 +426,8 @@ module ActionView
|
|
|
426
426
|
#
|
|
427
427
|
# * <tt>:poster</tt> - Set an image (like a screenshot) to be shown
|
|
428
428
|
# before the video loads. The path is calculated like the +src+ of +image_tag+.
|
|
429
|
-
# * <tt>:size</tt> - Supplied as "{
|
|
430
|
-
# width="30"
|
|
429
|
+
# * <tt>:size</tt> - Supplied as <tt>"#{width}x#{height}"</tt> or <tt>"#{number}"</tt>, so <tt>"30x45"</tt> becomes
|
|
430
|
+
# <tt>width="30" height="45"</tt>, and <tt>"50"</tt> becomes <tt>width="50" height="50"</tt>.
|
|
431
431
|
# <tt>:size</tt> will be ignored if the value is not in the correct format.
|
|
432
432
|
# * <tt>:poster_skip_pipeline</tt> will bypass the asset pipeline when using
|
|
433
433
|
# the <tt>:poster</tt> option instead using an asset in the public folder.
|
|
@@ -1002,8 +1002,8 @@ module ActionView
|
|
|
1002
1002
|
# <% end %>
|
|
1003
1003
|
#
|
|
1004
1004
|
# When a collection is used you might want to know the index of each
|
|
1005
|
-
# object
|
|
1006
|
-
#
|
|
1005
|
+
# object in the array. For this purpose, the <tt>index</tt> method is
|
|
1006
|
+
# available in the FormBuilder object.
|
|
1007
1007
|
#
|
|
1008
1008
|
# <%= form_for @person do |person_form| %>
|
|
1009
1009
|
# ...
|
|
@@ -1114,6 +1114,8 @@ module ActionView
|
|
|
1114
1114
|
# post:
|
|
1115
1115
|
# cost: "Total cost"
|
|
1116
1116
|
#
|
|
1117
|
+
# <code></code>
|
|
1118
|
+
#
|
|
1117
1119
|
# label(:post, :cost)
|
|
1118
1120
|
# # => <label for="post_cost">Total cost</label>
|
|
1119
1121
|
#
|
|
@@ -2239,7 +2241,7 @@ module ActionView
|
|
|
2239
2241
|
# <% end %>
|
|
2240
2242
|
#
|
|
2241
2243
|
# When a collection is used you might want to know the index of each
|
|
2242
|
-
# object
|
|
2244
|
+
# object in the array. For this purpose, the <tt>index</tt> method
|
|
2243
2245
|
# is available in the FormBuilder object.
|
|
2244
2246
|
#
|
|
2245
2247
|
# <%= form_for @person do |person_form| %>
|
|
@@ -2333,6 +2335,8 @@ module ActionView
|
|
|
2333
2335
|
# post:
|
|
2334
2336
|
# cost: "Total cost"
|
|
2335
2337
|
#
|
|
2338
|
+
# <code></code>
|
|
2339
|
+
#
|
|
2336
2340
|
# label(:cost)
|
|
2337
2341
|
# # => <label for="post_cost">Total cost</label>
|
|
2338
2342
|
#
|
|
@@ -23,42 +23,14 @@ module ActionView
|
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
#
|
|
27
|
-
# 123-9876). You can customize the format in the +options+ hash.
|
|
26
|
+
# Delegates to ActiveSupport::NumberHelper#number_to_phone.
|
|
28
27
|
#
|
|
29
|
-
#
|
|
28
|
+
# Additionally, supports a +:raise+ option that will cause
|
|
29
|
+
# InvalidNumberError to be raised if +number+ is not a valid number:
|
|
30
30
|
#
|
|
31
|
-
#
|
|
32
|
-
#
|
|
33
|
-
# (defaults to "-").
|
|
34
|
-
# * <tt>:extension</tt> - Specifies an extension to add to the
|
|
35
|
-
# end of the generated number.
|
|
36
|
-
# * <tt>:country_code</tt> - Sets the country code for the phone
|
|
37
|
-
# number.
|
|
38
|
-
# * <tt>:pattern</tt> - Specifies how the number is divided into three
|
|
39
|
-
# groups with the custom regexp to override the default format.
|
|
40
|
-
# * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when
|
|
41
|
-
# the argument is invalid.
|
|
31
|
+
# number_to_phone("12x34") # => "12x34"
|
|
32
|
+
# number_to_phone("12x34", raise: true) # => InvalidNumberError
|
|
42
33
|
#
|
|
43
|
-
# ==== Examples
|
|
44
|
-
#
|
|
45
|
-
# number_to_phone(5551234) # => 555-1234
|
|
46
|
-
# number_to_phone("5551234") # => 555-1234
|
|
47
|
-
# number_to_phone(1235551234) # => 123-555-1234
|
|
48
|
-
# number_to_phone(1235551234, area_code: true) # => (123) 555-1234
|
|
49
|
-
# number_to_phone(1235551234, delimiter: " ") # => 123 555 1234
|
|
50
|
-
# number_to_phone(1235551234, area_code: true, extension: 555) # => (123) 555-1234 x 555
|
|
51
|
-
# number_to_phone(1235551234, country_code: 1) # => +1-123-555-1234
|
|
52
|
-
# number_to_phone("123a456") # => 123a456
|
|
53
|
-
# number_to_phone("1234a567", raise: true) # => InvalidNumberError
|
|
54
|
-
#
|
|
55
|
-
# number_to_phone(1235551234, country_code: 1, extension: 1343, delimiter: ".")
|
|
56
|
-
# # => +1.123.555.1234 x 1343
|
|
57
|
-
#
|
|
58
|
-
# number_to_phone(75561234567, pattern: /(\d{1,4})(\d{4})(\d{4})$/, area_code: true)
|
|
59
|
-
# # => "(755) 6123-4567"
|
|
60
|
-
# number_to_phone(13312345678, pattern: /(\d{3})(\d{4})(\d{4})$/)
|
|
61
|
-
# # => "133-1234-5678"
|
|
62
34
|
def number_to_phone(number, options = {})
|
|
63
35
|
return unless number
|
|
64
36
|
options = options.symbolize_keys
|
|
@@ -67,339 +39,73 @@ module ActionView
|
|
|
67
39
|
ERB::Util.html_escape(ActiveSupport::NumberHelper.number_to_phone(number, options))
|
|
68
40
|
end
|
|
69
41
|
|
|
70
|
-
#
|
|
71
|
-
# can customize the format in the +options+ hash.
|
|
72
|
-
#
|
|
73
|
-
# The currency unit and number formatting of the current locale will be used
|
|
74
|
-
# unless otherwise specified in the provided options. No currency conversion
|
|
75
|
-
# is performed. If the user is given a way to change their locale, they will
|
|
76
|
-
# also be able to change the relative value of the currency displayed with
|
|
77
|
-
# this helper. If your application will ever support multiple locales, you
|
|
78
|
-
# may want to specify a constant <tt>:locale</tt> option or consider
|
|
79
|
-
# using a library capable of currency conversion.
|
|
42
|
+
# Delegates to ActiveSupport::NumberHelper#number_to_currency.
|
|
80
43
|
#
|
|
81
|
-
#
|
|
44
|
+
# Additionally, supports a +:raise+ option that will cause
|
|
45
|
+
# InvalidNumberError to be raised if +number+ is not a valid number:
|
|
82
46
|
#
|
|
83
|
-
#
|
|
84
|
-
# (
|
|
85
|
-
# * <tt>:precision</tt> - Sets the level of precision (defaults
|
|
86
|
-
# to 2).
|
|
87
|
-
# * <tt>:unit</tt> - Sets the denomination of the currency
|
|
88
|
-
# (defaults to "$").
|
|
89
|
-
# * <tt>:separator</tt> - Sets the separator between the units
|
|
90
|
-
# (defaults to ".").
|
|
91
|
-
# * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults
|
|
92
|
-
# to ",").
|
|
93
|
-
# * <tt>:format</tt> - Sets the format for non-negative numbers
|
|
94
|
-
# (defaults to "%u%n"). Fields are <tt>%u</tt> for the
|
|
95
|
-
# currency, and <tt>%n</tt> for the number.
|
|
96
|
-
# * <tt>:negative_format</tt> - Sets the format for negative
|
|
97
|
-
# numbers (defaults to prepending a hyphen to the formatted
|
|
98
|
-
# number given by <tt>:format</tt>). Accepts the same fields
|
|
99
|
-
# than <tt>:format</tt>, except <tt>%n</tt> is here the
|
|
100
|
-
# absolute value of the number.
|
|
101
|
-
# * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when
|
|
102
|
-
# the argument is invalid.
|
|
103
|
-
# * <tt>:strip_insignificant_zeros</tt> - If +true+ removes
|
|
104
|
-
# insignificant zeros after the decimal separator (defaults to
|
|
105
|
-
# +false+).
|
|
47
|
+
# number_to_currency("12x34") # => "$12x34"
|
|
48
|
+
# number_to_currency("12x34", raise: true) # => InvalidNumberError
|
|
106
49
|
#
|
|
107
|
-
# ==== Examples
|
|
108
|
-
#
|
|
109
|
-
# number_to_currency(1234567890.50) # => $1,234,567,890.50
|
|
110
|
-
# number_to_currency(1234567890.506) # => $1,234,567,890.51
|
|
111
|
-
# number_to_currency(1234567890.506, precision: 3) # => $1,234,567,890.506
|
|
112
|
-
# number_to_currency(1234567890.506, locale: :fr) # => 1 234 567 890,51 €
|
|
113
|
-
# number_to_currency("123a456") # => $123a456
|
|
114
|
-
#
|
|
115
|
-
# number_to_currency("123a456", raise: true) # => InvalidNumberError
|
|
116
|
-
#
|
|
117
|
-
# number_to_currency(-0.456789, precision: 0)
|
|
118
|
-
# # => "$0"
|
|
119
|
-
# number_to_currency(-1234567890.50, negative_format: "(%u%n)")
|
|
120
|
-
# # => ($1,234,567,890.50)
|
|
121
|
-
# number_to_currency(1234567890.50, unit: "R$", separator: ",", delimiter: "")
|
|
122
|
-
# # => R$1234567890,50
|
|
123
|
-
# number_to_currency(1234567890.50, unit: "R$", separator: ",", delimiter: "", format: "%n %u")
|
|
124
|
-
# # => 1234567890,50 R$
|
|
125
|
-
# number_to_currency(1234567890.50, strip_insignificant_zeros: true)
|
|
126
|
-
# # => "$1,234,567,890.5"
|
|
127
50
|
def number_to_currency(number, options = {})
|
|
128
51
|
delegate_number_helper_method(:number_to_currency, number, options)
|
|
129
52
|
end
|
|
130
53
|
|
|
131
|
-
#
|
|
132
|
-
# customize the format in the +options+ hash.
|
|
133
|
-
#
|
|
134
|
-
# ==== Options
|
|
54
|
+
# Delegates to ActiveSupport::NumberHelper#number_to_percentage.
|
|
135
55
|
#
|
|
136
|
-
#
|
|
137
|
-
#
|
|
138
|
-
# * <tt>:precision</tt> - Sets the precision of the number
|
|
139
|
-
# (defaults to 3).
|
|
140
|
-
# * <tt>:significant</tt> - If +true+, precision will be the number
|
|
141
|
-
# of significant_digits. If +false+, the number of fractional
|
|
142
|
-
# digits (defaults to +false+).
|
|
143
|
-
# * <tt>:separator</tt> - Sets the separator between the
|
|
144
|
-
# fractional and integer digits (defaults to ".").
|
|
145
|
-
# * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults
|
|
146
|
-
# to "").
|
|
147
|
-
# * <tt>:strip_insignificant_zeros</tt> - If +true+ removes
|
|
148
|
-
# insignificant zeros after the decimal separator (defaults to
|
|
149
|
-
# +false+).
|
|
150
|
-
# * <tt>:format</tt> - Specifies the format of the percentage
|
|
151
|
-
# string The number field is <tt>%n</tt> (defaults to "%n%").
|
|
152
|
-
# * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when
|
|
153
|
-
# the argument is invalid.
|
|
56
|
+
# Additionally, supports a +:raise+ option that will cause
|
|
57
|
+
# InvalidNumberError to be raised if +number+ is not a valid number:
|
|
154
58
|
#
|
|
155
|
-
#
|
|
59
|
+
# number_to_percentage("99x") # => "99x%"
|
|
60
|
+
# number_to_percentage("99x", raise: true) # => InvalidNumberError
|
|
156
61
|
#
|
|
157
|
-
# number_to_percentage(100) # => 100.000%
|
|
158
|
-
# number_to_percentage("98") # => 98.000%
|
|
159
|
-
# number_to_percentage(100, precision: 0) # => 100%
|
|
160
|
-
# number_to_percentage(1000, delimiter: '.', separator: ',') # => 1.000,000%
|
|
161
|
-
# number_to_percentage(302.24398923423, precision: 5) # => 302.24399%
|
|
162
|
-
# number_to_percentage(1000, locale: :fr) # => 1 000,000%
|
|
163
|
-
# number_to_percentage("98a") # => 98a%
|
|
164
|
-
# number_to_percentage(100, format: "%n %") # => 100.000 %
|
|
165
|
-
#
|
|
166
|
-
# number_to_percentage("98a", raise: true) # => InvalidNumberError
|
|
167
62
|
def number_to_percentage(number, options = {})
|
|
168
63
|
delegate_number_helper_method(:number_to_percentage, number, options)
|
|
169
64
|
end
|
|
170
65
|
|
|
171
|
-
#
|
|
172
|
-
# (e.g., 12,324). You can customize the format in the +options+
|
|
173
|
-
# hash.
|
|
174
|
-
#
|
|
175
|
-
# ==== Options
|
|
176
|
-
#
|
|
177
|
-
# * <tt>:locale</tt> - Sets the locale to be used for formatting
|
|
178
|
-
# (defaults to current locale).
|
|
179
|
-
# * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults
|
|
180
|
-
# to ",").
|
|
181
|
-
# * <tt>:separator</tt> - Sets the separator between the
|
|
182
|
-
# fractional and integer digits (defaults to ".").
|
|
183
|
-
# * <tt>:delimiter_pattern</tt> - Sets a custom regular expression used for
|
|
184
|
-
# deriving the placement of delimiter. Helpful when using currency formats
|
|
185
|
-
# like INR.
|
|
186
|
-
# * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when
|
|
187
|
-
# the argument is invalid.
|
|
188
|
-
#
|
|
189
|
-
# ==== Examples
|
|
66
|
+
# Delegates to ActiveSupport::NumberHelper#number_to_delimited.
|
|
190
67
|
#
|
|
191
|
-
#
|
|
192
|
-
#
|
|
193
|
-
# number_with_delimiter(12345678.05) # => 12,345,678.05
|
|
194
|
-
# number_with_delimiter(12345678, delimiter: ".") # => 12.345.678
|
|
195
|
-
# number_with_delimiter(12345678, delimiter: ",") # => 12,345,678
|
|
196
|
-
# number_with_delimiter(12345678.05, separator: " ") # => 12,345,678 05
|
|
197
|
-
# number_with_delimiter(12345678.05, locale: :fr) # => 12 345 678,05
|
|
198
|
-
# number_with_delimiter("112a") # => 112a
|
|
199
|
-
# number_with_delimiter(98765432.98, delimiter: " ", separator: ",")
|
|
200
|
-
# # => 98 765 432,98
|
|
68
|
+
# Additionally, supports a +:raise+ option that will cause
|
|
69
|
+
# InvalidNumberError to be raised if +number+ is not a valid number:
|
|
201
70
|
#
|
|
202
|
-
# number_with_delimiter("
|
|
203
|
-
#
|
|
71
|
+
# number_with_delimiter("12x34") # => "12x34"
|
|
72
|
+
# number_with_delimiter("12x34", raise: true) # => InvalidNumberError
|
|
204
73
|
#
|
|
205
|
-
# number_with_delimiter("112a", raise: true) # => raise InvalidNumberError
|
|
206
74
|
def number_with_delimiter(number, options = {})
|
|
207
75
|
delegate_number_helper_method(:number_to_delimited, number, options)
|
|
208
76
|
end
|
|
209
77
|
|
|
210
|
-
#
|
|
211
|
-
# <tt>:precision</tt> (e.g., 112.32 has a precision of 2 if
|
|
212
|
-
# +:significant+ is +false+, and 5 if +:significant+ is +true+).
|
|
213
|
-
# You can customize the format in the +options+ hash.
|
|
214
|
-
#
|
|
215
|
-
# ==== Options
|
|
216
|
-
#
|
|
217
|
-
# * <tt>:locale</tt> - Sets the locale to be used for formatting
|
|
218
|
-
# (defaults to current locale).
|
|
219
|
-
# * <tt>:precision</tt> - Sets the precision of the number
|
|
220
|
-
# (defaults to 3).
|
|
221
|
-
# * <tt>:significant</tt> - If +true+, precision will be the number
|
|
222
|
-
# of significant_digits. If +false+, the number of fractional
|
|
223
|
-
# digits (defaults to +false+).
|
|
224
|
-
# * <tt>:separator</tt> - Sets the separator between the
|
|
225
|
-
# fractional and integer digits (defaults to ".").
|
|
226
|
-
# * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults
|
|
227
|
-
# to "").
|
|
228
|
-
# * <tt>:strip_insignificant_zeros</tt> - If +true+ removes
|
|
229
|
-
# insignificant zeros after the decimal separator (defaults to
|
|
230
|
-
# +false+).
|
|
231
|
-
# * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when
|
|
232
|
-
# the argument is invalid.
|
|
233
|
-
#
|
|
234
|
-
# ==== Examples
|
|
78
|
+
# Delegates to ActiveSupport::NumberHelper#number_to_rounded.
|
|
235
79
|
#
|
|
236
|
-
#
|
|
237
|
-
#
|
|
238
|
-
# number_with_precision(13, precision: 5) # => 13.00000
|
|
239
|
-
# number_with_precision(389.32314, precision: 0) # => 389
|
|
240
|
-
# number_with_precision(111.2345, significant: true) # => 111
|
|
241
|
-
# number_with_precision(111.2345, precision: 1, significant: true) # => 100
|
|
242
|
-
# number_with_precision(13, precision: 5, significant: true) # => 13.000
|
|
243
|
-
# number_with_precision(111.234, locale: :fr) # => 111,234
|
|
80
|
+
# Additionally, supports a +:raise+ option that will cause
|
|
81
|
+
# InvalidNumberError to be raised if +number+ is not a valid number:
|
|
244
82
|
#
|
|
245
|
-
# number_with_precision(
|
|
246
|
-
# # =>
|
|
83
|
+
# number_with_precision("12x34") # => "12x34"
|
|
84
|
+
# number_with_precision("12x34", raise: true) # => InvalidNumberError
|
|
247
85
|
#
|
|
248
|
-
# number_with_precision(389.32314, precision: 4, significant: true) # => 389.3
|
|
249
|
-
# number_with_precision(1111.2345, precision: 2, separator: ',', delimiter: '.')
|
|
250
|
-
# # => 1.111,23
|
|
251
86
|
def number_with_precision(number, options = {})
|
|
252
87
|
delegate_number_helper_method(:number_to_rounded, number, options)
|
|
253
88
|
end
|
|
254
89
|
|
|
255
|
-
#
|
|
256
|
-
# representation (e.g., giving it 1500 yields 1.46 KB). This
|
|
257
|
-
# method is useful for reporting file sizes to users. You can
|
|
258
|
-
# customize the format in the +options+ hash.
|
|
90
|
+
# Delegates to ActiveSupport::NumberHelper#number_to_human_size.
|
|
259
91
|
#
|
|
260
|
-
#
|
|
261
|
-
#
|
|
92
|
+
# Additionally, supports a +:raise+ option that will cause
|
|
93
|
+
# InvalidNumberError to be raised if +number+ is not a valid number:
|
|
262
94
|
#
|
|
263
|
-
#
|
|
95
|
+
# number_to_human_size("12x34") # => "12x34"
|
|
96
|
+
# number_to_human_size("12x34", raise: true) # => InvalidNumberError
|
|
264
97
|
#
|
|
265
|
-
# * <tt>:locale</tt> - Sets the locale to be used for formatting
|
|
266
|
-
# (defaults to current locale).
|
|
267
|
-
# * <tt>:precision</tt> - Sets the precision of the number
|
|
268
|
-
# (defaults to 3).
|
|
269
|
-
# * <tt>:significant</tt> - If +true+, precision will be the number
|
|
270
|
-
# of significant_digits. If +false+, the number of fractional
|
|
271
|
-
# digits (defaults to +true+)
|
|
272
|
-
# * <tt>:separator</tt> - Sets the separator between the
|
|
273
|
-
# fractional and integer digits (defaults to ".").
|
|
274
|
-
# * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults
|
|
275
|
-
# to "").
|
|
276
|
-
# * <tt>:strip_insignificant_zeros</tt> - If +true+ removes
|
|
277
|
-
# insignificant zeros after the decimal separator (defaults to
|
|
278
|
-
# +true+)
|
|
279
|
-
# * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when
|
|
280
|
-
# the argument is invalid.
|
|
281
|
-
#
|
|
282
|
-
# ==== Examples
|
|
283
|
-
#
|
|
284
|
-
# number_to_human_size(123) # => 123 Bytes
|
|
285
|
-
# number_to_human_size(1234) # => 1.21 KB
|
|
286
|
-
# number_to_human_size(12345) # => 12.1 KB
|
|
287
|
-
# number_to_human_size(1234567) # => 1.18 MB
|
|
288
|
-
# number_to_human_size(1234567890) # => 1.15 GB
|
|
289
|
-
# number_to_human_size(1234567890123) # => 1.12 TB
|
|
290
|
-
# number_to_human_size(1234567890123456) # => 1.1 PB
|
|
291
|
-
# number_to_human_size(1234567890123456789) # => 1.07 EB
|
|
292
|
-
# number_to_human_size(1234567, precision: 2) # => 1.2 MB
|
|
293
|
-
# number_to_human_size(483989, precision: 2) # => 470 KB
|
|
294
|
-
# number_to_human_size(1234567, precision: 2, separator: ',') # => 1,2 MB
|
|
295
|
-
# number_to_human_size(1234567890123, precision: 5) # => "1.1228 TB"
|
|
296
|
-
# number_to_human_size(524288000, precision: 5) # => "500 MB"
|
|
297
98
|
def number_to_human_size(number, options = {})
|
|
298
99
|
delegate_number_helper_method(:number_to_human_size, number, options)
|
|
299
100
|
end
|
|
300
101
|
|
|
301
|
-
#
|
|
302
|
-
# is more readable by humans (e.g.: 1200000000 becomes "1.2
|
|
303
|
-
# Billion"). This is useful for numbers that can get very large
|
|
304
|
-
# (and too hard to read).
|
|
305
|
-
#
|
|
306
|
-
# See <tt>number_to_human_size</tt> if you want to print a file
|
|
307
|
-
# size.
|
|
308
|
-
#
|
|
309
|
-
# You can also define your own unit-quantifier names if you want
|
|
310
|
-
# to use other decimal units (e.g.: 1500 becomes "1.5
|
|
311
|
-
# kilometers", 0.150 becomes "150 milliliters", etc). You may
|
|
312
|
-
# define a wide range of unit quantifiers, even fractional ones
|
|
313
|
-
# (centi, deci, mili, etc).
|
|
314
|
-
#
|
|
315
|
-
# ==== Options
|
|
316
|
-
#
|
|
317
|
-
# * <tt>:locale</tt> - Sets the locale to be used for formatting
|
|
318
|
-
# (defaults to current locale).
|
|
319
|
-
# * <tt>:precision</tt> - Sets the precision of the number
|
|
320
|
-
# (defaults to 3).
|
|
321
|
-
# * <tt>:significant</tt> - If +true+, precision will be the number
|
|
322
|
-
# of significant_digits. If +false+, the number of fractional
|
|
323
|
-
# digits (defaults to +true+)
|
|
324
|
-
# * <tt>:separator</tt> - Sets the separator between the
|
|
325
|
-
# fractional and integer digits (defaults to ".").
|
|
326
|
-
# * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults
|
|
327
|
-
# to "").
|
|
328
|
-
# * <tt>:strip_insignificant_zeros</tt> - If +true+ removes
|
|
329
|
-
# insignificant zeros after the decimal separator (defaults to
|
|
330
|
-
# +true+)
|
|
331
|
-
# * <tt>:units</tt> - A Hash of unit quantifier names. Or a
|
|
332
|
-
# string containing an i18n scope where to find this hash. It
|
|
333
|
-
# might have the following keys:
|
|
334
|
-
# * *integers*: <tt>:unit</tt>, <tt>:ten</tt>,
|
|
335
|
-
# <tt>:hundred</tt>, <tt>:thousand</tt>, <tt>:million</tt>,
|
|
336
|
-
# <tt>:billion</tt>, <tt>:trillion</tt>,
|
|
337
|
-
# <tt>:quadrillion</tt>
|
|
338
|
-
# * *fractionals*: <tt>:deci</tt>, <tt>:centi</tt>,
|
|
339
|
-
# <tt>:mili</tt>, <tt>:micro</tt>, <tt>:nano</tt>,
|
|
340
|
-
# <tt>:pico</tt>, <tt>:femto</tt>
|
|
341
|
-
# * <tt>:format</tt> - Sets the format of the output string
|
|
342
|
-
# (defaults to "%n %u"). The field types are:
|
|
343
|
-
# * %u - The quantifier (ex.: 'thousand')
|
|
344
|
-
# * %n - The number
|
|
345
|
-
# * <tt>:raise</tt> - If true, raises +InvalidNumberError+ when
|
|
346
|
-
# the argument is invalid.
|
|
347
|
-
#
|
|
348
|
-
# ==== Examples
|
|
349
|
-
#
|
|
350
|
-
# number_to_human(123) # => "123"
|
|
351
|
-
# number_to_human(1234) # => "1.23 Thousand"
|
|
352
|
-
# number_to_human(12345) # => "12.3 Thousand"
|
|
353
|
-
# number_to_human(1234567) # => "1.23 Million"
|
|
354
|
-
# number_to_human(1234567890) # => "1.23 Billion"
|
|
355
|
-
# number_to_human(1234567890123) # => "1.23 Trillion"
|
|
356
|
-
# number_to_human(1234567890123456) # => "1.23 Quadrillion"
|
|
357
|
-
# number_to_human(1234567890123456789) # => "1230 Quadrillion"
|
|
358
|
-
# number_to_human(489939, precision: 2) # => "490 Thousand"
|
|
359
|
-
# number_to_human(489939, precision: 4) # => "489.9 Thousand"
|
|
360
|
-
# number_to_human(1234567, precision: 4,
|
|
361
|
-
# significant: false) # => "1.2346 Million"
|
|
362
|
-
# number_to_human(1234567, precision: 1,
|
|
363
|
-
# separator: ',',
|
|
364
|
-
# significant: false) # => "1,2 Million"
|
|
365
|
-
#
|
|
366
|
-
# number_to_human(500000000, precision: 5) # => "500 Million"
|
|
367
|
-
# number_to_human(12345012345, significant: false) # => "12.345 Billion"
|
|
368
|
-
#
|
|
369
|
-
# Non-significant zeros after the decimal separator are stripped
|
|
370
|
-
# out by default (set <tt>:strip_insignificant_zeros</tt> to
|
|
371
|
-
# +false+ to change that):
|
|
372
|
-
#
|
|
373
|
-
# number_to_human(12.00001) # => "12"
|
|
374
|
-
# number_to_human(12.00001, strip_insignificant_zeros: false) # => "12.0"
|
|
375
|
-
#
|
|
376
|
-
# ==== Custom Unit Quantifiers
|
|
377
|
-
#
|
|
378
|
-
# You can also use your own custom unit quantifiers:
|
|
379
|
-
#
|
|
380
|
-
# number_to_human(500000, units: {unit: "ml", thousand: "lt"}) # => "500 lt"
|
|
381
|
-
#
|
|
382
|
-
# If in your I18n locale you have:
|
|
383
|
-
# distance:
|
|
384
|
-
# centi:
|
|
385
|
-
# one: "centimeter"
|
|
386
|
-
# other: "centimeters"
|
|
387
|
-
# unit:
|
|
388
|
-
# one: "meter"
|
|
389
|
-
# other: "meters"
|
|
390
|
-
# thousand:
|
|
391
|
-
# one: "kilometer"
|
|
392
|
-
# other: "kilometers"
|
|
393
|
-
# billion: "gazillion-distance"
|
|
102
|
+
# Delegates to ActiveSupport::NumberHelper#number_to_human.
|
|
394
103
|
#
|
|
395
|
-
#
|
|
104
|
+
# Additionally, supports a +:raise+ option that will cause
|
|
105
|
+
# InvalidNumberError to be raised if +number+ is not a valid number:
|
|
396
106
|
#
|
|
397
|
-
# number_to_human(
|
|
398
|
-
# number_to_human(
|
|
399
|
-
# number_to_human(54393498000, units: :distance) # => "54.4 gazillion-distance"
|
|
400
|
-
# number_to_human(343, units: :distance, precision: 1) # => "300 meters"
|
|
401
|
-
# number_to_human(1, units: :distance) # => "1 meter"
|
|
402
|
-
# number_to_human(0.34, units: :distance) # => "34 centimeters"
|
|
107
|
+
# number_to_human("12x34") # => "12x34"
|
|
108
|
+
# number_to_human("12x34", raise: true) # => InvalidNumberError
|
|
403
109
|
#
|
|
404
110
|
def number_to_human(number, options = {})
|
|
405
111
|
delegate_number_helper_method(:number_to_human, number, options)
|
|
@@ -11,12 +11,12 @@ module ActionView
|
|
|
11
11
|
extend ActiveSupport::Concern
|
|
12
12
|
# Sanitizes HTML input, stripping all but known-safe tags and attributes.
|
|
13
13
|
#
|
|
14
|
-
# It also strips href/src attributes with unsafe protocols like
|
|
14
|
+
# It also strips +href+ / +src+ attributes with unsafe protocols like
|
|
15
15
|
# <tt>javascript:</tt>, while also protecting against attempts to use Unicode,
|
|
16
16
|
# ASCII, and hex character references to work around these protocol filters.
|
|
17
17
|
# All special characters will be escaped.
|
|
18
18
|
#
|
|
19
|
-
# The default sanitizer is Rails::Html::SafeListSanitizer
|
|
19
|
+
# The default sanitizer is +Rails::Html::SafeListSanitizer+. See {Rails HTML
|
|
20
20
|
# Sanitizers}[https://github.com/rails/rails-html-sanitizer] for more information.
|
|
21
21
|
#
|
|
22
22
|
# Custom sanitization rules can also be provided.
|
|
@@ -26,24 +26,29 @@ module ActionView
|
|
|
26
26
|
#
|
|
27
27
|
# ==== Options
|
|
28
28
|
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
29
|
+
# [+:tags+]
|
|
30
|
+
# An array of allowed tags.
|
|
31
|
+
#
|
|
32
|
+
# [+:attributes+]
|
|
33
|
+
# An array of allowed attributes.
|
|
34
|
+
#
|
|
35
|
+
# [+:scrubber+]
|
|
36
|
+
# A {Rails::Html scrubber}[https://github.com/rails/rails-html-sanitizer]
|
|
32
37
|
# or {Loofah::Scrubber}[https://github.com/flavorjones/loofah] object that
|
|
33
38
|
# defines custom sanitization rules. A custom scrubber takes precedence over
|
|
34
39
|
# custom tags and attributes.
|
|
35
40
|
#
|
|
36
41
|
# ==== Examples
|
|
37
42
|
#
|
|
38
|
-
# Normal use
|
|
43
|
+
# ===== Normal use
|
|
39
44
|
#
|
|
40
45
|
# <%= sanitize @comment.body %>
|
|
41
46
|
#
|
|
42
|
-
# Providing custom lists of permitted tags and attributes
|
|
47
|
+
# ===== Providing custom lists of permitted tags and attributes
|
|
43
48
|
#
|
|
44
49
|
# <%= sanitize @comment.body, tags: %w(strong em a), attributes: %w(href) %>
|
|
45
50
|
#
|
|
46
|
-
# Providing a custom Rails::Html scrubber
|
|
51
|
+
# ===== Providing a custom +Rails::Html+ scrubber
|
|
47
52
|
#
|
|
48
53
|
# class CommentScrubber < Rails::Html::PermitScrubber
|
|
49
54
|
# def initialize
|
|
@@ -57,21 +62,27 @@ module ActionView
|
|
|
57
62
|
# end
|
|
58
63
|
# end
|
|
59
64
|
#
|
|
65
|
+
# <code></code>
|
|
66
|
+
#
|
|
60
67
|
# <%= sanitize @comment.body, scrubber: CommentScrubber.new %>
|
|
61
68
|
#
|
|
62
69
|
# See {Rails HTML Sanitizer}[https://github.com/rails/rails-html-sanitizer] for
|
|
63
|
-
# documentation about Rails::Html scrubbers.
|
|
70
|
+
# documentation about +Rails::Html+ scrubbers.
|
|
64
71
|
#
|
|
65
|
-
# Providing a custom Loofah::Scrubber
|
|
72
|
+
# ===== Providing a custom +Loofah::Scrubber+
|
|
66
73
|
#
|
|
67
74
|
# scrubber = Loofah::Scrubber.new do |node|
|
|
68
75
|
# node.remove if node.name == 'script'
|
|
69
76
|
# end
|
|
70
77
|
#
|
|
78
|
+
# <code></code>
|
|
79
|
+
#
|
|
71
80
|
# <%= sanitize @comment.body, scrubber: scrubber %>
|
|
72
81
|
#
|
|
73
82
|
# See {Loofah's documentation}[https://github.com/flavorjones/loofah] for more
|
|
74
|
-
# information about defining custom Loofah::Scrubber objects.
|
|
83
|
+
# information about defining custom +Loofah::Scrubber+ objects.
|
|
84
|
+
#
|
|
85
|
+
# ==== Global Configuration
|
|
75
86
|
#
|
|
76
87
|
# To set the default allowed tags or attributes across your application:
|
|
77
88
|
#
|
|
@@ -82,7 +93,7 @@ module ActionView
|
|
|
82
93
|
self.class.safe_list_sanitizer.sanitize(html, options)&.html_safe
|
|
83
94
|
end
|
|
84
95
|
|
|
85
|
-
# Sanitizes a block of CSS code. Used by
|
|
96
|
+
# Sanitizes a block of CSS code. Used by #sanitize when it comes across a style attribute.
|
|
86
97
|
def sanitize_css(style)
|
|
87
98
|
self.class.safe_list_sanitizer.sanitize_css(style)
|
|
88
99
|
end
|
|
@@ -40,21 +40,25 @@ module ActionView
|
|
|
40
40
|
include OutputSafetyHelper
|
|
41
41
|
|
|
42
42
|
# The preferred method of outputting text in your views is to use the
|
|
43
|
-
#
|
|
43
|
+
# <tt><%= "text" %></tt> eRuby syntax. The regular +puts+ and +print+ methods
|
|
44
44
|
# do not operate as expected in an eRuby code block. If you absolutely must
|
|
45
|
-
# output text within a non-output code block (i.e.,
|
|
45
|
+
# output text within a non-output code block (i.e., <tt><% %></tt>), you
|
|
46
|
+
# can use the +concat+ method.
|
|
47
|
+
#
|
|
48
|
+
# <% concat "hello" %> is equivalent to <%= "hello" %>
|
|
46
49
|
#
|
|
47
50
|
# <%
|
|
48
|
-
#
|
|
49
|
-
#
|
|
50
|
-
#
|
|
51
|
-
# if logged_in
|
|
52
|
-
# concat "Logged in!"
|
|
53
|
-
# else
|
|
54
|
-
# concat link_to('login', action: :login)
|
|
55
|
-
# end
|
|
56
|
-
# # will either display "Logged in!" or a login link
|
|
51
|
+
# unless signed_in?
|
|
52
|
+
# concat link_to("Sign In", action: :sign_in)
|
|
53
|
+
# end
|
|
57
54
|
# %>
|
|
55
|
+
#
|
|
56
|
+
# is equivalent to
|
|
57
|
+
#
|
|
58
|
+
# <% unless signed_in? %>
|
|
59
|
+
# <%= link_to "Sign In", action: :sign_in %>
|
|
60
|
+
# <% end %>
|
|
61
|
+
#
|
|
58
62
|
def concat(string)
|
|
59
63
|
output_buffer << string
|
|
60
64
|
end
|
|
@@ -63,17 +67,36 @@ module ActionView
|
|
|
63
67
|
output_buffer.respond_to?(:safe_concat) ? output_buffer.safe_concat(string) : concat(string)
|
|
64
68
|
end
|
|
65
69
|
|
|
66
|
-
# Truncates
|
|
67
|
-
#
|
|
68
|
-
#
|
|
70
|
+
# Truncates +text+ if it is longer than a specified +:length+. If +text+
|
|
71
|
+
# is truncated, an omission marker will be appended to the result for a
|
|
72
|
+
# total length not exceeding +:length+.
|
|
73
|
+
#
|
|
74
|
+
# You can also pass a block to render and append extra content after the
|
|
75
|
+
# omission marker when +text+ is truncated. However, this content _can_
|
|
76
|
+
# cause the total length to exceed +:length+ characters.
|
|
69
77
|
#
|
|
70
|
-
#
|
|
78
|
+
# The result will be escaped unless <tt>escape: false</tt> is specified.
|
|
79
|
+
# In any case, the result will be marked HTML-safe. Care should be taken
|
|
80
|
+
# if +text+ might contain HTML tags or entities, because truncation could
|
|
81
|
+
# produce invalid HTML, such as unbalanced or incomplete tags.
|
|
71
82
|
#
|
|
72
|
-
#
|
|
83
|
+
# ==== Options
|
|
73
84
|
#
|
|
74
|
-
#
|
|
75
|
-
#
|
|
76
|
-
#
|
|
85
|
+
# [+:length+]
|
|
86
|
+
# The maximum number of characters that should be returned, excluding
|
|
87
|
+
# any extra content from the block. Defaults to 30.
|
|
88
|
+
#
|
|
89
|
+
# [+:omission+]
|
|
90
|
+
# The string to append after truncating. Defaults to <tt>"..."</tt>.
|
|
91
|
+
#
|
|
92
|
+
# [+:separator+]
|
|
93
|
+
# A string or regexp used to find a breaking point at which to truncate.
|
|
94
|
+
# By default, truncation can occur at any character in +text+.
|
|
95
|
+
#
|
|
96
|
+
# [+:escape+]
|
|
97
|
+
# Whether to escape the result. Defaults to true.
|
|
98
|
+
#
|
|
99
|
+
# ==== Examples
|
|
77
100
|
#
|
|
78
101
|
# truncate("Once upon a time in a world far far away")
|
|
79
102
|
# # => "Once upon a time in a world..."
|
|
@@ -94,7 +117,7 @@ module ActionView
|
|
|
94
117
|
# # => "<p>Once upon a time in a wo..."
|
|
95
118
|
#
|
|
96
119
|
# truncate("Once upon a time in a world far far away") { link_to "Continue", "#" }
|
|
97
|
-
# # => "Once upon a time in a
|
|
120
|
+
# # => "Once upon a time in a world...<a href=\"#\">Continue</a>"
|
|
98
121
|
def truncate(text, options = {}, &block)
|
|
99
122
|
if text
|
|
100
123
|
length = options.fetch(:length, 30)
|
|
@@ -106,33 +129,47 @@ module ActionView
|
|
|
106
129
|
end
|
|
107
130
|
end
|
|
108
131
|
|
|
109
|
-
# Highlights
|
|
110
|
-
#
|
|
111
|
-
#
|
|
112
|
-
#
|
|
113
|
-
#
|
|
114
|
-
#
|
|
132
|
+
# Highlights occurrences of +phrases+ in +text+ by formatting them with a
|
|
133
|
+
# highlighter string. +phrases+ can be one or more strings or regular
|
|
134
|
+
# expressions. The result will be marked HTML safe. By default, +text+ is
|
|
135
|
+
# sanitized before highlighting to prevent possible XSS attacks.
|
|
136
|
+
#
|
|
137
|
+
# If a block is specified, it will be used instead of the highlighter
|
|
138
|
+
# string. Each occurrence of a phrase will be passed to the block, and its
|
|
139
|
+
# return value will be inserted into the final result.
|
|
140
|
+
#
|
|
141
|
+
# ==== Options
|
|
142
|
+
#
|
|
143
|
+
# [+:highlighter+]
|
|
144
|
+
# The highlighter string. Uses <tt>\1</tt> as the placeholder for a
|
|
145
|
+
# phrase, similar to +String#sub+. Defaults to <tt>"<mark>\1</mark>"</tt>.
|
|
146
|
+
# This option is ignored if a block is specified.
|
|
147
|
+
#
|
|
148
|
+
# [+:sanitize+]
|
|
149
|
+
# Whether to sanitize +text+ before highlighting. Defaults to true.
|
|
150
|
+
#
|
|
151
|
+
# ==== Examples
|
|
115
152
|
#
|
|
116
153
|
# highlight('You searched for: rails', 'rails')
|
|
117
|
-
# # => You searched for: <mark>rails</mark>
|
|
154
|
+
# # => "You searched for: <mark>rails</mark>"
|
|
118
155
|
#
|
|
119
156
|
# highlight('You searched for: rails', /for|rails/)
|
|
120
|
-
# # => You searched <mark>for</mark>: <mark>rails</mark>
|
|
157
|
+
# # => "You searched <mark>for</mark>: <mark>rails</mark>"
|
|
121
158
|
#
|
|
122
159
|
# highlight('You searched for: ruby, rails, dhh', 'actionpack')
|
|
123
|
-
# # => You searched for: ruby, rails, dhh
|
|
160
|
+
# # => "You searched for: ruby, rails, dhh"
|
|
124
161
|
#
|
|
125
162
|
# highlight('You searched for: rails', ['for', 'rails'], highlighter: '<em>\1</em>')
|
|
126
|
-
# # => You searched <em>for</em>: <em>rails</em>
|
|
163
|
+
# # => "You searched <em>for</em>: <em>rails</em>"
|
|
127
164
|
#
|
|
128
165
|
# highlight('You searched for: rails', 'rails', highlighter: '<a href="search?q=\1">\1</a>')
|
|
129
|
-
# # => You searched for: <a href
|
|
166
|
+
# # => "You searched for: <a href=\"search?q=rails\">rails</a>"
|
|
130
167
|
#
|
|
131
168
|
# highlight('You searched for: rails', 'rails') { |match| link_to(search_path(q: match, match)) }
|
|
132
|
-
# # => You searched for: <a href
|
|
169
|
+
# # => "You searched for: <a href=\"search?q=rails\">rails</a>"
|
|
133
170
|
#
|
|
134
171
|
# highlight('<a href="javascript:alert(\'no!\')">ruby</a> on rails', 'rails', sanitize: false)
|
|
135
|
-
# # => <a href
|
|
172
|
+
# # => "<a href=\"javascript:alert('no!')\">ruby</a> on <mark>rails</mark>"
|
|
136
173
|
def highlight(text, phrases, options = {}, &block)
|
|
137
174
|
text = sanitize(text) if options.fetch(:sanitize, true)
|
|
138
175
|
|
|
@@ -152,30 +189,45 @@ module ActionView
|
|
|
152
189
|
end.html_safe
|
|
153
190
|
end
|
|
154
191
|
|
|
155
|
-
# Extracts
|
|
156
|
-
#
|
|
157
|
-
#
|
|
158
|
-
#
|
|
159
|
-
#
|
|
160
|
-
#
|
|
192
|
+
# Extracts the first occurrence of +phrase+ plus surrounding text from
|
|
193
|
+
# +text+. An omission marker is prepended / appended if the start / end of
|
|
194
|
+
# the result does not coincide with the start / end of +text+. The result
|
|
195
|
+
# is always stripped in any case. Returns +nil+ if +phrase+ isn't found.
|
|
196
|
+
#
|
|
197
|
+
# ==== Options
|
|
198
|
+
#
|
|
199
|
+
# [+:radius+]
|
|
200
|
+
# The number of characters (or tokens — see +:separator+ option) around
|
|
201
|
+
# +phrase+ to include in the result. Defaults to 100.
|
|
202
|
+
#
|
|
203
|
+
# [+:omission+]
|
|
204
|
+
# The marker to prepend / append when the start / end of the excerpt
|
|
205
|
+
# does not coincide with the start / end of +text+. Defaults to
|
|
206
|
+
# <tt>"..."</tt>.
|
|
207
|
+
#
|
|
208
|
+
# [+:separator+]
|
|
209
|
+
# The separator between tokens to count for +:radius+. Defaults to
|
|
210
|
+
# <tt>""</tt>, which treats each character as a token.
|
|
211
|
+
#
|
|
212
|
+
# ==== Examples
|
|
161
213
|
#
|
|
162
214
|
# excerpt('This is an example', 'an', radius: 5)
|
|
163
|
-
# # => ...s is an exam...
|
|
215
|
+
# # => "...s is an exam..."
|
|
164
216
|
#
|
|
165
217
|
# excerpt('This is an example', 'is', radius: 5)
|
|
166
|
-
# # => This is a...
|
|
218
|
+
# # => "This is a..."
|
|
167
219
|
#
|
|
168
220
|
# excerpt('This is an example', 'is')
|
|
169
|
-
# # => This is an example
|
|
221
|
+
# # => "This is an example"
|
|
170
222
|
#
|
|
171
223
|
# excerpt('This next thing is an example', 'ex', radius: 2)
|
|
172
|
-
# # => ...next...
|
|
224
|
+
# # => "...next..."
|
|
173
225
|
#
|
|
174
226
|
# excerpt('This is also an example', 'an', radius: 8, omission: '<chop> ')
|
|
175
|
-
# # => <chop> is also an example
|
|
227
|
+
# # => "<chop> is also an example"
|
|
176
228
|
#
|
|
177
229
|
# excerpt('This is a very beautiful morning', 'very', separator: ' ', radius: 1)
|
|
178
|
-
# # => ...a very beautiful...
|
|
230
|
+
# # => "...a very beautiful..."
|
|
179
231
|
def excerpt(text, phrase, options = {})
|
|
180
232
|
return unless text && phrase
|
|
181
233
|
|
|
@@ -211,26 +263,26 @@ module ActionView
|
|
|
211
263
|
# Attempts to pluralize the +singular+ word unless +count+ is 1. If
|
|
212
264
|
# +plural+ is supplied, it will use that when count is > 1, otherwise
|
|
213
265
|
# it will use the Inflector to determine the plural form for the given locale,
|
|
214
|
-
# which defaults to I18n.locale
|
|
266
|
+
# which defaults to +I18n.locale+.
|
|
215
267
|
#
|
|
216
268
|
# The word will be pluralized using rules defined for the locale
|
|
217
269
|
# (you must define your own inflection rules for languages other than English).
|
|
218
270
|
# See ActiveSupport::Inflector.pluralize
|
|
219
271
|
#
|
|
220
272
|
# pluralize(1, 'person')
|
|
221
|
-
# # => 1 person
|
|
273
|
+
# # => "1 person"
|
|
222
274
|
#
|
|
223
275
|
# pluralize(2, 'person')
|
|
224
|
-
# # => 2 people
|
|
276
|
+
# # => "2 people"
|
|
225
277
|
#
|
|
226
278
|
# pluralize(3, 'person', plural: 'users')
|
|
227
|
-
# # => 3 users
|
|
279
|
+
# # => "3 users"
|
|
228
280
|
#
|
|
229
281
|
# pluralize(0, 'person')
|
|
230
|
-
# # => 0 people
|
|
282
|
+
# # => "0 people"
|
|
231
283
|
#
|
|
232
284
|
# pluralize(2, 'Person', locale: :de)
|
|
233
|
-
# # => 2 Personen
|
|
285
|
+
# # => "2 Personen"
|
|
234
286
|
def pluralize(count, singular, plural_arg = nil, plural: plural_arg, locale: I18n.locale)
|
|
235
287
|
word = if count == 1 || count.to_s.match?(/^1(\.0+)?$/)
|
|
236
288
|
singular
|
|
@@ -246,21 +298,21 @@ module ActionView
|
|
|
246
298
|
# (which is 80 by default).
|
|
247
299
|
#
|
|
248
300
|
# word_wrap('Once upon a time')
|
|
249
|
-
# # => Once upon a time
|
|
301
|
+
# # => "Once upon a time"
|
|
250
302
|
#
|
|
251
303
|
# word_wrap('Once upon a time, in a kingdom called Far Far Away, a king fell ill, and finding a successor to the throne turned out to be more trouble than anyone could have imagined...')
|
|
252
|
-
# # => Once upon a time, in a kingdom called Far Far Away, a king fell ill, and finding\na successor to the throne turned out to be more trouble than anyone could have\nimagined...
|
|
304
|
+
# # => "Once upon a time, in a kingdom called Far Far Away, a king fell ill, and finding\na successor to the throne turned out to be more trouble than anyone could have\nimagined..."
|
|
253
305
|
#
|
|
254
306
|
# word_wrap('Once upon a time', line_width: 8)
|
|
255
|
-
# # => Once\nupon a\ntime
|
|
307
|
+
# # => "Once\nupon a\ntime"
|
|
256
308
|
#
|
|
257
309
|
# word_wrap('Once upon a time', line_width: 1)
|
|
258
|
-
# # => Once\nupon\na\ntime
|
|
310
|
+
# # => "Once\nupon\na\ntime"
|
|
259
311
|
#
|
|
260
|
-
#
|
|
312
|
+
# You can also specify a custom +break_sequence+ ("\n" by default):
|
|
261
313
|
#
|
|
262
314
|
# word_wrap('Once upon a time', line_width: 1, break_sequence: "\r\n")
|
|
263
|
-
# # => Once\r\nupon\r\na\r\ntime
|
|
315
|
+
# # => "Once\r\nupon\r\na\r\ntime"
|
|
264
316
|
def word_wrap(text, line_width: 80, break_sequence: "\n")
|
|
265
317
|
text.split("\n").collect! do |line|
|
|
266
318
|
line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1#{break_sequence}").rstrip : line
|
|
@@ -318,7 +370,7 @@ module ActionView
|
|
|
318
370
|
end
|
|
319
371
|
end
|
|
320
372
|
|
|
321
|
-
# Creates a Cycle object whose
|
|
373
|
+
# Creates a Cycle object whose +to_s+ method cycles through elements of an
|
|
322
374
|
# array every time it is called. This can be used for example, to alternate
|
|
323
375
|
# classes for table rows. You can use named cycles to allow nesting in loops.
|
|
324
376
|
# Passing a Hash as the last parameter with a <tt>:name</tt> key will create a
|
|
@@ -327,8 +379,8 @@ module ActionView
|
|
|
327
379
|
# and passing the name of the cycle. The current cycle string can be obtained
|
|
328
380
|
# anytime using the current_cycle method.
|
|
329
381
|
#
|
|
330
|
-
#
|
|
331
|
-
# @items = [1,2,3,4]
|
|
382
|
+
# <%# Alternate CSS classes for even and odd numbers... %>
|
|
383
|
+
# <% @items = [1,2,3,4] %>
|
|
332
384
|
# <table>
|
|
333
385
|
# <% @items.each do |item| %>
|
|
334
386
|
# <tr class="<%= cycle("odd", "even") -%>">
|
|
@@ -338,10 +390,12 @@ module ActionView
|
|
|
338
390
|
# </table>
|
|
339
391
|
#
|
|
340
392
|
#
|
|
341
|
-
#
|
|
342
|
-
# @items =
|
|
343
|
-
#
|
|
344
|
-
#
|
|
393
|
+
# <%# Cycle CSS classes for rows, and text colors for values within each row %>
|
|
394
|
+
# <% @items = [
|
|
395
|
+
# { first: "Robert", middle: "Daniel", last: "James" },
|
|
396
|
+
# { first: "Emily", middle: "Shannon", maiden: "Pike", last: "Hicks" },
|
|
397
|
+
# { first: "June", middle: "Dae", last: "Jones" },
|
|
398
|
+
# ] %>
|
|
345
399
|
# <% @items.each do |item| %>
|
|
346
400
|
# <tr class="<%= cycle("odd", "even", name: "row_class") -%>">
|
|
347
401
|
# <td>
|
|
@@ -372,8 +426,8 @@ module ActionView
|
|
|
372
426
|
# for complex table highlighting or any other design need which requires
|
|
373
427
|
# the current cycle string in more than one place.
|
|
374
428
|
#
|
|
375
|
-
#
|
|
376
|
-
# @items = [1,2,3,4]
|
|
429
|
+
# <%# Alternate background colors %>
|
|
430
|
+
# <% @items = [1,2,3,4] %>
|
|
377
431
|
# <% @items.each do |item| %>
|
|
378
432
|
# <div style="background-color:<%= cycle("red","white","blue") %>">
|
|
379
433
|
# <span style="background-color:<%= current_cycle %>"><%= item %></span>
|
|
@@ -387,8 +441,8 @@ module ActionView
|
|
|
387
441
|
# Resets a cycle so that it starts from the first element the next time
|
|
388
442
|
# it is called. Pass in +name+ to reset a named cycle.
|
|
389
443
|
#
|
|
390
|
-
#
|
|
391
|
-
# @items = [[1,2,3,4], [5,6,3], [3,4,5,6,7,4]]
|
|
444
|
+
# <%# Alternate CSS classes for even and odd numbers... %>
|
|
445
|
+
# <% @items = [[1,2,3,4], [5,6,3], [3,4,5,6,7,4]] %>
|
|
392
446
|
# <table>
|
|
393
447
|
# <% @items.each do |item| %>
|
|
394
448
|
# <tr class="<%= cycle("even", "odd") -%>">
|
data/lib/action_view/layouts.rb
CHANGED
|
@@ -150,7 +150,7 @@ module ActionView
|
|
|
150
150
|
# The template will be looked always in <tt>app/views/layouts/</tt> folder. But you can point
|
|
151
151
|
# <tt>layouts</tt> folder direct also. <tt>layout "layouts/demo"</tt> is the same as <tt>layout "demo"</tt>.
|
|
152
152
|
#
|
|
153
|
-
# Setting the layout to +nil+ forces it to be looked up in the filesystem and
|
|
153
|
+
# Setting the layout to +nil+ forces it to be looked up in the filesystem and falls back to the parent behavior if none exists.
|
|
154
154
|
# Setting it to +nil+ is useful to re-enable template lookup overriding a previous configuration set in the parent:
|
|
155
155
|
#
|
|
156
156
|
# class ApplicationController < ActionController::Base
|
|
@@ -162,7 +162,7 @@ module ActionView
|
|
|
162
162
|
# end
|
|
163
163
|
#
|
|
164
164
|
# class CommentsController < ApplicationController
|
|
165
|
-
# # Will search for "comments" layout and
|
|
165
|
+
# # Will search for "comments" layout and fall back to "application" layout
|
|
166
166
|
# layout nil
|
|
167
167
|
# end
|
|
168
168
|
#
|
data/lib/action_view/template.rb
CHANGED
|
@@ -182,7 +182,7 @@ module ActionView
|
|
|
182
182
|
# the same as <tt>Encoding.default_external</tt>.
|
|
183
183
|
#
|
|
184
184
|
# The user can also specify the encoding via a comment on the first
|
|
185
|
-
# line of the template (
|
|
185
|
+
# line of the template (<tt># encoding: NAME-OF-ENCODING</tt>). This will work
|
|
186
186
|
# with any template engine, as we process out the encoding comment
|
|
187
187
|
# before passing the source on to the template engine, leaving a
|
|
188
188
|
# blank line in its stead.
|
|
@@ -280,7 +280,7 @@ module ActionView
|
|
|
280
280
|
# encoding of the code
|
|
281
281
|
original_source = source
|
|
282
282
|
source = +<<-end_src
|
|
283
|
-
def #{method_name}(local_assigns, output_buffer)
|
|
283
|
+
def #{method_name}(local_assigns, output_buffer, &_)
|
|
284
284
|
@virtual_path = #{@virtual_path.inspect};#{locals_code};#{code}
|
|
285
285
|
end
|
|
286
286
|
end_src
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: actionview
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 7.0.
|
|
4
|
+
version: 7.0.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- David Heinemeier Hansson
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: activesupport
|
|
@@ -16,14 +15,14 @@ dependencies:
|
|
|
16
15
|
requirements:
|
|
17
16
|
- - '='
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 7.0.
|
|
18
|
+
version: 7.0.9
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
23
|
- - '='
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 7.0.
|
|
25
|
+
version: 7.0.9
|
|
27
26
|
- !ruby/object:Gem::Dependency
|
|
28
27
|
name: builder
|
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -92,28 +91,28 @@ dependencies:
|
|
|
92
91
|
requirements:
|
|
93
92
|
- - '='
|
|
94
93
|
- !ruby/object:Gem::Version
|
|
95
|
-
version: 7.0.
|
|
94
|
+
version: 7.0.9
|
|
96
95
|
type: :development
|
|
97
96
|
prerelease: false
|
|
98
97
|
version_requirements: !ruby/object:Gem::Requirement
|
|
99
98
|
requirements:
|
|
100
99
|
- - '='
|
|
101
100
|
- !ruby/object:Gem::Version
|
|
102
|
-
version: 7.0.
|
|
101
|
+
version: 7.0.9
|
|
103
102
|
- !ruby/object:Gem::Dependency
|
|
104
103
|
name: activemodel
|
|
105
104
|
requirement: !ruby/object:Gem::Requirement
|
|
106
105
|
requirements:
|
|
107
106
|
- - '='
|
|
108
107
|
- !ruby/object:Gem::Version
|
|
109
|
-
version: 7.0.
|
|
108
|
+
version: 7.0.9
|
|
110
109
|
type: :development
|
|
111
110
|
prerelease: false
|
|
112
111
|
version_requirements: !ruby/object:Gem::Requirement
|
|
113
112
|
requirements:
|
|
114
113
|
- - '='
|
|
115
114
|
- !ruby/object:Gem::Version
|
|
116
|
-
version: 7.0.
|
|
115
|
+
version: 7.0.9
|
|
117
116
|
description: Simple, battle-tested conventions and helpers for building web pages.
|
|
118
117
|
email: david@loudthinking.com
|
|
119
118
|
executables: []
|
|
@@ -246,12 +245,11 @@ licenses:
|
|
|
246
245
|
- MIT
|
|
247
246
|
metadata:
|
|
248
247
|
bug_tracker_uri: https://github.com/rails/rails/issues
|
|
249
|
-
changelog_uri: https://github.com/rails/rails/blob/v7.0.
|
|
250
|
-
documentation_uri: https://api.rubyonrails.org/v7.0.
|
|
248
|
+
changelog_uri: https://github.com/rails/rails/blob/v7.0.9/actionview/CHANGELOG.md
|
|
249
|
+
documentation_uri: https://api.rubyonrails.org/v7.0.9/
|
|
251
250
|
mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
|
|
252
|
-
source_code_uri: https://github.com/rails/rails/tree/v7.0.
|
|
251
|
+
source_code_uri: https://github.com/rails/rails/tree/v7.0.9/actionview
|
|
253
252
|
rubygems_mfa_required: 'true'
|
|
254
|
-
post_install_message:
|
|
255
253
|
rdoc_options: []
|
|
256
254
|
require_paths:
|
|
257
255
|
- lib
|
|
@@ -267,8 +265,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
267
265
|
version: '0'
|
|
268
266
|
requirements:
|
|
269
267
|
- none
|
|
270
|
-
rubygems_version: 3.
|
|
271
|
-
signing_key:
|
|
268
|
+
rubygems_version: 3.6.9
|
|
272
269
|
specification_version: 4
|
|
273
270
|
summary: Rendering framework putting the V in MVC (part of Rails).
|
|
274
271
|
test_files: []
|