actionview 7.1.2 → 7.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -0
- data/lib/action_view/gem_version.rb +1 -1
- data/lib/action_view/helpers/form_helper.rb +8 -4
- data/lib/action_view/helpers/form_tag_helper.rb +6 -6
- data/lib/action_view/helpers/number_helper.rb +35 -329
- data/lib/action_view/helpers/sanitize_helper.rb +25 -14
- data/lib/action_view/helpers/text_helper.rb +124 -68
- data/lib/action_view/layouts.rb +2 -2
- data/lib/action_view/template.rb +1 -1
- data/lib/action_view/test_case.rb +2 -2
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 922d7936de34cfa626cd9cec0f32208e1fe48086f75be08b08e78a28911fa1fb
|
4
|
+
data.tar.gz: d24e4bcf03ad6c510536f5b423664f3877ac07873cfccdbff1cd087c081e7455
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b99bd07d8343f338a2a20bb0739efd3bf2ce7e05efba079f7971905772e282675b995ecc4cc56d731c7cc75ab9b1ea252c64d1d6041b303d46d05f2bbb1427a
|
7
|
+
data.tar.gz: 5f9702c425eab497ce8d6c2123ad8a8b57a17c1708286bf1b3b9ed8ad447dec4bf0c22c0e1011f6a88de4d4305efc5484b16532f5af8752d2e7f3e9d78876edc
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,26 @@
|
|
1
|
+
## Rails 7.1.3 (January 16, 2024) ##
|
2
|
+
|
3
|
+
* Better handle SyntaxError in Action View.
|
4
|
+
|
5
|
+
*Mario Caropreso*
|
6
|
+
|
7
|
+
* Fix `word_wrap` with empty string.
|
8
|
+
|
9
|
+
*Jonathan Hefner*
|
10
|
+
|
11
|
+
* Rename `ActionView::TestCase::Behavior::Content` to `ActionView::TestCase::Behavior::RenderedViewContent`.
|
12
|
+
|
13
|
+
Make `RenderedViewContent` inherit from `String`. Make private API with `:nodoc:`.
|
14
|
+
|
15
|
+
*Sean Doyle*
|
16
|
+
|
17
|
+
* Fix detection of required strict locals.
|
18
|
+
|
19
|
+
Further fix `render @collection` compatibility with strict locals
|
20
|
+
|
21
|
+
*Jean Boussier*
|
22
|
+
|
23
|
+
|
1
24
|
## Rails 7.1.2 (November 10, 2023) ##
|
2
25
|
|
3
26
|
* Fix the `number_to_human_size` view helper to correctly work with negative numbers.
|
@@ -1006,8 +1006,8 @@ module ActionView
|
|
1006
1006
|
# <% end %>
|
1007
1007
|
#
|
1008
1008
|
# When a collection is used you might want to know the index of each
|
1009
|
-
# object
|
1010
|
-
#
|
1009
|
+
# object in the array. For this purpose, the <tt>index</tt> method is
|
1010
|
+
# available in the FormBuilder object.
|
1011
1011
|
#
|
1012
1012
|
# <%= form_for @person do |person_form| %>
|
1013
1013
|
# ...
|
@@ -1118,6 +1118,8 @@ module ActionView
|
|
1118
1118
|
# post:
|
1119
1119
|
# cost: "Total cost"
|
1120
1120
|
#
|
1121
|
+
# <code></code>
|
1122
|
+
#
|
1121
1123
|
# label(:post, :cost)
|
1122
1124
|
# # => <label for="post_cost">Total cost</label>
|
1123
1125
|
#
|
@@ -1779,12 +1781,12 @@ module ActionView
|
|
1779
1781
|
#
|
1780
1782
|
# <%= form_for @post do |f| %>
|
1781
1783
|
# <%= f.text_field :title, name: f.field_name(:title, :subtitle) %>
|
1782
|
-
# <%# => <input type="text" name="post[title][subtitle]">
|
1784
|
+
# <%# => <input type="text" name="post[title][subtitle]"> %>
|
1783
1785
|
# <% end %>
|
1784
1786
|
#
|
1785
1787
|
# <%= form_for @post do |f| %>
|
1786
1788
|
# <%= f.text_field :tag, name: f.field_name(:tag, multiple: true) %>
|
1787
|
-
# <%# => <input type="text" name="post[tag][]">
|
1789
|
+
# <%# => <input type="text" name="post[tag][]"> %>
|
1788
1790
|
# <% end %>
|
1789
1791
|
#
|
1790
1792
|
def field_name(method, *methods, multiple: false, index: @options[:index])
|
@@ -2358,6 +2360,8 @@ module ActionView
|
|
2358
2360
|
# post:
|
2359
2361
|
# cost: "Total cost"
|
2360
2362
|
#
|
2363
|
+
# <code></code>
|
2364
|
+
#
|
2361
2365
|
# label(:cost)
|
2362
2366
|
# # => <label for="post_cost">Total cost</label>
|
2363
2367
|
#
|
@@ -91,11 +91,11 @@ module ActionView
|
|
91
91
|
# attribute name.
|
92
92
|
#
|
93
93
|
# <%= label_tag :post, :title %>
|
94
|
-
# <%=
|
94
|
+
# <%= text_field :post, :title, aria: { describedby: field_id(:post, :title, :error) } %>
|
95
95
|
# <%= tag.span("is blank", id: field_id(:post, :title, :error) %>
|
96
96
|
#
|
97
97
|
# In the example above, the <tt><input type="text"></tt> element built by
|
98
|
-
# the call to <tt>
|
98
|
+
# the call to <tt>text_field</tt> declares an
|
99
99
|
# <tt>aria-describedby</tt> attribute referencing the <tt><span></tt>
|
100
100
|
# element, sharing a common <tt>id</tt> root (<tt>post_title</tt>, in this
|
101
101
|
# case).
|
@@ -123,11 +123,11 @@ module ActionView
|
|
123
123
|
# Return the value generated by the <tt>FormBuilder</tt> for the given
|
124
124
|
# attribute name.
|
125
125
|
#
|
126
|
-
# <%=
|
127
|
-
# <%# => <input type="text" name="post[title][subtitle]">
|
126
|
+
# <%= text_field :post, :title, name: field_name(:post, :title, :subtitle) %>
|
127
|
+
# <%# => <input type="text" name="post[title][subtitle]"> %>
|
128
128
|
#
|
129
|
-
# <%=
|
130
|
-
# <%# => <input type="text" name="post[tag][]">
|
129
|
+
# <%= text_field :post, :tag, name: field_name(:post, :tag, multiple: true) %>
|
130
|
+
# <%# => <input type="text" name="post[tag][]"> %>
|
131
131
|
#
|
132
132
|
def field_name(object_name, method_name, *method_names, multiple: false, index: nil)
|
133
133
|
names = method_names.map! { |name| "[#{name}]" }.join
|
@@ -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)
|
@@ -15,11 +15,11 @@ module ActionView
|
|
15
15
|
|
16
16
|
# Sanitizes HTML input, stripping all but known-safe tags and attributes.
|
17
17
|
#
|
18
|
-
# It also strips href/src attributes with unsafe protocols like
|
18
|
+
# It also strips +href+ / +src+ attributes with unsafe protocols like +javascript:+, while
|
19
19
|
# also protecting against attempts to use Unicode, ASCII, and hex character references to work
|
20
20
|
# around these protocol filters.
|
21
21
|
#
|
22
|
-
# The default sanitizer is Rails::HTML5::SafeListSanitizer
|
22
|
+
# The default sanitizer is +Rails::HTML5::SafeListSanitizer+. See {Rails HTML
|
23
23
|
# Sanitizers}[https://github.com/rails/rails-html-sanitizer] for more information.
|
24
24
|
#
|
25
25
|
# Custom sanitization rules can also be provided.
|
@@ -29,24 +29,29 @@ module ActionView
|
|
29
29
|
#
|
30
30
|
# ==== Options
|
31
31
|
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
32
|
+
# [+:tags+]
|
33
|
+
# An array of allowed tags.
|
34
|
+
#
|
35
|
+
# [+:attributes+]
|
36
|
+
# An array of allowed attributes.
|
37
|
+
#
|
38
|
+
# [+:scrubber+]
|
39
|
+
# A {Rails::HTML scrubber}[https://github.com/rails/rails-html-sanitizer]
|
35
40
|
# or {Loofah::Scrubber}[https://github.com/flavorjones/loofah] object that
|
36
41
|
# defines custom sanitization rules. A custom scrubber takes precedence over
|
37
42
|
# custom tags and attributes.
|
38
43
|
#
|
39
44
|
# ==== Examples
|
40
45
|
#
|
41
|
-
# Normal use
|
46
|
+
# ===== Normal use
|
42
47
|
#
|
43
48
|
# <%= sanitize @comment.body %>
|
44
49
|
#
|
45
|
-
# Providing custom lists of permitted tags and attributes
|
50
|
+
# ===== Providing custom lists of permitted tags and attributes
|
46
51
|
#
|
47
52
|
# <%= sanitize @comment.body, tags: %w(strong em a), attributes: %w(href) %>
|
48
53
|
#
|
49
|
-
# Providing a custom Rails::HTML scrubber
|
54
|
+
# ===== Providing a custom +Rails::HTML+ scrubber
|
50
55
|
#
|
51
56
|
# class CommentScrubber < Rails::HTML::PermitScrubber
|
52
57
|
# def initialize
|
@@ -60,21 +65,27 @@ module ActionView
|
|
60
65
|
# end
|
61
66
|
# end
|
62
67
|
#
|
68
|
+
# <code></code>
|
69
|
+
#
|
63
70
|
# <%= sanitize @comment.body, scrubber: CommentScrubber.new %>
|
64
71
|
#
|
65
72
|
# See {Rails HTML Sanitizer}[https://github.com/rails/rails-html-sanitizer] for
|
66
|
-
# documentation about Rails::HTML scrubbers.
|
73
|
+
# documentation about +Rails::HTML+ scrubbers.
|
67
74
|
#
|
68
|
-
# Providing a custom Loofah::Scrubber
|
75
|
+
# ===== Providing a custom +Loofah::Scrubber+
|
69
76
|
#
|
70
77
|
# scrubber = Loofah::Scrubber.new do |node|
|
71
78
|
# node.remove if node.name == 'script'
|
72
79
|
# end
|
73
80
|
#
|
81
|
+
# <code></code>
|
82
|
+
#
|
74
83
|
# <%= sanitize @comment.body, scrubber: scrubber %>
|
75
84
|
#
|
76
85
|
# See {Loofah's documentation}[https://github.com/flavorjones/loofah] for more
|
77
|
-
# information about defining custom Loofah::Scrubber objects.
|
86
|
+
# information about defining custom +Loofah::Scrubber+ objects.
|
87
|
+
#
|
88
|
+
# ==== Global Configuration
|
78
89
|
#
|
79
90
|
# To set the default allowed tags or attributes across your application:
|
80
91
|
#
|
@@ -95,13 +106,13 @@ module ActionView
|
|
95
106
|
# # In config/application.rb
|
96
107
|
# config.action_view.sanitizer_vendor = Rails::HTML5::Sanitizer
|
97
108
|
#
|
98
|
-
# NOTE: Rails::HTML5::Sanitizer is not supported on JRuby, so on JRuby platforms \Rails will
|
99
|
-
# fall back to
|
109
|
+
# NOTE: +Rails::HTML5::Sanitizer+ is not supported on JRuby, so on JRuby platforms \Rails will
|
110
|
+
# fall back to using +Rails::HTML4::Sanitizer+.
|
100
111
|
def sanitize(html, options = {})
|
101
112
|
self.class.safe_list_sanitizer.sanitize(html, options)&.html_safe
|
102
113
|
end
|
103
114
|
|
104
|
-
# Sanitizes a block of CSS code. Used by
|
115
|
+
# Sanitizes a block of CSS code. Used by #sanitize when it comes across a style attribute.
|
105
116
|
def sanitize_css(style)
|
106
117
|
self.class.safe_list_sanitizer.sanitize_css(style)
|
107
118
|
end
|
@@ -41,21 +41,25 @@ module ActionView
|
|
41
41
|
include OutputSafetyHelper
|
42
42
|
|
43
43
|
# The preferred method of outputting text in your views is to use the
|
44
|
-
#
|
44
|
+
# <tt><%= "text" %></tt> eRuby syntax. The regular +puts+ and +print+ methods
|
45
45
|
# do not operate as expected in an eRuby code block. If you absolutely must
|
46
|
-
# output text within a non-output code block (i.e.,
|
46
|
+
# output text within a non-output code block (i.e., <tt><% %></tt>), you
|
47
|
+
# can use the +concat+ method.
|
48
|
+
#
|
49
|
+
# <% concat "hello" %> is equivalent to <%= "hello" %>
|
47
50
|
#
|
48
51
|
# <%
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
# if logged_in
|
53
|
-
# concat "Logged in!"
|
54
|
-
# else
|
55
|
-
# concat link_to('login', action: :login)
|
56
|
-
# end
|
57
|
-
# # will either display "Logged in!" or a login link
|
52
|
+
# unless signed_in?
|
53
|
+
# concat link_to("Sign In", action: :sign_in)
|
54
|
+
# end
|
58
55
|
# %>
|
56
|
+
#
|
57
|
+
# is equivalent to
|
58
|
+
#
|
59
|
+
# <% unless signed_in? %>
|
60
|
+
# <%= link_to "Sign In", action: :sign_in %>
|
61
|
+
# <% end %>
|
62
|
+
#
|
59
63
|
def concat(string)
|
60
64
|
output_buffer << string
|
61
65
|
end
|
@@ -64,17 +68,36 @@ module ActionView
|
|
64
68
|
output_buffer.respond_to?(:safe_concat) ? output_buffer.safe_concat(string) : concat(string)
|
65
69
|
end
|
66
70
|
|
67
|
-
# Truncates
|
68
|
-
#
|
69
|
-
#
|
71
|
+
# Truncates +text+ if it is longer than a specified +:length+. If +text+
|
72
|
+
# is truncated, an omission marker will be appended to the result for a
|
73
|
+
# total length not exceeding +:length+.
|
74
|
+
#
|
75
|
+
# You can also pass a block to render and append extra content after the
|
76
|
+
# omission marker when +text+ is truncated. However, this content _can_
|
77
|
+
# cause the total length to exceed +:length+ characters.
|
78
|
+
#
|
79
|
+
# The result will be escaped unless <tt>escape: false</tt> is specified.
|
80
|
+
# In any case, the result will be marked HTML-safe. Care should be taken
|
81
|
+
# if +text+ might contain HTML tags or entities, because truncation could
|
82
|
+
# produce invalid HTML, such as unbalanced or incomplete tags.
|
70
83
|
#
|
71
|
-
#
|
84
|
+
# ==== Options
|
85
|
+
#
|
86
|
+
# [+:length+]
|
87
|
+
# The maximum number of characters that should be returned, excluding
|
88
|
+
# any extra content from the block. Defaults to 30.
|
72
89
|
#
|
73
|
-
#
|
90
|
+
# [+:omission+]
|
91
|
+
# The string to append after truncating. Defaults to <tt>"..."</tt>.
|
74
92
|
#
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
93
|
+
# [+:separator+]
|
94
|
+
# A string or regexp used to find a breaking point at which to truncate.
|
95
|
+
# By default, truncation can occur at any character in +text+.
|
96
|
+
#
|
97
|
+
# [+:escape+]
|
98
|
+
# Whether to escape the result. Defaults to true.
|
99
|
+
#
|
100
|
+
# ==== Examples
|
78
101
|
#
|
79
102
|
# truncate("Once upon a time in a world far far away")
|
80
103
|
# # => "Once upon a time in a world..."
|
@@ -95,7 +118,7 @@ module ActionView
|
|
95
118
|
# # => "<p>Once upon a time in a wo..."
|
96
119
|
#
|
97
120
|
# truncate("Once upon a time in a world far far away") { link_to "Continue", "#" }
|
98
|
-
# # => "Once upon a time in a
|
121
|
+
# # => "Once upon a time in a world...<a href=\"#\">Continue</a>"
|
99
122
|
def truncate(text, options = {}, &block)
|
100
123
|
if text
|
101
124
|
length = options.fetch(:length, 30)
|
@@ -107,33 +130,47 @@ module ActionView
|
|
107
130
|
end
|
108
131
|
end
|
109
132
|
|
110
|
-
# Highlights
|
111
|
-
#
|
112
|
-
#
|
113
|
-
#
|
114
|
-
#
|
115
|
-
#
|
133
|
+
# Highlights occurrences of +phrases+ in +text+ by formatting them with a
|
134
|
+
# highlighter string. +phrases+ can be one or more strings or regular
|
135
|
+
# expressions. The result will be marked HTML safe. By default, +text+ is
|
136
|
+
# sanitized before highlighting to prevent possible XSS attacks.
|
137
|
+
#
|
138
|
+
# If a block is specified, it will be used instead of the highlighter
|
139
|
+
# string. Each occurrence of a phrase will be passed to the block, and its
|
140
|
+
# return value will be inserted into the final result.
|
141
|
+
#
|
142
|
+
# ==== Options
|
143
|
+
#
|
144
|
+
# [+:highlighter+]
|
145
|
+
# The highlighter string. Uses <tt>\1</tt> as the placeholder for a
|
146
|
+
# phrase, similar to +String#sub+. Defaults to <tt>"<mark>\1</mark>"</tt>.
|
147
|
+
# This option is ignored if a block is specified.
|
148
|
+
#
|
149
|
+
# [+:sanitize+]
|
150
|
+
# Whether to sanitize +text+ before highlighting. Defaults to true.
|
151
|
+
#
|
152
|
+
# ==== Examples
|
116
153
|
#
|
117
154
|
# highlight('You searched for: rails', 'rails')
|
118
|
-
# # => You searched for: <mark>rails</mark>
|
155
|
+
# # => "You searched for: <mark>rails</mark>"
|
119
156
|
#
|
120
157
|
# highlight('You searched for: rails', /for|rails/)
|
121
|
-
# # => You searched <mark>for</mark>: <mark>rails</mark>
|
158
|
+
# # => "You searched <mark>for</mark>: <mark>rails</mark>"
|
122
159
|
#
|
123
160
|
# highlight('You searched for: ruby, rails, dhh', 'actionpack')
|
124
|
-
# # => You searched for: ruby, rails, dhh
|
161
|
+
# # => "You searched for: ruby, rails, dhh"
|
125
162
|
#
|
126
163
|
# highlight('You searched for: rails', ['for', 'rails'], highlighter: '<em>\1</em>')
|
127
|
-
# # => You searched <em>for</em>: <em>rails</em>
|
164
|
+
# # => "You searched <em>for</em>: <em>rails</em>"
|
128
165
|
#
|
129
166
|
# highlight('You searched for: rails', 'rails', highlighter: '<a href="search?q=\1">\1</a>')
|
130
|
-
# # => You searched for: <a href
|
167
|
+
# # => "You searched for: <a href=\"search?q=rails\">rails</a>"
|
131
168
|
#
|
132
169
|
# highlight('You searched for: rails', 'rails') { |match| link_to(search_path(q: match, match)) }
|
133
|
-
# # => You searched for: <a href
|
170
|
+
# # => "You searched for: <a href=\"search?q=rails\">rails</a>"
|
134
171
|
#
|
135
172
|
# highlight('<a href="javascript:alert(\'no!\')">ruby</a> on rails', 'rails', sanitize: false)
|
136
|
-
# # => <a href
|
173
|
+
# # => "<a href=\"javascript:alert('no!')\">ruby</a> on <mark>rails</mark>"
|
137
174
|
def highlight(text, phrases, options = {}, &block)
|
138
175
|
text = sanitize(text) if options.fetch(:sanitize, true)
|
139
176
|
|
@@ -156,30 +193,45 @@ module ActionView
|
|
156
193
|
end.html_safe
|
157
194
|
end
|
158
195
|
|
159
|
-
# Extracts
|
160
|
-
#
|
161
|
-
#
|
162
|
-
#
|
163
|
-
#
|
164
|
-
#
|
196
|
+
# Extracts the first occurrence of +phrase+ plus surrounding text from
|
197
|
+
# +text+. An omission marker is prepended / appended if the start / end of
|
198
|
+
# the result does not coincide with the start / end of +text+. The result
|
199
|
+
# is always stripped in any case. Returns +nil+ if +phrase+ isn't found.
|
200
|
+
#
|
201
|
+
# ==== Options
|
202
|
+
#
|
203
|
+
# [+:radius+]
|
204
|
+
# The number of characters (or tokens — see +:separator+ option) around
|
205
|
+
# +phrase+ to include in the result. Defaults to 100.
|
206
|
+
#
|
207
|
+
# [+:omission+]
|
208
|
+
# The marker to prepend / append when the start / end of the excerpt
|
209
|
+
# does not coincide with the start / end of +text+. Defaults to
|
210
|
+
# <tt>"..."</tt>.
|
211
|
+
#
|
212
|
+
# [+:separator+]
|
213
|
+
# The separator between tokens to count for +:radius+. Defaults to
|
214
|
+
# <tt>""</tt>, which treats each character as a token.
|
215
|
+
#
|
216
|
+
# ==== Examples
|
165
217
|
#
|
166
218
|
# excerpt('This is an example', 'an', radius: 5)
|
167
|
-
# # => ...s is an exam...
|
219
|
+
# # => "...s is an exam..."
|
168
220
|
#
|
169
221
|
# excerpt('This is an example', 'is', radius: 5)
|
170
|
-
# # => This is a...
|
222
|
+
# # => "This is a..."
|
171
223
|
#
|
172
224
|
# excerpt('This is an example', 'is')
|
173
|
-
# # => This is an example
|
225
|
+
# # => "This is an example"
|
174
226
|
#
|
175
227
|
# excerpt('This next thing is an example', 'ex', radius: 2)
|
176
|
-
# # => ...next...
|
228
|
+
# # => "...next..."
|
177
229
|
#
|
178
230
|
# excerpt('This is also an example', 'an', radius: 8, omission: '<chop> ')
|
179
|
-
# # => <chop> is also an example
|
231
|
+
# # => "<chop> is also an example"
|
180
232
|
#
|
181
233
|
# excerpt('This is a very beautiful morning', 'very', separator: ' ', radius: 1)
|
182
|
-
# # => ...a very beautiful...
|
234
|
+
# # => "...a very beautiful..."
|
183
235
|
def excerpt(text, phrase, options = {})
|
184
236
|
return unless text && phrase
|
185
237
|
|
@@ -215,26 +267,26 @@ module ActionView
|
|
215
267
|
# Attempts to pluralize the +singular+ word unless +count+ is 1. If
|
216
268
|
# +plural+ is supplied, it will use that when count is > 1, otherwise
|
217
269
|
# it will use the Inflector to determine the plural form for the given locale,
|
218
|
-
# which defaults to I18n.locale
|
270
|
+
# which defaults to +I18n.locale+.
|
219
271
|
#
|
220
272
|
# The word will be pluralized using rules defined for the locale
|
221
273
|
# (you must define your own inflection rules for languages other than English).
|
222
274
|
# See ActiveSupport::Inflector.pluralize
|
223
275
|
#
|
224
276
|
# pluralize(1, 'person')
|
225
|
-
# # => 1 person
|
277
|
+
# # => "1 person"
|
226
278
|
#
|
227
279
|
# pluralize(2, 'person')
|
228
|
-
# # => 2 people
|
280
|
+
# # => "2 people"
|
229
281
|
#
|
230
282
|
# pluralize(3, 'person', plural: 'users')
|
231
|
-
# # => 3 users
|
283
|
+
# # => "3 users"
|
232
284
|
#
|
233
285
|
# pluralize(0, 'person')
|
234
|
-
# # => 0 people
|
286
|
+
# # => "0 people"
|
235
287
|
#
|
236
288
|
# pluralize(2, 'Person', locale: :de)
|
237
|
-
# # => 2 Personen
|
289
|
+
# # => "2 Personen"
|
238
290
|
def pluralize(count, singular, plural_arg = nil, plural: plural_arg, locale: I18n.locale)
|
239
291
|
word = if count == 1 || count.to_s.match?(/^1(\.0+)?$/)
|
240
292
|
singular
|
@@ -250,22 +302,24 @@ module ActionView
|
|
250
302
|
# (which is 80 by default).
|
251
303
|
#
|
252
304
|
# word_wrap('Once upon a time')
|
253
|
-
# # => Once upon a time
|
305
|
+
# # => "Once upon a time"
|
254
306
|
#
|
255
307
|
# 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...')
|
256
|
-
# # => 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...
|
308
|
+
# # => "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..."
|
257
309
|
#
|
258
310
|
# word_wrap('Once upon a time', line_width: 8)
|
259
|
-
# # => Once\nupon a\ntime
|
311
|
+
# # => "Once\nupon a\ntime"
|
260
312
|
#
|
261
313
|
# word_wrap('Once upon a time', line_width: 1)
|
262
|
-
# # => Once\nupon\na\ntime
|
314
|
+
# # => "Once\nupon\na\ntime"
|
263
315
|
#
|
264
|
-
#
|
316
|
+
# You can also specify a custom +break_sequence+ ("\n" by default):
|
265
317
|
#
|
266
318
|
# word_wrap('Once upon a time', line_width: 1, break_sequence: "\r\n")
|
267
|
-
# # => Once\r\nupon\r\na\r\ntime
|
319
|
+
# # => "Once\r\nupon\r\na\r\ntime"
|
268
320
|
def word_wrap(text, line_width: 80, break_sequence: "\n")
|
321
|
+
return +"" if text.empty?
|
322
|
+
|
269
323
|
# Match up to `line_width` characters, followed by one of
|
270
324
|
# (1) non-newline whitespace plus an optional newline
|
271
325
|
# (2) the end of the string, ignoring any trailing newlines
|
@@ -334,7 +388,7 @@ module ActionView
|
|
334
388
|
end
|
335
389
|
end
|
336
390
|
|
337
|
-
# Creates a Cycle object whose
|
391
|
+
# Creates a Cycle object whose +to_s+ method cycles through elements of an
|
338
392
|
# array every time it is called. This can be used for example, to alternate
|
339
393
|
# classes for table rows. You can use named cycles to allow nesting in loops.
|
340
394
|
# Passing a Hash as the last parameter with a <tt>:name</tt> key will create a
|
@@ -343,8 +397,8 @@ module ActionView
|
|
343
397
|
# and passing the name of the cycle. The current cycle string can be obtained
|
344
398
|
# anytime using the current_cycle method.
|
345
399
|
#
|
346
|
-
#
|
347
|
-
# @items = [1,2,3,4]
|
400
|
+
# <%# Alternate CSS classes for even and odd numbers... %>
|
401
|
+
# <% @items = [1,2,3,4] %>
|
348
402
|
# <table>
|
349
403
|
# <% @items.each do |item| %>
|
350
404
|
# <tr class="<%= cycle("odd", "even") -%>">
|
@@ -354,10 +408,12 @@ module ActionView
|
|
354
408
|
# </table>
|
355
409
|
#
|
356
410
|
#
|
357
|
-
#
|
358
|
-
# @items =
|
359
|
-
#
|
360
|
-
#
|
411
|
+
# <%# Cycle CSS classes for rows, and text colors for values within each row %>
|
412
|
+
# <% @items = [
|
413
|
+
# { first: "Robert", middle: "Daniel", last: "James" },
|
414
|
+
# { first: "Emily", middle: "Shannon", maiden: "Pike", last: "Hicks" },
|
415
|
+
# { first: "June", middle: "Dae", last: "Jones" },
|
416
|
+
# ] %>
|
361
417
|
# <% @items.each do |item| %>
|
362
418
|
# <tr class="<%= cycle("odd", "even", name: "row_class") -%>">
|
363
419
|
# <td>
|
@@ -388,8 +444,8 @@ module ActionView
|
|
388
444
|
# for complex table highlighting or any other design need which requires
|
389
445
|
# the current cycle string in more than one place.
|
390
446
|
#
|
391
|
-
#
|
392
|
-
# @items = [1,2,3,4]
|
447
|
+
# <%# Alternate background colors %>
|
448
|
+
# <% @items = [1,2,3,4] %>
|
393
449
|
# <% @items.each do |item| %>
|
394
450
|
# <div style="background-color:<%= cycle("red","white","blue") %>">
|
395
451
|
# <span style="background-color:<%= current_cycle %>"><%= item %></span>
|
@@ -403,8 +459,8 @@ module ActionView
|
|
403
459
|
# Resets a cycle so that it starts from the first element the next time
|
404
460
|
# it is called. Pass in +name+ to reset a named cycle.
|
405
461
|
#
|
406
|
-
#
|
407
|
-
# @items = [[1,2,3,4], [5,6,3], [3,4,5,6,7,4]]
|
462
|
+
# <%# Alternate CSS classes for even and odd numbers... %>
|
463
|
+
# <% @items = [[1,2,3,4], [5,6,3], [3,4,5,6,7,4]] %>
|
408
464
|
# <table>
|
409
465
|
# <% @items.each do |item| %>
|
410
466
|
# <tr class="<%= cycle("even", "odd") -%>">
|
data/lib/action_view/layouts.rb
CHANGED
@@ -152,7 +152,7 @@ module ActionView
|
|
152
152
|
# The template will be looked always in <tt>app/views/layouts/</tt> folder. But you can point
|
153
153
|
# <tt>layouts</tt> folder direct also. <tt>layout "layouts/demo"</tt> is the same as <tt>layout "demo"</tt>.
|
154
154
|
#
|
155
|
-
# Setting the layout to +nil+ forces it to be looked up in the filesystem and
|
155
|
+
# Setting the layout to +nil+ forces it to be looked up in the filesystem and falls back to the parent behavior if none exists.
|
156
156
|
# Setting it to +nil+ is useful to re-enable template lookup overriding a previous configuration set in the parent:
|
157
157
|
#
|
158
158
|
# class ApplicationController < ActionController::Base
|
@@ -164,7 +164,7 @@ module ActionView
|
|
164
164
|
# end
|
165
165
|
#
|
166
166
|
# class CommentsController < ApplicationController
|
167
|
-
# # Will search for "comments" layout and
|
167
|
+
# # Will search for "comments" layout and fall back to "application" layout
|
168
168
|
# layout nil
|
169
169
|
# end
|
170
170
|
#
|
data/lib/action_view/template.rb
CHANGED
@@ -198,7 +198,7 @@ module ActionView
|
|
198
198
|
end
|
199
199
|
|
200
200
|
included do
|
201
|
-
class_attribute :content_class, instance_accessor: false, default:
|
201
|
+
class_attribute :content_class, instance_accessor: false, default: RenderedViewContent
|
202
202
|
|
203
203
|
setup :setup_with_controller
|
204
204
|
|
@@ -299,7 +299,7 @@ module ActionView
|
|
299
299
|
@controller._routes if @controller.respond_to?(:_routes)
|
300
300
|
end
|
301
301
|
|
302
|
-
class
|
302
|
+
class RenderedViewContent < String # :nodoc:
|
303
303
|
end
|
304
304
|
|
305
305
|
# Need to experiment if this priority is the best one: rendered => output_buffer
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actionview
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.1.
|
4
|
+
version: 7.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 7.1.
|
19
|
+
version: 7.1.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 7.1.
|
26
|
+
version: 7.1.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: builder
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,28 +86,28 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - '='
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 7.1.
|
89
|
+
version: 7.1.3
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - '='
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 7.1.
|
96
|
+
version: 7.1.3
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: activemodel
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - '='
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 7.1.
|
103
|
+
version: 7.1.3
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - '='
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 7.1.
|
110
|
+
version: 7.1.3
|
111
111
|
description: Simple, battle-tested conventions and helpers for building web pages.
|
112
112
|
email: david@loudthinking.com
|
113
113
|
executables: []
|
@@ -246,10 +246,10 @@ licenses:
|
|
246
246
|
- MIT
|
247
247
|
metadata:
|
248
248
|
bug_tracker_uri: https://github.com/rails/rails/issues
|
249
|
-
changelog_uri: https://github.com/rails/rails/blob/v7.1.
|
250
|
-
documentation_uri: https://api.rubyonrails.org/v7.1.
|
249
|
+
changelog_uri: https://github.com/rails/rails/blob/v7.1.3/actionview/CHANGELOG.md
|
250
|
+
documentation_uri: https://api.rubyonrails.org/v7.1.3/
|
251
251
|
mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
|
252
|
-
source_code_uri: https://github.com/rails/rails/tree/v7.1.
|
252
|
+
source_code_uri: https://github.com/rails/rails/tree/v7.1.3/actionview
|
253
253
|
rubygems_mfa_required: 'true'
|
254
254
|
post_install_message:
|
255
255
|
rdoc_options: []
|