actionview 6.0.0.rc1 → 6.0.3.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionview might be problematic. Click here for more details.

Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +62 -0
  3. data/README.rdoc +1 -1
  4. data/lib/action_view.rb +1 -0
  5. data/lib/action_view/base.rb +1 -1
  6. data/lib/action_view/cache_expiry.rb +13 -9
  7. data/lib/action_view/digestor.rb +5 -4
  8. data/lib/action_view/flows.rb +0 -1
  9. data/lib/action_view/gem_version.rb +1 -1
  10. data/lib/action_view/helpers/active_model_helper.rb +0 -1
  11. data/lib/action_view/helpers/asset_tag_helper.rb +1 -1
  12. data/lib/action_view/helpers/cache_helper.rb +1 -2
  13. data/lib/action_view/helpers/date_helper.rb +1 -2
  14. data/lib/action_view/helpers/form_helper.rb +2 -2
  15. data/lib/action_view/helpers/form_options_helper.rb +4 -3
  16. data/lib/action_view/helpers/form_tag_helper.rb +4 -1
  17. data/lib/action_view/helpers/javascript_helper.rb +4 -2
  18. data/lib/action_view/helpers/number_helper.rb +3 -2
  19. data/lib/action_view/helpers/sanitize_helper.rb +10 -16
  20. data/lib/action_view/helpers/tag_helper.rb +3 -3
  21. data/lib/action_view/helpers/tags/base.rb +0 -1
  22. data/lib/action_view/helpers/tags/check_box.rb +0 -1
  23. data/lib/action_view/helpers/tags/collection_check_boxes.rb +0 -1
  24. data/lib/action_view/helpers/tags/collection_helpers.rb +0 -1
  25. data/lib/action_view/helpers/tags/collection_radio_buttons.rb +0 -1
  26. data/lib/action_view/helpers/tags/color_field.rb +0 -1
  27. data/lib/action_view/helpers/tags/date_field.rb +0 -1
  28. data/lib/action_view/helpers/tags/date_select.rb +0 -1
  29. data/lib/action_view/helpers/tags/datetime_field.rb +0 -1
  30. data/lib/action_view/helpers/tags/datetime_local_field.rb +0 -1
  31. data/lib/action_view/helpers/tags/label.rb +0 -1
  32. data/lib/action_view/helpers/tags/month_field.rb +0 -1
  33. data/lib/action_view/helpers/tags/radio_button.rb +0 -1
  34. data/lib/action_view/helpers/tags/select.rb +0 -1
  35. data/lib/action_view/helpers/tags/text_field.rb +0 -1
  36. data/lib/action_view/helpers/tags/time_field.rb +0 -1
  37. data/lib/action_view/helpers/tags/week_field.rb +0 -1
  38. data/lib/action_view/helpers/text_helper.rb +0 -1
  39. data/lib/action_view/helpers/translation_helper.rb +7 -8
  40. data/lib/action_view/helpers/url_helper.rb +1 -1
  41. data/lib/action_view/layouts.rb +0 -3
  42. data/lib/action_view/log_subscriber.rb +0 -1
  43. data/lib/action_view/lookup_context.rb +4 -3
  44. data/lib/action_view/path_set.rb +0 -1
  45. data/lib/action_view/record_identifier.rb +0 -1
  46. data/lib/action_view/renderer/abstract_renderer.rb +0 -1
  47. data/lib/action_view/renderer/partial_renderer.rb +0 -4
  48. data/lib/action_view/renderer/partial_renderer/collection_caching.rb +1 -1
  49. data/lib/action_view/renderer/streaming_template_renderer.rb +0 -2
  50. data/lib/action_view/renderer/template_renderer.rb +1 -2
  51. data/lib/action_view/rendering.rb +0 -1
  52. data/lib/action_view/template.rb +0 -1
  53. data/lib/action_view/template/error.rb +9 -14
  54. data/lib/action_view/template/handlers/erb.rb +0 -1
  55. data/lib/action_view/template/resolver.rb +1 -5
  56. data/lib/action_view/test_case.rb +2 -3
  57. data/lib/action_view/testing/resolvers.rb +25 -14
  58. data/lib/action_view/unbound_template.rb +1 -2
  59. data/lib/action_view/view_paths.rb +0 -1
  60. data/lib/assets/compiled/rails-ujs.js +7 -4
  61. metadata +18 -15
@@ -39,7 +39,6 @@ module ActionView
39
39
  end
40
40
 
41
41
  private
42
-
43
42
  def checked?(value)
44
43
  case value
45
44
  when TrueClass, FalseClass
@@ -22,7 +22,6 @@ module ActionView
22
22
  end
23
23
 
24
24
  private
25
-
26
25
  def render_component(builder)
27
26
  builder.check_box + builder.label
28
27
  end
@@ -37,7 +37,6 @@ module ActionView
37
37
  end
38
38
 
39
39
  private
40
-
41
40
  def instantiate_builder(builder_class, item, value, text, html_options)
42
41
  builder_class.new(@template_object, @object_name, @method_name, item,
43
42
  sanitize_attribute_name(value), text, value, html_options)
@@ -21,7 +21,6 @@ module ActionView
21
21
  end
22
22
 
23
23
  private
24
-
25
24
  def render_component(builder)
26
25
  builder.radio_button + builder.label
27
26
  end
@@ -12,7 +12,6 @@ module ActionView
12
12
  end
13
13
 
14
14
  private
15
-
16
15
  def validate_color_string(string)
17
16
  regex = /#[0-9a-fA-F]{6}/
18
17
  if regex.match?(string)
@@ -5,7 +5,6 @@ module ActionView
5
5
  module Tags # :nodoc:
6
6
  class DateField < DatetimeField # :nodoc:
7
7
  private
8
-
9
8
  def format_date(value)
10
9
  value.try(:strftime, "%Y-%m-%d")
11
10
  end
@@ -23,7 +23,6 @@ module ActionView
23
23
  end
24
24
 
25
25
  private
26
-
27
26
  def select_type
28
27
  self.class.select_type
29
28
  end
@@ -14,7 +14,6 @@ module ActionView
14
14
  end
15
15
 
16
16
  private
17
-
18
17
  def format_date(value)
19
18
  raise NotImplementedError
20
19
  end
@@ -11,7 +11,6 @@ module ActionView
11
11
  end
12
12
 
13
13
  private
14
-
15
14
  def format_date(value)
16
15
  value.try(:strftime, "%Y-%m-%dT%T")
17
16
  end
@@ -71,7 +71,6 @@ module ActionView
71
71
  end
72
72
 
73
73
  private
74
-
75
74
  def render_component(builder)
76
75
  builder.translation
77
76
  end
@@ -5,7 +5,6 @@ module ActionView
5
5
  module Tags # :nodoc:
6
6
  class MonthField < DatetimeField # :nodoc:
7
7
  private
8
-
9
8
  def format_date(value)
10
9
  value.try(:strftime, "%Y-%m")
11
10
  end
@@ -23,7 +23,6 @@ module ActionView
23
23
  end
24
24
 
25
25
  private
26
-
27
26
  def checked?(value)
28
27
  value.to_s == @tag_value.to_s
29
28
  end
@@ -29,7 +29,6 @@ module ActionView
29
29
  end
30
30
 
31
31
  private
32
-
33
32
  # Grouped choices look like this:
34
33
  #
35
34
  # [nil, []]
@@ -24,7 +24,6 @@ module ActionView
24
24
  end
25
25
 
26
26
  private
27
-
28
27
  def field_type
29
28
  self.class.field_type
30
29
  end
@@ -5,7 +5,6 @@ module ActionView
5
5
  module Tags # :nodoc:
6
6
  class TimeField < DatetimeField # :nodoc:
7
7
  private
8
-
9
8
  def format_date(value)
10
9
  value.try(:strftime, "%T.%L")
11
10
  end
@@ -5,7 +5,6 @@ module ActionView
5
5
  module Tags # :nodoc:
6
6
  class WeekField < DatetimeField # :nodoc:
7
7
  private
8
-
9
8
  def format_date(value)
10
9
  value.try(:strftime, "%Y-W%V")
11
10
  end
@@ -426,7 +426,6 @@ module ActionView
426
426
  end
427
427
 
428
428
  private
429
-
430
429
  def next_index
431
430
  step_index(1)
432
431
  end
@@ -57,10 +57,9 @@ module ActionView
57
57
  # that include HTML tags so that you know what kind of output to expect
58
58
  # when you call translate in a template and translators know which keys
59
59
  # they can provide HTML values for.
60
- def translate(key, options = {})
61
- options = options.dup
60
+ def translate(key, **options)
62
61
  if options.has_key?(:default)
63
- remaining_defaults = Array(options.delete(:default)).compact
62
+ remaining_defaults = Array.wrap(options.delete(:default)).compact
64
63
  options[:default] = remaining_defaults unless remaining_defaults.first.kind_of?(Symbol)
65
64
  end
66
65
 
@@ -82,18 +81,18 @@ module ActionView
82
81
  html_safe_options[name] = ERB::Util.html_escape(value.to_s)
83
82
  end
84
83
  end
85
- translation = I18n.translate(scope_key_by_partial(key), html_safe_options.merge(raise: i18n_raise))
84
+ translation = I18n.translate(scope_key_by_partial(key), **html_safe_options.merge(raise: i18n_raise))
86
85
  if translation.respond_to?(:map)
87
86
  translation.map { |element| element.respond_to?(:html_safe) ? element.html_safe : element }
88
87
  else
89
88
  translation.respond_to?(:html_safe) ? translation.html_safe : translation
90
89
  end
91
90
  else
92
- I18n.translate(scope_key_by_partial(key), options.merge(raise: i18n_raise))
91
+ I18n.translate(scope_key_by_partial(key), **options.merge(raise: i18n_raise))
93
92
  end
94
93
  rescue I18n::MissingTranslationData => e
95
94
  if remaining_defaults.present?
96
- translate remaining_defaults.shift, options.merge(default: remaining_defaults)
95
+ translate remaining_defaults.shift, **options.merge(default: remaining_defaults)
97
96
  else
98
97
  raise e if raise_error
99
98
 
@@ -116,8 +115,8 @@ module ActionView
116
115
  #
117
116
  # See https://www.rubydoc.info/github/svenfuchs/i18n/master/I18n/Backend/Base:localize
118
117
  # for more information.
119
- def localize(*args)
120
- I18n.localize(*args)
118
+ def localize(object, **options)
119
+ I18n.localize(object, **options)
121
120
  end
122
121
  alias :l :localize
123
122
 
@@ -253,7 +253,7 @@ module ActionView
253
253
  # # <input value="New" type="submit" />
254
254
  # # </form>"
255
255
  #
256
- # <%= button_to "New", new_articles_path %>
256
+ # <%= button_to "New", new_article_path %>
257
257
  # # => "<form method="post" action="/articles/new" class="button_to">
258
258
  # # <input value="New" type="submit" />
259
259
  # # </form>"
@@ -224,7 +224,6 @@ module ActionView
224
224
  # that if no layout conditions are used, this method is not used
225
225
  module LayoutConditions # :nodoc:
226
226
  private
227
-
228
227
  # Determines whether the current action has a layout definition by
229
228
  # checking the action name against the :only and :except conditions
230
229
  # set by the <tt>layout</tt> method.
@@ -334,7 +333,6 @@ module ActionView
334
333
  end
335
334
 
336
335
  private
337
-
338
336
  # If no layout is supplied, look for a template named the return
339
337
  # value of this method.
340
338
  #
@@ -372,7 +370,6 @@ module ActionView
372
370
  end
373
371
 
374
372
  private
375
-
376
373
  def _conditional_layout?
377
374
  true
378
375
  end
@@ -54,7 +54,6 @@ module ActionView
54
54
  end
55
55
 
56
56
  private
57
-
58
57
  EMPTY = ""
59
58
  def from_rails_root(string) # :doc:
60
59
  string = string.sub(rails_root, EMPTY)
@@ -61,6 +61,7 @@ module ActionView
61
61
 
62
62
  @details_keys = Concurrent::Map.new
63
63
  @digest_cache = Concurrent::Map.new
64
+ @view_context_mutex = Mutex.new
64
65
 
65
66
  def self.digest_cache(details)
66
67
  @digest_cache[details_cache_key(details)] ||= Concurrent::Map.new
@@ -89,7 +90,9 @@ module ActionView
89
90
  end
90
91
 
91
92
  def self.view_context_class(klass)
92
- @view_context_class ||= klass.with_empty_template_cache
93
+ @view_context_mutex.synchronize do
94
+ @view_context_class ||= klass.with_empty_template_cache
95
+ end
93
96
  end
94
97
  end
95
98
 
@@ -112,7 +115,6 @@ module ActionView
112
115
  end
113
116
 
114
117
  private
115
-
116
118
  def _set_detail(key, value) # :doc:
117
119
  @details = @details.dup if @digest_cache || @details_key
118
120
  @digest_cache = nil
@@ -171,7 +173,6 @@ module ActionView
171
173
  end
172
174
 
173
175
  private
174
-
175
176
  # Whenever setting view paths, makes a copy so that we can manipulate them in
176
177
  # instance objects as we wish.
177
178
  def build_view_paths(paths)
@@ -69,7 +69,6 @@ module ActionView #:nodoc:
69
69
  end
70
70
 
71
71
  private
72
-
73
72
  def _find_all(path, prefixes, args)
74
73
  prefixes = [prefixes] if String === prefixes
75
74
  prefixes.each do |prefix|
@@ -95,7 +95,6 @@ module ActionView
95
95
  end
96
96
 
97
97
  private
98
-
99
98
  # Returns a string representation of the key attribute(s) that is suitable for use in an HTML DOM id.
100
99
  # This can be overwritten to customize the default generated string representation if desired.
101
100
  # If you need to read back a key from a dom_id in order to query for the underlying database record,
@@ -75,7 +75,6 @@ module ActionView
75
75
  end
76
76
 
77
77
  private
78
-
79
78
  def extract_details(options) # :doc:
80
79
  @lookup_context.registered_details.each_with_object({}) do |key, details|
81
80
  value = options[key]
@@ -105,9 +105,6 @@ module ActionView
105
105
  #
106
106
  # <%= render(partial: "ad", collection: @advertisements) || "There's no ad to be displayed" %>
107
107
  #
108
- # NOTE: Due to backwards compatibility concerns, the collection can't be one of hashes. Normally you'd also
109
- # just keep domain objects, like Active Records, in there.
110
- #
111
108
  # == \Rendering shared partials
112
109
  #
113
110
  # Two controllers can share a set of partials and render them like this:
@@ -322,7 +319,6 @@ module ActionView
322
319
  end
323
320
 
324
321
  private
325
-
326
322
  def render_collection(view, template)
327
323
  identifier = (template && template.identifier) || @path
328
324
  instrument(:collection, identifier: identifier, count: @collection.size) do |payload|
@@ -12,7 +12,7 @@ module ActionView
12
12
 
13
13
  private
14
14
  def cache_collection_render(instrumentation_payload, view, template)
15
- return yield unless @options[:cached]
15
+ return yield unless @options[:cached] && view.controller.respond_to?(:perform_caching) && view.controller.perform_caching
16
16
 
17
17
  # Result is a hash with the key represents the
18
18
  # key used for cache lookup and the value is the item
@@ -27,7 +27,6 @@ module ActionView
27
27
  end
28
28
 
29
29
  private
30
-
31
30
  # This is the same logging logic as in ShowExceptions middleware.
32
31
  def log_error(exception)
33
32
  logger = ActionView::Base.logger
@@ -55,7 +54,6 @@ module ActionView
55
54
  end
56
55
 
57
56
  private
58
-
59
57
  def delayed_render(buffer, template, layout, view, locals)
60
58
  # Wrap the given buffer in the StreamingBuffer and pass it to the
61
59
  # underlying template handler. Now, every time something is concatenated
@@ -14,7 +14,6 @@ module ActionView
14
14
  end
15
15
 
16
16
  private
17
-
18
17
  # Determine the template to be rendered using the given options.
19
18
  def determine_template(options)
20
19
  keys = options.has_key?(:locals) ? options[:locals].keys : []
@@ -96,7 +95,7 @@ module ActionView
96
95
  end
97
96
  rescue ActionView::MissingTemplate
98
97
  all_details = @details.merge(formats: @lookup_context.default_formats)
99
- raise unless template_exists?(layout, nil, false, [], all_details)
98
+ raise unless template_exists?(layout, nil, false, [], **all_details)
100
99
  end
101
100
  when Proc
102
101
  resolve_layout(layout.call(@lookup_context, formats), keys, formats)
@@ -104,7 +104,6 @@ module ActionView
104
104
  end
105
105
 
106
106
  private
107
-
108
107
  # Find and render a template based on the options given.
109
108
  def _render_template(options)
110
109
  variant = options.delete(:variant)
@@ -264,7 +264,6 @@ module ActionView
264
264
  end
265
265
 
266
266
  private
267
-
268
267
  # Compile a template. This method ensures a template is compiled
269
268
  # just once and removes the source after it is compiled.
270
269
  def compile!(view)
@@ -81,19 +81,19 @@ module ActionView
81
81
  end
82
82
  end
83
83
 
84
- def source_extract(indentation = 0, output = :console)
85
- return unless num = line_number
84
+ def source_extract(indentation = 0)
85
+ return [] unless num = line_number
86
86
  num = num.to_i
87
87
 
88
- source_code = @template.source.split("\n")
88
+ source_code = @template.encode!.split("\n")
89
89
 
90
90
  start_on_line = [ num - SOURCE_CODE_RADIUS - 1, 0 ].max
91
91
  end_on_line = [ num + SOURCE_CODE_RADIUS - 1, source_code.length].min
92
92
 
93
93
  indent = end_on_line.to_s.size + indentation
94
- return unless source_code = source_code[start_on_line..end_on_line]
94
+ return [] unless source_code = source_code[start_on_line..end_on_line]
95
95
 
96
- formatted_code_for(source_code, start_on_line, indent, output)
96
+ formatted_code_for(source_code, start_on_line, indent)
97
97
  end
98
98
 
99
99
  def sub_template_of(template_path)
@@ -114,7 +114,6 @@ module ActionView
114
114
  end
115
115
 
116
116
  private
117
-
118
117
  def source_location
119
118
  if line_number
120
119
  "on line ##{line_number} of "
@@ -123,15 +122,11 @@ module ActionView
123
122
  end + file_name
124
123
  end
125
124
 
126
- def formatted_code_for(source_code, line_counter, indent, output)
127
- start_value = (output == :html) ? {} : []
128
- source_code.inject(start_value) do |result, line|
125
+ def formatted_code_for(source_code, line_counter, indent)
126
+ indent_template = "%#{indent}s: %s"
127
+ source_code.map do |line|
129
128
  line_counter += 1
130
- if output == :html
131
- result.update(line_counter.to_s => "%#{indent}s %s\n" % ["", line])
132
- else
133
- result << "%#{indent}s: %s" % [line_counter, line]
134
- end
129
+ indent_template % [line_counter, line]
135
130
  end
136
131
  end
137
132
  end
@@ -63,7 +63,6 @@ module ActionView
63
63
  end
64
64
 
65
65
  private
66
-
67
66
  def valid_encoding(string, encoding)
68
67
  # If a magic encoding comment was found, tag the
69
68
  # String with this encoding. This is for a case
@@ -93,7 +93,6 @@ module ActionView
93
93
  end
94
94
 
95
95
  private
96
-
97
96
  def canonical_no_templates(templates)
98
97
  templates.empty? ? NO_TEMPLATES : templates
99
98
  end
@@ -130,7 +129,6 @@ module ActionView
130
129
  end
131
130
 
132
131
  private
133
-
134
132
  def _find_all(name, prefix, partial, details, key, locals)
135
133
  find_templates(name, prefix, partial, details, locals)
136
134
  end
@@ -183,7 +181,6 @@ module ActionView
183
181
  end
184
182
 
185
183
  private
186
-
187
184
  def _find_all(name, prefix, partial, details, key, locals)
188
185
  path = Path.build(name, prefix, partial)
189
186
  query(path, details, details[:formats], locals, cache: !!key)
@@ -323,7 +320,6 @@ module ActionView
323
320
  end
324
321
 
325
322
  private
326
-
327
323
  def find_template_paths_from_details(path, details)
328
324
  # Instead of checking for every possible path, as our other globs would
329
325
  # do, scan the directory for files with the right prefix.
@@ -358,7 +354,7 @@ module ActionView
358
354
  end
359
355
 
360
356
  def build_regex(path, details)
361
- query = escape_entry(File.join(@path, path))
357
+ query = Regexp.escape(File.join(@path, path))
362
358
  exts = EXTENSIONS.map do |ext, prefix|
363
359
  match =
364
360
  if ext == :variants && details[ext] == :any