actionview 7.0.10 → 7.1.0.beta1

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.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +235 -404
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +1 -1
  5. data/app/assets/javascripts/rails-ujs.esm.js +668 -0
  6. data/app/assets/javascripts/rails-ujs.js +606 -0
  7. data/lib/action_view/base.rb +28 -7
  8. data/lib/action_view/buffers.rb +106 -8
  9. data/lib/action_view/cache_expiry.rb +40 -43
  10. data/lib/action_view/context.rb +1 -1
  11. data/lib/action_view/deprecator.rb +7 -0
  12. data/lib/action_view/digestor.rb +1 -1
  13. data/lib/action_view/gem_version.rb +4 -4
  14. data/lib/action_view/helpers/active_model_helper.rb +1 -1
  15. data/lib/action_view/helpers/asset_tag_helper.rb +134 -50
  16. data/lib/action_view/helpers/asset_url_helper.rb +6 -5
  17. data/lib/action_view/helpers/atom_feed_helper.rb +5 -5
  18. data/lib/action_view/helpers/cache_helper.rb +3 -9
  19. data/lib/action_view/helpers/capture_helper.rb +24 -10
  20. data/lib/action_view/helpers/content_exfiltration_prevention_helper.rb +70 -0
  21. data/lib/action_view/helpers/controller_helper.rb +6 -0
  22. data/lib/action_view/helpers/csp_helper.rb +2 -2
  23. data/lib/action_view/helpers/csrf_helper.rb +2 -2
  24. data/lib/action_view/helpers/date_helper.rb +17 -19
  25. data/lib/action_view/helpers/debug_helper.rb +3 -3
  26. data/lib/action_view/helpers/form_helper.rb +46 -25
  27. data/lib/action_view/helpers/form_options_helper.rb +2 -1
  28. data/lib/action_view/helpers/form_tag_helper.rb +43 -9
  29. data/lib/action_view/helpers/javascript_helper.rb +1 -0
  30. data/lib/action_view/helpers/number_helper.rb +331 -36
  31. data/lib/action_view/helpers/output_safety_helper.rb +2 -2
  32. data/lib/action_view/helpers/rendering_helper.rb +1 -1
  33. data/lib/action_view/helpers/sanitize_helper.rb +40 -32
  34. data/lib/action_view/helpers/tag_helper.rb +5 -27
  35. data/lib/action_view/helpers/tags/base.rb +11 -52
  36. data/lib/action_view/helpers/tags/collection_check_boxes.rb +1 -0
  37. data/lib/action_view/helpers/tags/collection_radio_buttons.rb +1 -0
  38. data/lib/action_view/helpers/tags/collection_select.rb +3 -0
  39. data/lib/action_view/helpers/tags/date_field.rb +1 -1
  40. data/lib/action_view/helpers/tags/date_select.rb +2 -0
  41. data/lib/action_view/helpers/tags/datetime_field.rb +14 -6
  42. data/lib/action_view/helpers/tags/datetime_local_field.rb +11 -2
  43. data/lib/action_view/helpers/tags/grouped_collection_select.rb +3 -0
  44. data/lib/action_view/helpers/tags/month_field.rb +1 -1
  45. data/lib/action_view/helpers/tags/select.rb +3 -0
  46. data/lib/action_view/helpers/tags/select_renderer.rb +56 -0
  47. data/lib/action_view/helpers/tags/time_field.rb +1 -1
  48. data/lib/action_view/helpers/tags/time_zone_select.rb +3 -0
  49. data/lib/action_view/helpers/tags/week_field.rb +1 -1
  50. data/lib/action_view/helpers/tags/weekday_select.rb +3 -0
  51. data/lib/action_view/helpers/tags.rb +2 -0
  52. data/lib/action_view/helpers/text_helper.rb +100 -138
  53. data/lib/action_view/helpers/translation_helper.rb +3 -3
  54. data/lib/action_view/helpers/url_helper.rb +41 -14
  55. data/lib/action_view/helpers.rb +2 -0
  56. data/lib/action_view/layouts.rb +6 -4
  57. data/lib/action_view/log_subscriber.rb +49 -32
  58. data/lib/action_view/lookup_context.rb +29 -13
  59. data/lib/action_view/path_registry.rb +57 -0
  60. data/lib/action_view/path_set.rb +13 -14
  61. data/lib/action_view/railtie.rb +26 -3
  62. data/lib/action_view/record_identifier.rb +15 -8
  63. data/lib/action_view/renderer/abstract_renderer.rb +1 -1
  64. data/lib/action_view/renderer/collection_renderer.rb +9 -1
  65. data/lib/action_view/renderer/partial_renderer/collection_caching.rb +2 -1
  66. data/lib/action_view/renderer/partial_renderer.rb +2 -1
  67. data/lib/action_view/renderer/renderer.rb +2 -0
  68. data/lib/action_view/renderer/streaming_template_renderer.rb +3 -2
  69. data/lib/action_view/renderer/template_renderer.rb +3 -2
  70. data/lib/action_view/rendering.rb +22 -4
  71. data/lib/action_view/ripper_ast_parser.rb +6 -6
  72. data/lib/action_view/template/error.rb +14 -1
  73. data/lib/action_view/template/handlers/builder.rb +4 -4
  74. data/lib/action_view/template/handlers/erb/erubi.rb +23 -27
  75. data/lib/action_view/template/handlers/erb.rb +73 -1
  76. data/lib/action_view/template/handlers.rb +1 -1
  77. data/lib/action_view/template/html.rb +1 -1
  78. data/lib/action_view/template/raw_file.rb +1 -1
  79. data/lib/action_view/template/renderable.rb +1 -1
  80. data/lib/action_view/template/resolver.rb +10 -2
  81. data/lib/action_view/template/text.rb +1 -1
  82. data/lib/action_view/template/types.rb +25 -34
  83. data/lib/action_view/template.rb +180 -53
  84. data/lib/action_view/template_path.rb +2 -0
  85. data/lib/action_view/test_case.rb +8 -5
  86. data/lib/action_view/unbound_template.rb +15 -5
  87. data/lib/action_view/version.rb +1 -1
  88. data/lib/action_view/view_paths.rb +15 -24
  89. data/lib/action_view.rb +4 -1
  90. metadata +29 -26
@@ -8,8 +8,9 @@ require "action_view/helpers/tag_helper"
8
8
  require "action_view/helpers/output_safety_helper"
9
9
 
10
10
  module ActionView
11
- # = Action View Text Helpers
12
11
  module Helpers # :nodoc:
12
+ # = Action View Text \Helpers
13
+ #
13
14
  # The TextHelper module provides a set of methods for filtering, formatting
14
15
  # and transforming strings, which can reduce the amount of inline Ruby code in
15
16
  # your views. These helper methods extend Action View making them callable
@@ -40,25 +41,21 @@ module ActionView
40
41
  include OutputSafetyHelper
41
42
 
42
43
  # The preferred method of outputting text in your views is to use the
43
- # <tt><%= "text" %></tt> eRuby syntax. The regular +puts+ and +print+ methods
44
+ # <%= "text" %> eRuby syntax. The regular _puts_ and _print_ methods
44
45
  # 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., <tt><% %></tt>), you
46
- # can use the +concat+ method.
47
- #
48
- # <% concat "hello" %> is equivalent to <%= "hello" %>
46
+ # output text within a non-output code block (i.e., <% %>), you can use the concat method.
49
47
  #
50
48
  # <%
51
- # unless signed_in?
52
- # concat link_to("Sign In", action: :sign_in)
53
- # end
49
+ # concat "hello"
50
+ # # is the equivalent of <%= "hello" %>
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
54
58
  # %>
55
- #
56
- # is equivalent to
57
- #
58
- # <% unless signed_in? %>
59
- # <%= link_to "Sign In", action: :sign_in %>
60
- # <% end %>
61
- #
62
59
  def concat(string)
63
60
  output_buffer << string
64
61
  end
@@ -67,36 +64,17 @@ module ActionView
67
64
  output_buffer.respond_to?(:safe_concat) ? output_buffer.safe_concat(string) : concat(string)
68
65
  end
69
66
 
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.
77
- #
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.
67
+ # Truncates a given +text+ after a given <tt>:length</tt> if +text+ is longer than <tt>:length</tt>
68
+ # (defaults to 30). The last characters will be replaced with the <tt>:omission</tt> (defaults to "...")
69
+ # for a total length not exceeding <tt>:length</tt>.
82
70
  #
83
- # ==== Options
84
- #
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+.
71
+ # Pass a <tt>:separator</tt> to truncate +text+ at a natural break.
95
72
  #
96
- # [+:escape+]
97
- # Whether to escape the result. Defaults to true.
73
+ # Pass a block if you want to show extra content when the text is truncated.
98
74
  #
99
- # ==== Examples
75
+ # The result is marked as HTML-safe, but it is escaped by default, unless <tt>:escape</tt> is
76
+ # +false+. Care should be taken if +text+ contains HTML tags or entities, because truncation
77
+ # may produce invalid HTML (such as unbalanced or incomplete tags).
100
78
  #
101
79
  # truncate("Once upon a time in a world far far away")
102
80
  # # => "Once upon a time in a world..."
@@ -117,7 +95,7 @@ module ActionView
117
95
  # # => "<p>Once upon a time in a wo..."
118
96
  #
119
97
  # truncate("Once upon a time in a world far far away") { link_to "Continue", "#" }
120
- # # => "Once upon a time in a world...<a href=\"#\">Continue</a>"
98
+ # # => "Once upon a time in a wo...<a href="#">Continue</a>"
121
99
  def truncate(text, options = {}, &block)
122
100
  if text
123
101
  length = options.fetch(:length, 30)
@@ -129,105 +107,79 @@ module ActionView
129
107
  end
130
108
  end
131
109
 
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
110
+ # Highlights one or more +phrases+ everywhere in +text+ by inserting it into
111
+ # a <tt>:highlighter</tt> string. The highlighter can be specialized by passing <tt>:highlighter</tt>
112
+ # as a single-quoted string with <tt>\1</tt> where the phrase is to be inserted (defaults to
113
+ # <tt><mark>\1</mark></tt>) or passing a block that receives each matched term. By default +text+
114
+ # is sanitized to prevent possible XSS attacks. If the input is trustworthy, passing false
115
+ # for <tt>:sanitize</tt> will turn sanitizing off.
152
116
  #
153
117
  # highlight('You searched for: rails', 'rails')
154
- # # => "You searched for: <mark>rails</mark>"
118
+ # # => You searched for: <mark>rails</mark>
155
119
  #
156
120
  # highlight('You searched for: rails', /for|rails/)
157
- # # => "You searched <mark>for</mark>: <mark>rails</mark>"
121
+ # # => You searched <mark>for</mark>: <mark>rails</mark>
158
122
  #
159
123
  # highlight('You searched for: ruby, rails, dhh', 'actionpack')
160
- # # => "You searched for: ruby, rails, dhh"
124
+ # # => You searched for: ruby, rails, dhh
161
125
  #
162
126
  # highlight('You searched for: rails', ['for', 'rails'], highlighter: '<em>\1</em>')
163
- # # => "You searched <em>for</em>: <em>rails</em>"
127
+ # # => You searched <em>for</em>: <em>rails</em>
164
128
  #
165
129
  # highlight('You searched for: rails', 'rails', highlighter: '<a href="search?q=\1">\1</a>')
166
- # # => "You searched for: <a href=\"search?q=rails\">rails</a>"
130
+ # # => You searched for: <a href="search?q=rails">rails</a>
167
131
  #
168
132
  # highlight('You searched for: rails', 'rails') { |match| link_to(search_path(q: match, match)) }
169
- # # => "You searched for: <a href=\"search?q=rails\">rails</a>"
133
+ # # => You searched for: <a href="search?q=rails">rails</a>
170
134
  #
171
135
  # highlight('<a href="javascript:alert(\'no!\')">ruby</a> on rails', 'rails', sanitize: false)
172
- # # => "<a href=\"javascript:alert('no!')\">ruby</a> on <mark>rails</mark>"
136
+ # # => <a href="javascript:alert('no!')">ruby</a> on <mark>rails</mark>
173
137
  def highlight(text, phrases, options = {}, &block)
174
138
  text = sanitize(text) if options.fetch(:sanitize, true)
175
139
 
176
140
  if text.blank? || phrases.blank?
177
141
  text || ""
178
142
  else
179
- match = Array(phrases).map do |p|
180
- Regexp === p ? p.to_s : Regexp.escape(p)
181
- end.join("|")
182
-
183
- if block_given?
184
- text.gsub(/(#{match})(?![^<]*?>)/i, &block)
185
- else
186
- highlighter = options.fetch(:highlighter, '<mark>\1</mark>')
187
- text.gsub(/(#{match})(?![^<]*?>)/i, highlighter)
188
- end
143
+ patterns = Array(phrases).map { |phrase| Regexp === phrase ? phrase : Regexp.escape(phrase) }
144
+ pattern = /(#{patterns.join("|")})/i
145
+ highlighter = options.fetch(:highlighter, '<mark>\1</mark>') unless block
146
+
147
+ text.scan(/<[^>]*|[^<]+/).each do |segment|
148
+ if !segment.start_with?("<")
149
+ if block
150
+ segment.gsub!(pattern, &block)
151
+ else
152
+ segment.gsub!(pattern, highlighter)
153
+ end
154
+ end
155
+ end.join
189
156
  end.html_safe
190
157
  end
191
158
 
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
159
+ # Extracts an excerpt from +text+ that matches the first instance of +phrase+.
160
+ # The <tt>:radius</tt> option expands the excerpt on each side of the first occurrence of +phrase+ by the number of characters
161
+ # defined in <tt>:radius</tt> (which defaults to 100). If the excerpt radius overflows the beginning or end of the +text+,
162
+ # then the <tt>:omission</tt> option (which defaults to "...") will be prepended/appended accordingly. Use the
163
+ # <tt>:separator</tt> option to choose the delimitation. The resulting string will be stripped in any case. If the +phrase+
164
+ # isn't found, +nil+ is returned.
213
165
  #
214
166
  # excerpt('This is an example', 'an', radius: 5)
215
- # # => "...s is an exam..."
167
+ # # => ...s is an exam...
216
168
  #
217
169
  # excerpt('This is an example', 'is', radius: 5)
218
- # # => "This is a..."
170
+ # # => This is a...
219
171
  #
220
172
  # excerpt('This is an example', 'is')
221
- # # => "This is an example"
173
+ # # => This is an example
222
174
  #
223
175
  # excerpt('This next thing is an example', 'ex', radius: 2)
224
- # # => "...next..."
176
+ # # => ...next...
225
177
  #
226
178
  # excerpt('This is also an example', 'an', radius: 8, omission: '<chop> ')
227
- # # => "<chop> is also an example"
179
+ # # => <chop> is also an example
228
180
  #
229
181
  # excerpt('This is a very beautiful morning', 'very', separator: ' ', radius: 1)
230
- # # => "...a very beautiful..."
182
+ # # => ...a very beautiful...
231
183
  def excerpt(text, phrase, options = {})
232
184
  return unless text && phrase
233
185
 
@@ -263,26 +215,26 @@ module ActionView
263
215
  # Attempts to pluralize the +singular+ word unless +count+ is 1. If
264
216
  # +plural+ is supplied, it will use that when count is > 1, otherwise
265
217
  # it will use the Inflector to determine the plural form for the given locale,
266
- # which defaults to +I18n.locale+.
218
+ # which defaults to I18n.locale
267
219
  #
268
220
  # The word will be pluralized using rules defined for the locale
269
221
  # (you must define your own inflection rules for languages other than English).
270
222
  # See ActiveSupport::Inflector.pluralize
271
223
  #
272
224
  # pluralize(1, 'person')
273
- # # => "1 person"
225
+ # # => 1 person
274
226
  #
275
227
  # pluralize(2, 'person')
276
- # # => "2 people"
228
+ # # => 2 people
277
229
  #
278
230
  # pluralize(3, 'person', plural: 'users')
279
- # # => "3 users"
231
+ # # => 3 users
280
232
  #
281
233
  # pluralize(0, 'person')
282
- # # => "0 people"
234
+ # # => 0 people
283
235
  #
284
236
  # pluralize(2, 'Person', locale: :de)
285
- # # => "2 Personen"
237
+ # # => 2 Personen
286
238
  def pluralize(count, singular, plural_arg = nil, plural: plural_arg, locale: I18n.locale)
287
239
  word = if count == 1 || count.to_s.match?(/^1(\.0+)?$/)
288
240
  singular
@@ -298,25 +250,33 @@ module ActionView
298
250
  # (which is 80 by default).
299
251
  #
300
252
  # word_wrap('Once upon a time')
301
- # # => "Once upon a time"
253
+ # # => Once upon a time
302
254
  #
303
255
  # 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...')
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..."
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...
305
257
  #
306
258
  # word_wrap('Once upon a time', line_width: 8)
307
- # # => "Once\nupon a\ntime"
259
+ # # => Once\nupon a\ntime
308
260
  #
309
261
  # word_wrap('Once upon a time', line_width: 1)
310
- # # => "Once\nupon\na\ntime"
262
+ # # => Once\nupon\na\ntime
311
263
  #
312
- # You can also specify a custom +break_sequence+ ("\n" by default):
264
+ # You can also specify a custom +break_sequence+ ("\n" by default)
313
265
  #
314
266
  # word_wrap('Once upon a time', line_width: 1, break_sequence: "\r\n")
315
- # # => "Once\r\nupon\r\na\r\ntime"
267
+ # # => Once\r\nupon\r\na\r\ntime
316
268
  def word_wrap(text, line_width: 80, break_sequence: "\n")
317
- text.split("\n").collect! do |line|
318
- line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1#{break_sequence}").rstrip : line
319
- end * break_sequence
269
+ # Match up to `line_width` characters, followed by one of
270
+ # (1) non-newline whitespace plus an optional newline
271
+ # (2) the end of the string, ignoring any trailing newlines
272
+ # (3) a newline
273
+ #
274
+ # -OR-
275
+ #
276
+ # Match an empty line
277
+ pattern = /(.{1,#{line_width}})(?:[^\S\n]+\n?|\n*\Z|\n)|\n/
278
+
279
+ text.gsub(pattern, "\\1#{break_sequence}").chomp!(break_sequence)
320
280
  end
321
281
 
322
282
  # Returns +text+ transformed into HTML using simple formatting rules.
@@ -331,6 +291,7 @@ module ActionView
331
291
  #
332
292
  # ==== Options
333
293
  # * <tt>:sanitize</tt> - If +false+, does not sanitize +text+.
294
+ # * <tt>:sanitize_options</tt> - Any extra options you want appended to the sanitize.
334
295
  # * <tt>:wrapper_tag</tt> - String representing the wrapper tag, defaults to <tt>"p"</tt>
335
296
  #
336
297
  # ==== Examples
@@ -355,10 +316,13 @@ module ActionView
355
316
  #
356
317
  # simple_format("<blink>Blinkable!</blink> It's true.", {}, sanitize: false)
357
318
  # # => "<p><blink>Blinkable!</blink> It's true.</p>"
319
+ #
320
+ # simple_format("<a target=\"_blank\" href=\"http://example.com\">Continue</a>", {}, { sanitize_options: { attributes: %w[target href] } })
321
+ # # => "<p><a target=\"_blank\" href=\"http://example.com\">Continue</a></p>"
358
322
  def simple_format(text, html_options = {}, options = {})
359
- wrapper_tag = options.fetch(:wrapper_tag, :p)
323
+ wrapper_tag = options[:wrapper_tag] || "p"
360
324
 
361
- text = sanitize(text) if options.fetch(:sanitize, true)
325
+ text = sanitize(text, options.fetch(:sanitize_options, {})) if options.fetch(:sanitize, true)
362
326
  paragraphs = split_paragraphs(text)
363
327
 
364
328
  if paragraphs.empty?
@@ -370,7 +334,7 @@ module ActionView
370
334
  end
371
335
  end
372
336
 
373
- # Creates a Cycle object whose +to_s+ method cycles through elements of an
337
+ # Creates a Cycle object whose _to_s_ method cycles through elements of an
374
338
  # array every time it is called. This can be used for example, to alternate
375
339
  # classes for table rows. You can use named cycles to allow nesting in loops.
376
340
  # Passing a Hash as the last parameter with a <tt>:name</tt> key will create a
@@ -379,8 +343,8 @@ module ActionView
379
343
  # and passing the name of the cycle. The current cycle string can be obtained
380
344
  # anytime using the current_cycle method.
381
345
  #
382
- # <%# Alternate CSS classes for even and odd numbers... %>
383
- # <% @items = [1,2,3,4] %>
346
+ # # Alternate CSS classes for even and odd numbers...
347
+ # @items = [1,2,3,4]
384
348
  # <table>
385
349
  # <% @items.each do |item| %>
386
350
  # <tr class="<%= cycle("odd", "even") -%>">
@@ -390,12 +354,10 @@ module ActionView
390
354
  # </table>
391
355
  #
392
356
  #
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
- # ] %>
357
+ # # Cycle CSS classes for rows, and text colors for values within each row
358
+ # @items = x = [{first: 'Robert', middle: 'Daniel', last: 'James'},
359
+ # {first: 'Emily', middle: 'Shannon', maiden: 'Pike', last: 'Hicks'},
360
+ # {first: 'June', middle: 'Dae', last: 'Jones'}]
399
361
  # <% @items.each do |item| %>
400
362
  # <tr class="<%= cycle("odd", "even", name: "row_class") -%>">
401
363
  # <td>
@@ -426,8 +388,8 @@ module ActionView
426
388
  # for complex table highlighting or any other design need which requires
427
389
  # the current cycle string in more than one place.
428
390
  #
429
- # <%# Alternate background colors %>
430
- # <% @items = [1,2,3,4] %>
391
+ # # Alternate background colors
392
+ # @items = [1,2,3,4]
431
393
  # <% @items.each do |item| %>
432
394
  # <div style="background-color:<%= cycle("red","white","blue") %>">
433
395
  # <span style="background-color:<%= current_cycle %>"><%= item %></span>
@@ -441,8 +403,8 @@ module ActionView
441
403
  # Resets a cycle so that it starts from the first element the next time
442
404
  # it is called. Pass in +name+ to reset a named cycle.
443
405
  #
444
- # <%# Alternate CSS classes for even and odd numbers... %>
445
- # <% @items = [[1,2,3,4], [5,6,3], [3,4,5,6,7,4]] %>
406
+ # # Alternate CSS classes for even and odd numbers...
407
+ # @items = [[1,2,3,4], [5,6,3], [3,4,5,6,7,4]]
446
408
  # <table>
447
409
  # <% @items.each do |item| %>
448
410
  # <tr class="<%= cycle("even", "odd") -%>">
@@ -4,14 +4,14 @@ require "action_view/helpers/tag_helper"
4
4
  require "active_support/html_safe_translation"
5
5
 
6
6
  module ActionView
7
- # = Action View Translation Helpers
8
7
  module Helpers # :nodoc:
8
+ # = Action View Translation \Helpers
9
9
  module TranslationHelper
10
10
  extend ActiveSupport::Concern
11
11
 
12
12
  include TagHelper
13
13
 
14
- # Specify whether an error should be raised for missing translations
14
+ # Specify whether an error should be raised for missing translations.
15
15
  singleton_class.attr_accessor :raise_on_missing_translations
16
16
 
17
17
  included do
@@ -93,7 +93,7 @@ module ActionView
93
93
  break translated unless translated == MISSING_TRANSLATION
94
94
 
95
95
  if alternatives.present? && !alternatives.first.is_a?(Symbol)
96
- break alternatives.first && I18n.translate(**options, default: alternatives)
96
+ break alternatives.first && I18n.translate(nil, **options, default: alternatives)
97
97
  end
98
98
 
99
99
  first_key ||= key
@@ -3,11 +3,13 @@
3
3
  require "active_support/core_ext/array/access"
4
4
  require "active_support/core_ext/hash/keys"
5
5
  require "active_support/core_ext/string/output_safety"
6
+ require "action_view/helpers/content_exfiltration_prevention_helper"
6
7
  require "action_view/helpers/tag_helper"
7
8
 
8
9
  module ActionView
9
- # = Action View URL Helpers
10
10
  module Helpers # :nodoc:
11
+ # = Action View URL \Helpers
12
+ #
11
13
  # Provides a set of methods for making links and getting URLs that
12
14
  # depend on the routing subsystem (see ActionDispatch::Routing).
13
15
  # This allows you to use the same format for links in views
@@ -22,6 +24,7 @@ module ActionView
22
24
  extend ActiveSupport::Concern
23
25
 
24
26
  include TagHelper
27
+ include ContentExfiltrationPreventionHelper
25
28
 
26
29
  module ClassMethods
27
30
  def _url_for_modules
@@ -93,7 +96,7 @@ module ActionView
93
96
  # ==== Examples
94
97
  #
95
98
  # Because it relies on +url_for+, +link_to+ supports both older-style controller/action/id arguments
96
- # and newer RESTful routes. Current Rails style favors RESTful routes whenever possible, so base
99
+ # and newer RESTful routes. Current \Rails style favors RESTful routes whenever possible, so base
97
100
  # your application on resources and use
98
101
  #
99
102
  # link_to "Profile", profile_path(@profile)
@@ -170,9 +173,31 @@ module ActionView
170
173
  # link_to "External link", "http://www.rubyonrails.org/", target: "_blank", rel: "nofollow"
171
174
  # # => <a href="http://www.rubyonrails.org/" target="_blank" rel="nofollow">External link</a>
172
175
  #
173
- # ==== Deprecated: Rails UJS Attributes
176
+ # ==== Turbo
174
177
  #
175
- # Prior to Rails 7, Rails shipped with a JavaScript library called <tt>@rails/ujs</tt> on by default. Following Rails 7,
178
+ # Rails 7 ships with Turbo enabled by default. Turbo provides the following +:data+ options:
179
+ #
180
+ # * <tt>turbo_method: symbol of HTTP verb</tt> - Performs a Turbo link visit
181
+ # with the given HTTP verb. Forms are recommended when performing non-+GET+ requests.
182
+ # Only use <tt>data-turbo-method</tt> where a form is not possible.
183
+ #
184
+ # * <tt>turbo_confirm: "question?"</tt> - Adds a confirmation dialog to the link with the
185
+ # given value.
186
+ #
187
+ # {Consult the Turbo Handbook for more information on the options
188
+ # above.}[https://turbo.hotwired.dev/handbook/drive#performing-visits-with-a-different-method]
189
+ #
190
+ # ===== \Examples
191
+ #
192
+ # link_to "Delete profile", @profile, data: { turbo_method: :delete }
193
+ # # => <a href="/profiles/1" data-turbo-method="delete">Delete profile</a>
194
+ #
195
+ # link_to "Visit Other Site", "https://rubyonrails.org/", data: { turbo_confirm: "Are you sure?" }
196
+ # # => <a href="https://rubyonrails.org/" data-turbo-confirm="Are you sure?">Visit Other Site</a>
197
+ #
198
+ # ==== Deprecated: \Rails UJS Attributes
199
+ #
200
+ # Prior to \Rails 7, \Rails shipped with a JavaScript library called <tt>@rails/ujs</tt> on by default. Following \Rails 7,
176
201
  # this library is no longer on by default. This library integrated with the following options:
177
202
  #
178
203
  # * <tt>method: symbol of HTTP verb</tt> - This modifier will dynamically
@@ -198,7 +223,7 @@ module ActionView
198
223
  # * <tt>:disable_with</tt> - Value of this parameter will be used as the
199
224
  # name for a disabled version of the link.
200
225
  #
201
- # ===== Rails UJS Examples
226
+ # ===== \Rails UJS Examples
202
227
  #
203
228
  # link_to "Remove Profile", profile_path(@profile), method: :delete
204
229
  # # => <a href="/profiles/1" rel="nofollow" data-method="delete">Remove Profile</a>
@@ -221,9 +246,6 @@ module ActionView
221
246
  # Generates a form containing a single button that submits to the URL created
222
247
  # by the set of +options+. This is the safest method to ensure links that
223
248
  # cause changes to your data are not triggered by search bots or accelerators.
224
- # If the HTML button does not work with your layout, you can also consider
225
- # using the +link_to+ method with the <tt>:method</tt> modifier as described in
226
- # the +link_to+ documentation.
227
249
  #
228
250
  # You can control the form and button behavior with +html_options+. Most
229
251
  # values in +html_options+ are passed through to the button element. For
@@ -237,6 +259,10 @@ module ActionView
237
259
  # The form submits a POST request by default. You can specify a different
238
260
  # HTTP verb via the +:method+ option within +html_options+.
239
261
  #
262
+ # If the HTML button generated from +button_to+ does not work with your layout, you can
263
+ # consider using the +link_to+ method with the +data-turbo-method+
264
+ # attribute as described in the +link_to+ documentation.
265
+ #
240
266
  # ==== Options
241
267
  # The +options+ hash accepts the same options as +url_for+. To generate a
242
268
  # <tt><form></tt> element without an <tt>[action]</tt> attribute, pass
@@ -302,9 +328,9 @@ module ActionView
302
328
  # # <input name="authenticity_token" type="hidden" value="10f2163b45388899ad4d5ae948988266befcb6c3d1b2451cf657a0c293d605a6" autocomplete="off"/>
303
329
  # # </form>"
304
330
  #
305
- # ==== Deprecated: Rails UJS Attributes
331
+ # ==== Deprecated: \Rails UJS Attributes
306
332
  #
307
- # Prior to Rails 7, Rails shipped with a JavaScript library called <tt>@rails/ujs</tt> on by default. Following Rails 7,
333
+ # Prior to \Rails 7, \Rails shipped with a JavaScript library called <tt>@rails/ujs</tt> on by default. Following \Rails 7,
308
334
  # this library is no longer on by default. This library integrated with the following options:
309
335
  #
310
336
  # * <tt>:remote</tt> - If set to true, will allow <tt>@rails/ujs</tt> to control the
@@ -320,7 +346,7 @@ module ActionView
320
346
  # used as the value for a disabled version of the submit
321
347
  # button when the form is submitted.
322
348
  #
323
- # ===== Rails UJS Examples
349
+ # ===== \Rails UJS Examples
324
350
  #
325
351
  # <%= button_to "Create", { action: "create" }, remote: true, form: { "data-type" => "json" } %>
326
352
  # # => "<form method="post" action="/images/create" class="button_to" data-remote="true" data-type="json">
@@ -380,7 +406,8 @@ module ActionView
380
406
  autocomplete: "off")
381
407
  end
382
408
  end
383
- content_tag("form", inner_tags, form_options)
409
+ html = content_tag("form", inner_tags, form_options)
410
+ prevent_content_exfiltration(html)
384
411
  end
385
412
 
386
413
  # Creates a link tag of the given +name+ using a URL created by the set of
@@ -495,7 +522,7 @@ module ActionView
495
522
  # * <tt>:reply_to</tt> - Preset the +Reply-To+ field of the email.
496
523
  #
497
524
  # ==== Obfuscation
498
- # Prior to Rails 4.0, +mail_to+ provided options for encoding the address
525
+ # Prior to \Rails 4.0, +mail_to+ provided options for encoding the address
499
526
  # in order to hinder email harvesters. To take advantage of these options,
500
527
  # install the +actionview-encoded_mail_to+ gem.
501
528
  #
@@ -595,7 +622,7 @@ module ActionView
595
622
  # We ignore any extra parameters in the request_uri if the
596
623
  # submitted URL doesn't have any either. This lets the function
597
624
  # work with things like ?order=asc
598
- # the behaviour can be disabled with check_parameters: true
625
+ # the behavior can be disabled with check_parameters: true
599
626
  request_uri = url_string.index("?") || check_parameters ? request.fullpath : request.path
600
627
  request_uri = URI::DEFAULT_PARSER.unescape(request_uri).force_encoding(Encoding::BINARY)
601
628
 
@@ -12,6 +12,7 @@ require "action_view/helpers/asset_tag_helper"
12
12
  require "action_view/helpers/asset_url_helper"
13
13
  require "action_view/helpers/atom_feed_helper"
14
14
  require "action_view/helpers/cache_helper"
15
+ require "action_view/helpers/content_exfiltration_prevention_helper"
15
16
  require "action_view/helpers/controller_helper"
16
17
  require "action_view/helpers/csp_helper"
17
18
  require "action_view/helpers/csrf_helper"
@@ -45,6 +46,7 @@ module ActionView # :nodoc:
45
46
  include AtomFeedHelper
46
47
  include CacheHelper
47
48
  include CaptureHelper
49
+ include ContentExfiltrationPreventionHelper
48
50
  include ControllerHelper
49
51
  include CspHelper
50
52
  include CsrfHelper
@@ -4,6 +4,8 @@ require "action_view/rendering"
4
4
  require "active_support/core_ext/module/redefine_method"
5
5
 
6
6
  module ActionView
7
+ # = Action View \Layouts
8
+ #
7
9
  # Layouts reverse the common pattern of including shared headers and footers in many templates to isolate changes in
8
10
  # repeated setups. The inclusion pattern has pages that look like this:
9
11
  #
@@ -150,7 +152,7 @@ module ActionView
150
152
  # The template will be looked always in <tt>app/views/layouts/</tt> folder. But you can point
151
153
  # <tt>layouts</tt> folder direct also. <tt>layout "layouts/demo"</tt> is the same as <tt>layout "demo"</tt>.
152
154
  #
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.
155
+ # Setting the layout to +nil+ forces it to be looked up in the filesystem and fallbacks to the parent behavior if none exists.
154
156
  # Setting it to +nil+ is useful to re-enable template lookup overriding a previous configuration set in the parent:
155
157
  #
156
158
  # class ApplicationController < ActionController::Base
@@ -162,7 +164,7 @@ module ActionView
162
164
  # end
163
165
  #
164
166
  # class CommentsController < ApplicationController
165
- # # Will search for "comments" layout and fall back to "application" layout
167
+ # # Will search for "comments" layout and fallback "application" layout
166
168
  # layout nil
167
169
  # end
168
170
  #
@@ -210,9 +212,9 @@ module ActionView
210
212
  class_attribute :_layout_conditions, instance_accessor: false, default: {}
211
213
 
212
214
  _write_layout_method
213
- end
214
215
 
215
- delegate :_layout_conditions, to: :class
216
+ delegate :_layout_conditions, to: :class
217
+ end
216
218
 
217
219
  module ClassMethods
218
220
  def inherited(klass) # :nodoc: