actionview 6.0.4.6 → 6.1.0.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 (66) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +152 -288
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +1 -1
  5. data/lib/action_view/base.rb +21 -52
  6. data/lib/action_view/cache_expiry.rb +1 -2
  7. data/lib/action_view/context.rb +0 -1
  8. data/lib/action_view/dependency_tracker.rb +10 -4
  9. data/lib/action_view/digestor.rb +3 -2
  10. data/lib/action_view/gem_version.rb +3 -3
  11. data/lib/action_view/helpers/asset_tag_helper.rb +40 -15
  12. data/lib/action_view/helpers/asset_url_helper.rb +6 -4
  13. data/lib/action_view/helpers/atom_feed_helper.rb +2 -1
  14. data/lib/action_view/helpers/cache_helper.rb +10 -16
  15. data/lib/action_view/helpers/date_helper.rb +4 -4
  16. data/lib/action_view/helpers/form_helper.rb +59 -17
  17. data/lib/action_view/helpers/form_options_helper.rb +7 -16
  18. data/lib/action_view/helpers/form_tag_helper.rb +8 -6
  19. data/lib/action_view/helpers/javascript_helper.rb +3 -3
  20. data/lib/action_view/helpers/number_helper.rb +6 -6
  21. data/lib/action_view/helpers/rendering_helper.rb +11 -3
  22. data/lib/action_view/helpers/sanitize_helper.rb +2 -2
  23. data/lib/action_view/helpers/tag_helper.rb +92 -17
  24. data/lib/action_view/helpers/tags/base.rb +9 -5
  25. data/lib/action_view/helpers/tags/date_field.rb +1 -1
  26. data/lib/action_view/helpers/tags/date_select.rb +2 -2
  27. data/lib/action_view/helpers/tags/datetime_local_field.rb +1 -1
  28. data/lib/action_view/helpers/tags/label.rb +4 -0
  29. data/lib/action_view/helpers/tags/month_field.rb +1 -1
  30. data/lib/action_view/helpers/tags/select.rb +1 -1
  31. data/lib/action_view/helpers/tags/time_field.rb +1 -1
  32. data/lib/action_view/helpers/tags/week_field.rb +1 -1
  33. data/lib/action_view/helpers/text_helper.rb +1 -1
  34. data/lib/action_view/helpers/translation_helper.rb +88 -53
  35. data/lib/action_view/helpers/url_helper.rb +107 -13
  36. data/lib/action_view/layouts.rb +3 -2
  37. data/lib/action_view/log_subscriber.rb +26 -10
  38. data/lib/action_view/lookup_context.rb +3 -18
  39. data/lib/action_view/path_set.rb +0 -3
  40. data/lib/action_view/railtie.rb +35 -46
  41. data/lib/action_view/renderer/abstract_renderer.rb +93 -14
  42. data/lib/action_view/renderer/collection_renderer.rb +192 -0
  43. data/lib/action_view/renderer/object_renderer.rb +34 -0
  44. data/lib/action_view/renderer/partial_renderer/collection_caching.rb +25 -26
  45. data/lib/action_view/renderer/partial_renderer.rb +20 -282
  46. data/lib/action_view/renderer/renderer.rb +44 -1
  47. data/lib/action_view/renderer/streaming_template_renderer.rb +5 -1
  48. data/lib/action_view/renderer/template_renderer.rb +15 -12
  49. data/lib/action_view/rendering.rb +3 -1
  50. data/lib/action_view/routing_url_for.rb +1 -1
  51. data/lib/action_view/template/handlers/erb/erubi.rb +9 -7
  52. data/lib/action_view/template/handlers/erb.rb +10 -14
  53. data/lib/action_view/template/handlers.rb +0 -26
  54. data/lib/action_view/template/html.rb +1 -11
  55. data/lib/action_view/template/raw_file.rb +0 -3
  56. data/lib/action_view/template/renderable.rb +24 -0
  57. data/lib/action_view/template/resolver.rb +82 -40
  58. data/lib/action_view/template/text.rb +0 -3
  59. data/lib/action_view/template.rb +9 -49
  60. data/lib/action_view/test_case.rb +18 -25
  61. data/lib/action_view/testing/resolvers.rb +10 -31
  62. data/lib/action_view/unbound_template.rb +3 -3
  63. data/lib/action_view/view_paths.rb +34 -36
  64. data/lib/action_view.rb +4 -1
  65. data/lib/assets/compiled/rails-ujs.js +1 -1
  66. metadata +20 -17
@@ -12,7 +12,7 @@ module ActionView
12
12
 
13
13
  private
14
14
  def format_date(value)
15
- value.try(:strftime, "%Y-%m-%dT%T")
15
+ value&.strftime("%Y-%m-%dT%T")
16
16
  end
17
17
  end
18
18
  end
@@ -25,6 +25,10 @@ module ActionView
25
25
 
26
26
  content
27
27
  end
28
+
29
+ def to_s
30
+ translation
31
+ end
28
32
  end
29
33
 
30
34
  def initialize(object_name, method_name, template_object, content_or_options = nil, options = nil)
@@ -6,7 +6,7 @@ module ActionView
6
6
  class MonthField < DatetimeField # :nodoc:
7
7
  private
8
8
  def format_date(value)
9
- value.try(:strftime, "%Y-%m")
9
+ value&.strftime("%Y-%m")
10
10
  end
11
11
  end
12
12
  end
@@ -15,7 +15,7 @@ module ActionView
15
15
 
16
16
  def render
17
17
  option_tags_options = {
18
- selected: @options.fetch(:selected) { value },
18
+ selected: @options.fetch(:selected) { value.to_s },
19
19
  disabled: @options[:disabled]
20
20
  }
21
21
 
@@ -6,7 +6,7 @@ module ActionView
6
6
  class TimeField < DatetimeField # :nodoc:
7
7
  private
8
8
  def format_date(value)
9
- value.try(:strftime, "%T.%L")
9
+ value&.strftime("%T.%L")
10
10
  end
11
11
  end
12
12
  end
@@ -6,7 +6,7 @@ module ActionView
6
6
  class WeekField < DatetimeField # :nodoc:
7
7
  private
8
8
  def format_date(value)
9
- value.try(:strftime, "%Y-W%V")
9
+ value&.strftime("%Y-W%V")
10
10
  end
11
11
  end
12
12
  end
@@ -228,7 +228,7 @@ module ActionView
228
228
  # pluralize(2, 'Person', locale: :de)
229
229
  # # => 2 Personen
230
230
  def pluralize(count, singular, plural_arg = nil, plural: plural_arg, locale: I18n.locale)
231
- word = if count == 1 || count.to_s =~ /^1(\.0+)?$/
231
+ word = if count == 1 || count.to_s.match?(/^1(\.0+)?$/)
232
232
  singular
233
233
  else
234
234
  plural || singular.pluralize(locale)
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "action_view/helpers/tag_helper"
4
- require "active_support/core_ext/string/access"
5
- require "i18n/exceptions"
4
+ require "active_support/core_ext/symbol/starts_ends_with"
6
5
 
7
6
  module ActionView
8
7
  # = Action View Translation Helpers
@@ -57,64 +56,55 @@ module ActionView
57
56
  # that include HTML tags so that you know what kind of output to expect
58
57
  # when you call translate in a template and translators know which keys
59
58
  # they can provide HTML values for.
59
+ #
60
+ # To access the translated text along with the fully resolved
61
+ # translation key, <tt>translate</tt> accepts a block:
62
+ #
63
+ # <%= translate(".relative_key") do |translation, resolved_key| %>
64
+ # <span title="<%= resolved_key %>"><%= translation %></span>
65
+ # <% end %>
66
+ #
67
+ # This enables annotate translated text to be aware of the scope it was
68
+ # resolved against.
69
+ #
60
70
  def translate(key, **options)
61
- if options.has_key?(:default)
62
- remaining_defaults = Array.wrap(options.delete(:default)).compact
63
- options[:default] = remaining_defaults unless remaining_defaults.first.kind_of?(Symbol)
64
- end
71
+ return key.map { |k| translate(k, **options) } if key.is_a?(Array)
65
72
 
66
- # If the user has explicitly decided to NOT raise errors, pass that option to I18n.
67
- # Otherwise, tell I18n to raise an exception, which we rescue further in this method.
68
- # Note: `raise_error` refers to us re-raising the error in this method. I18n is forced to raise by default.
69
- if options[:raise] == false
70
- raise_error = false
71
- i18n_raise = false
72
- else
73
- raise_error = options[:raise] || ActionView::Base.raise_on_missing_translations
74
- i18n_raise = true
73
+ alternatives = if options.key?(:default)
74
+ options[:default].is_a?(Array) ? options.delete(:default).compact : [options.delete(:default)]
75
75
  end
76
76
 
77
- if html_safe_translation_key?(key)
78
- html_safe_options = options.dup
77
+ options[:raise] = true if options[:raise].nil? && ActionView::Base.raise_on_missing_translations
78
+ default = MISSING_TRANSLATION
79
79
 
80
- options.except(*I18n::RESERVED_KEYS).each do |name, value|
81
- unless name == :count && value.is_a?(Numeric)
82
- html_safe_options[name] = ERB::Util.html_escape(value.to_s)
83
- end
80
+ translation = while key
81
+ if alternatives.blank? && !options[:raise].nil?
82
+ default = NO_DEFAULT # let I18n handle missing translation
84
83
  end
85
84
 
86
- html_safe_options[:default] = MISSING_TRANSLATION unless html_safe_options[:default].blank?
87
-
88
- translation = I18n.translate(scope_key_by_partial(key), **html_safe_options.merge(raise: i18n_raise))
85
+ key = scope_key_by_partial(key)
86
+ first_key ||= key
89
87
 
90
- if translation.equal?(MISSING_TRANSLATION)
91
- options[:default].first
92
- elsif translation.respond_to?(:map)
93
- translation.map { |element| element.respond_to?(:html_safe) ? element.html_safe : element }
88
+ if html_safe_translation_key?(key)
89
+ html_safe_options ||= html_escape_translation_options(options)
90
+ translated = I18n.translate(key, **html_safe_options, default: default)
91
+ break html_safe_translation(translated) unless translated.equal?(MISSING_TRANSLATION)
94
92
  else
95
- translation.respond_to?(:html_safe) ? translation.html_safe : translation
96
- end
97
- else
98
- I18n.translate(scope_key_by_partial(key), **options.merge(raise: i18n_raise))
99
- end
100
- rescue I18n::MissingTranslationData => e
101
- if remaining_defaults.present?
102
- translate remaining_defaults.shift, **options.merge(default: remaining_defaults)
103
- else
104
- raise e if raise_error
105
-
106
- keys = I18n.normalize_keys(e.locale, e.key, e.options[:scope])
107
- title = +"translation missing: #{keys.join('.')}"
108
-
109
- interpolations = options.except(:default, :scope)
110
- if interpolations.any?
111
- title << ", " << interpolations.map { |k, v| "#{k}: #{ERB::Util.html_escape(v)}" }.join(", ")
93
+ translated = I18n.translate(key, **options, default: default)
94
+ break translated unless translated.equal?(MISSING_TRANSLATION)
112
95
  end
113
96
 
114
- return title unless ActionView::Base.debug_missing_translation
97
+ break alternatives.first if alternatives.present? && !alternatives.first.is_a?(Symbol)
115
98
 
116
- content_tag("span", keys.last.to_s.titleize, class: "translation_missing", title: title)
99
+ key = alternatives&.shift
117
100
  end
101
+
102
+ if key.nil?
103
+ translation = missing_translation(first_key, options)
104
+ key = first_key
105
+ end
106
+
107
+ block_given? ? yield(translation, key) : translation
118
108
  end
119
109
  alias :t :translate
120
110
 
@@ -131,13 +121,19 @@ module ActionView
131
121
  MISSING_TRANSLATION = Object.new
132
122
  private_constant :MISSING_TRANSLATION
133
123
 
124
+ NO_DEFAULT = [].freeze
125
+ private_constant :NO_DEFAULT
126
+
127
+ def self.i18n_option?(name)
128
+ (@i18n_option_names ||= I18n::RESERVED_KEYS.to_set).include?(name)
129
+ end
130
+
134
131
  def scope_key_by_partial(key)
135
- stringified_key = key.to_s
136
- if stringified_key.first == "."
137
- if @virtual_path
132
+ if key.start_with?(".")
133
+ if @current_template&.virtual_path
138
134
  @_scope_key_by_partial_cache ||= {}
139
- @_scope_key_by_partial_cache[@virtual_path] ||= @virtual_path.gsub(%r{/_?}, ".")
140
- "#{@_scope_key_by_partial_cache[@virtual_path]}#{stringified_key}"
135
+ @_scope_key_by_partial_cache[@current_template.virtual_path] ||= @current_template.virtual_path.gsub(%r{/_?}, ".")
136
+ "#{@_scope_key_by_partial_cache[@current_template.virtual_path]}#{key}"
141
137
  else
142
138
  raise "Cannot use t(#{key.inspect}) shortcut because path is not available"
143
139
  end
@@ -146,8 +142,47 @@ module ActionView
146
142
  end
147
143
  end
148
144
 
145
+ def html_escape_translation_options(options)
146
+ return options if options.empty?
147
+ html_safe_options = options.dup
148
+
149
+ options.each do |name, value|
150
+ unless TranslationHelper.i18n_option?(name) || (name == :count && value.is_a?(Numeric))
151
+ html_safe_options[name] = ERB::Util.html_escape(value.to_s)
152
+ end
153
+ end
154
+
155
+ html_safe_options
156
+ end
157
+
149
158
  def html_safe_translation_key?(key)
150
- /(?:_|\b)html\z/.match?(key.to_s)
159
+ /(?:_|\b)html\z/.match?(key)
160
+ end
161
+
162
+ def html_safe_translation(translation)
163
+ if translation.respond_to?(:map)
164
+ translation.map { |element| element.respond_to?(:html_safe) ? element.html_safe : element }
165
+ else
166
+ translation.respond_to?(:html_safe) ? translation.html_safe : translation
167
+ end
168
+ end
169
+
170
+ def missing_translation(key, options)
171
+ keys = I18n.normalize_keys(options[:locale] || I18n.locale, key, options[:scope])
172
+
173
+ title = +"translation missing: #{keys.join(".")}"
174
+
175
+ options.each do |name, value|
176
+ unless name == :scope
177
+ title << ", " << name.to_s << ": " << ERB::Util.html_escape(value)
178
+ end
179
+ end
180
+
181
+ if ActionView::Base.debug_missing_translation
182
+ content_tag("span", keys.last.to_s.titleize, class: "translation_missing", title: title)
183
+ else
184
+ title
185
+ end
151
186
  end
152
187
  end
153
188
  end
@@ -45,7 +45,7 @@ module ActionView
45
45
  def _back_url # :nodoc:
46
46
  _filtered_referrer || "javascript:history.back()"
47
47
  end
48
- protected :_back_url
48
+ private :_back_url
49
49
 
50
50
  def _filtered_referrer # :nodoc:
51
51
  if controller.respond_to?(:request)
@@ -56,12 +56,12 @@ module ActionView
56
56
  end
57
57
  rescue URI::InvalidURIError
58
58
  end
59
- protected :_filtered_referrer
59
+ private :_filtered_referrer
60
60
 
61
61
  # Creates an anchor element of the given +name+ using a URL created by the set of +options+.
62
62
  # See the valid options in the documentation for +url_for+. It's also possible to
63
- # pass a String instead of an options hash, which generates an anchor element that uses the
64
- # value of the String as the href for the link. Using a <tt>:back</tt> Symbol instead
63
+ # pass a \String instead of an options hash, which generates an anchor element that uses the
64
+ # value of the \String as the href for the link. Using a <tt>:back</tt> \Symbol instead
65
65
  # of an options hash will generate a link to the referrer (a JavaScript back link
66
66
  # will be used in place of a referrer if none exists). If +nil+ is passed as the name
67
67
  # the value of the link itself will become the name.
@@ -177,7 +177,7 @@ module ActionView
177
177
  # # => <a href="/searches?query=ruby+on+rails">Ruby on Rails search</a>
178
178
  #
179
179
  # link_to "Nonsense search", searches_path(foo: "bar", baz: "quux")
180
- # # => <a href="/searches?foo=bar&amp;baz=quux">Nonsense search</a>
180
+ # # => <a href="/searches?foo=bar&baz=quux">Nonsense search</a>
181
181
  #
182
182
  # The only option specific to +link_to+ (<tt>:method</tt>) is used as follows:
183
183
  #
@@ -226,7 +226,7 @@ module ActionView
226
226
  # The +options+ hash accepts the same options as +url_for+.
227
227
  #
228
228
  # There are a few special +html_options+:
229
- # * <tt>:method</tt> - Symbol of HTTP verb. Supported verbs are <tt>:post</tt>, <tt>:get</tt>,
229
+ # * <tt>:method</tt> - \Symbol of HTTP verb. Supported verbs are <tt>:post</tt>, <tt>:get</tt>,
230
230
  # <tt>:delete</tt>, <tt>:patch</tt>, and <tt>:put</tt>. By default it will be <tt>:post</tt>.
231
231
  # * <tt>:disabled</tt> - If set to true, it will generate a disabled button.
232
232
  # * <tt>:data</tt> - This option can be used to add custom data attributes.
@@ -235,7 +235,7 @@ module ActionView
235
235
  # * <tt>:form</tt> - This hash will be form attributes
236
236
  # * <tt>:form_class</tt> - This controls the class of the form within which the submit button will
237
237
  # be placed
238
- # * <tt>:params</tt> - Hash of parameters to be rendered as hidden fields within the form.
238
+ # * <tt>:params</tt> - \Hash of parameters to be rendered as hidden fields within the form.
239
239
  #
240
240
  # ==== Data attributes
241
241
  #
@@ -290,7 +290,7 @@ module ActionView
290
290
  #
291
291
  #
292
292
  # <%= button_to('Destroy', 'http://www.example.com',
293
- # method: "delete", remote: true, data: { confirm: 'Are you sure?', disable_with: 'loading...' }) %>
293
+ # method: :delete, remote: true, data: { confirm: 'Are you sure?', disable_with: 'loading...' }) %>
294
294
  # # => "<form class='button_to' method='post' action='http://www.example.com' data-remote='true'>
295
295
  # # <input name='_method' value='delete' type='hidden' />
296
296
  # # <input value='Destroy' type='submit' data-disable-with='loading...' data-confirm='Are you sure?' />
@@ -412,8 +412,7 @@ module ActionView
412
412
  # Creates a link tag of the given +name+ using a URL created by the set of
413
413
  # +options+ if +condition+ is true, otherwise only the name is
414
414
  # returned. To specialize the default behavior, you can pass a block that
415
- # accepts the name or the full argument list for +link_to_unless+ (see the examples
416
- # in +link_to_unless+).
415
+ # accepts the name or the full argument list for +link_to_if+.
417
416
  #
418
417
  # ==== Examples
419
418
  # <%= link_to_if(@current_user.nil?, "Login", { controller: "sessions", action: "new" }) %>
@@ -550,14 +549,14 @@ module ActionView
550
549
  return false unless request.get? || request.head?
551
550
 
552
551
  check_parameters ||= options.is_a?(Hash) && options.delete(:check_parameters)
553
- url_string = URI.parser.unescape(url_for(options)).force_encoding(Encoding::BINARY)
552
+ url_string = URI::DEFAULT_PARSER.unescape(url_for(options)).force_encoding(Encoding::BINARY)
554
553
 
555
554
  # We ignore any extra parameters in the request_uri if the
556
555
  # submitted URL doesn't have any either. This lets the function
557
556
  # work with things like ?order=asc
558
557
  # the behaviour can be disabled with check_parameters: true
559
558
  request_uri = url_string.index("?") || check_parameters ? request.fullpath : request.path
560
- request_uri = URI.parser.unescape(request_uri).force_encoding(Encoding::BINARY)
559
+ request_uri = URI::DEFAULT_PARSER.unescape(request_uri).force_encoding(Encoding::BINARY)
561
560
 
562
561
  if url_string.start_with?("/") && url_string != "/"
563
562
  url_string.chomp!("/")
@@ -571,6 +570,101 @@ module ActionView
571
570
  end
572
571
  end
573
572
 
573
+ # Creates an SMS anchor link tag to the specified +phone_number+, which is
574
+ # also used as the name of the link unless +name+ is specified. Additional
575
+ # HTML attributes for the link can be passed in +html_options+.
576
+ #
577
+ # When clicked, an SMS message is prepopulated with the passed phone number
578
+ # and optional +body+ value.
579
+ #
580
+ # +sms_to+ has a +body+ option for customizing the SMS message itself by
581
+ # passing special keys to +html_options+.
582
+ #
583
+ # ==== Options
584
+ # * <tt>:body</tt> - Preset the body of the message.
585
+ #
586
+ # ==== Examples
587
+ # sms_to "5155555785"
588
+ # # => <a href="sms:5155555785;">5155555785</a>
589
+ #
590
+ # sms_to "5155555785", "Text me"
591
+ # # => <a href="sms:5155555785;">Text me</a>
592
+ #
593
+ # sms_to "5155555785", "Text me",
594
+ # body: "Hello Jim I have a question about your product."
595
+ # # => <a href="sms:5155555785;?body=Hello%20Jim%20I%20have%20a%20question%20about%20your%20product">Text me</a>
596
+ #
597
+ # You can use a block as well if your link target is hard to fit into the name parameter. \ERB example:
598
+ #
599
+ # <%= sms_to "5155555785" do %>
600
+ # <strong>Text me:</strong>
601
+ # <% end %>
602
+ # # => <a href="sms:5155555785;">
603
+ # <strong>Text me:</strong>
604
+ # </a>
605
+ def sms_to(phone_number, name = nil, html_options = {}, &block)
606
+ html_options, name = name, nil if block_given?
607
+ html_options = (html_options || {}).stringify_keys
608
+
609
+ extras = %w{ body }.map! { |item|
610
+ option = html_options.delete(item).presence || next
611
+ "#{item.dasherize}=#{ERB::Util.url_encode(option)}"
612
+ }.compact
613
+ extras = extras.empty? ? "" : "?&" + extras.join("&")
614
+
615
+ encoded_phone_number = ERB::Util.url_encode(phone_number)
616
+ html_options["href"] = "sms:#{encoded_phone_number};#{extras}"
617
+
618
+ content_tag("a", name || phone_number, html_options, &block)
619
+ end
620
+
621
+ # Creates a TEL anchor link tag to the specified +phone_number+, which is
622
+ # also used as the name of the link unless +name+ is specified. Additional
623
+ # HTML attributes for the link can be passed in +html_options+.
624
+ #
625
+ # When clicked, the default app to make calls is opened, and it
626
+ # is prepopulated with the passed phone number and optional
627
+ # +country_code+ value.
628
+ #
629
+ # +phone_to+ has an optional +country_code+ option which automatically adds the country
630
+ # code as well as the + sign in the phone numer that gets prepopulated,
631
+ # for example if +country_code: "01"+ +\+01+ will be prepended to the
632
+ # phone numer, by passing special keys to +html_options+.
633
+ #
634
+ # ==== Options
635
+ # * <tt>:country_code</tt> - Prepends the country code to the number
636
+ #
637
+ # ==== Examples
638
+ # phone_to "1234567890"
639
+ # # => <a href="tel:1234567890">1234567890</a>
640
+ #
641
+ # phone_to "1234567890", "Phone me"
642
+ # # => <a href="tel:134567890">Phone me</a>
643
+ #
644
+ # phone_to "1234567890", "Phone me", country_code: "01"
645
+ # # => <a href="tel:+015155555785">Phone me</a>
646
+ #
647
+ # You can use a block as well if your link target is hard to fit into the name parameter. \ERB example:
648
+ #
649
+ # <%= phone_to "1234567890" do %>
650
+ # <strong>Phone me:</strong>
651
+ # <% end %>
652
+ # # => <a href="tel:1234567890">
653
+ # <strong>Phone me:</strong>
654
+ # </a>
655
+ def phone_to(phone_number, name = nil, html_options = {}, &block)
656
+ html_options, name = name, nil if block_given?
657
+ html_options = (html_options || {}).stringify_keys
658
+
659
+ country_code = html_options.delete("country_code").presence
660
+ country_code = country_code.nil? ? "" : "+#{ERB::Util.url_encode(country_code)}"
661
+
662
+ encoded_phone_number = ERB::Util.url_encode(phone_number)
663
+ html_options["href"] = "tel:#{country_code}#{encoded_phone_number}"
664
+
665
+ content_tag("a", name || phone_number, html_options, &block)
666
+ end
667
+
574
668
  private
575
669
  def convert_options_to_data_attributes(options, html_options)
576
670
  if html_options
@@ -594,7 +688,7 @@ module ActionView
594
688
  end
595
689
 
596
690
  def add_method_to_attributes!(html_options, method)
597
- if method_not_get_method?(method) && html_options["rel"] !~ /nofollow/
691
+ if method_not_get_method?(method) && !html_options["rel"]&.match?(/nofollow/)
598
692
  if html_options["rel"].blank?
599
693
  html_options["rel"] = "nofollow"
600
694
  else
@@ -306,7 +306,7 @@ module ActionView
306
306
  RUBY
307
307
  when Proc
308
308
  define_method :_layout_from_proc, &_layout
309
- protected :_layout_from_proc
309
+ private :_layout_from_proc
310
310
  <<-RUBY
311
311
  result = _layout_from_proc(#{_layout.arity == 0 ? '' : 'self'})
312
312
  return #{default_behavior} if result.nil?
@@ -321,6 +321,7 @@ module ActionView
321
321
  end
322
322
 
323
323
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
324
+ # frozen_string_literal: true
324
325
  def _layout(lookup_context, formats)
325
326
  if _conditional_layout?
326
327
  #{layout_definition}
@@ -395,7 +396,7 @@ module ActionView
395
396
  end
396
397
 
397
398
  def _normalize_layout(value)
398
- value.is_a?(String) && value !~ /\blayouts/ ? "layouts/#{value}" : value
399
+ value.is_a?(String) && !value.match?(/\blayouts/) ? "layouts/#{value}" : value
399
400
  end
400
401
 
401
402
  # Returns the default layout for this controller.
@@ -23,7 +23,7 @@ module ActionView
23
23
  end
24
24
 
25
25
  def render_partial(event)
26
- info do
26
+ debug do
27
27
  message = +" Rendered #{from_rails_root(event.payload[:identifier])}"
28
28
  message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout]
29
29
  message << " (Duration: #{event.duration.round(1)}ms | Allocations: #{event.allocations})"
@@ -32,19 +32,26 @@ module ActionView
32
32
  end
33
33
  end
34
34
 
35
+ def render_layout(event)
36
+ info do
37
+ message = +" Rendered layout #{from_rails_root(event.payload[:identifier])}"
38
+ message << " (Duration: #{event.duration.round(1)}ms | Allocations: #{event.allocations})"
39
+ end
40
+ end
41
+
35
42
  def render_collection(event)
36
43
  identifier = event.payload[:identifier] || "templates"
37
44
 
38
- info do
39
- " Rendered collection of #{from_rails_root(identifier)}" \
40
- " #{render_count(event.payload)} (Duration: #{event.duration.round(1)}ms | Allocations: #{event.allocations})"
45
+ debug do
46
+ message = +" Rendered collection of #{from_rails_root(identifier)}"
47
+ message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout]
48
+ message << " #{render_count(event.payload)} (Duration: #{event.duration.round(1)}ms | Allocations: #{event.allocations})"
49
+ message
41
50
  end
42
51
  end
43
52
 
44
53
  def start(name, id, payload)
45
- if name == "render_template.action_view"
46
- log_rendering_start(payload)
47
- end
54
+ log_rendering_start(payload, name)
48
55
 
49
56
  super
50
57
  end
@@ -82,9 +89,18 @@ module ActionView
82
89
  end
83
90
  end
84
91
 
85
- def log_rendering_start(payload)
86
- info do
87
- message = +" Rendering #{from_rails_root(payload[:identifier])}"
92
+ def log_rendering_start(payload, name)
93
+ debug do
94
+ qualifier =
95
+ if name == "render_template.action_view"
96
+ ""
97
+ elsif name == "render_layout.action_view"
98
+ "layout "
99
+ end
100
+
101
+ return unless qualifier
102
+
103
+ message = +" Rendering #{qualifier}#{from_rails_root(payload[:identifier])}"
88
104
  message << " within #{from_rails_root(payload[:layout])}" if payload[:layout]
89
105
  message
90
106
  end
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "concurrent/map"
4
- require "active_support/core_ext/module/remove_method"
5
4
  require "active_support/core_ext/module/attribute_accessors"
6
- require "active_support/deprecation"
7
5
  require "action_view/template/resolver"
8
6
 
9
7
  module ActionView
@@ -16,8 +14,6 @@ module ActionView
16
14
  # only once during the request, it speeds up all cache accesses.
17
15
  class LookupContext #:nodoc:
18
16
  attr_accessor :prefixes, :rendered_format
19
- deprecate :rendered_format
20
- deprecate :rendered_format=
21
17
 
22
18
  mattr_accessor :fallbacks, default: FallbackFileSystemResolver.instances
23
19
 
@@ -30,7 +26,7 @@ module ActionView
30
26
  Accessors.define_method(:"default_#{name}", &block)
31
27
  Accessors.module_eval <<-METHOD, __FILE__, __LINE__ + 1
32
28
  def #{name}
33
- @details.fetch(:#{name}, [])
29
+ @details[:#{name}] || []
34
30
  end
35
31
 
36
32
  def #{name}=(value)
@@ -132,9 +128,6 @@ module ActionView
132
128
  end
133
129
  alias :find_template :find
134
130
 
135
- alias :find_file :find
136
- deprecate :find_file
137
-
138
131
  def find_all(name, prefixes = [], partial = false, keys = [], options = {})
139
132
  @view_paths.find_all(*args_for_lookup(name, prefixes, partial, keys, options))
140
133
  end
@@ -155,18 +148,10 @@ module ActionView
155
148
  view_paths = build_view_paths((@view_paths.paths + self.class.fallbacks).uniq)
156
149
 
157
150
  if block_given?
158
- ActiveSupport::Deprecation.warn <<~eowarn.squish
159
- Calling `with_fallbacks` with a block is deprecated. Call methods on
151
+ raise ArgumentError, <<~eowarn.squish
152
+ Calling `with_fallbacks` with a block is not supported. Call methods on
160
153
  the lookup context returned by `with_fallbacks` instead.
161
154
  eowarn
162
-
163
- begin
164
- _view_paths = @view_paths
165
- @view_paths = view_paths
166
- yield
167
- ensure
168
- @view_paths = _view_paths
169
- end
170
155
  else
171
156
  ActionView::LookupContext.new(view_paths, @details, @prefixes)
172
157
  end
@@ -48,9 +48,6 @@ module ActionView #:nodoc:
48
48
  find_all(*args).first || raise(MissingTemplate.new(self, *args))
49
49
  end
50
50
 
51
- alias :find_file :find
52
- deprecate :find_file
53
-
54
51
  def find_all(path, prefixes = [], *args)
55
52
  _find_all path, prefixes, args
56
53
  end