actionview 7.1.5.1 → 7.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,10 +27,10 @@ module ActionView
27
27
  extend ActiveSupport::Concern
28
28
  include ActionView::ViewPaths
29
29
 
30
- attr_reader :rendered_format
30
+ attr_internal_reader :rendered_format
31
31
 
32
32
  def initialize
33
- @rendered_format = nil
33
+ @_rendered_format = nil
34
34
  super
35
35
  end
36
36
 
@@ -136,7 +136,7 @@ module ActionView
136
136
  end
137
137
 
138
138
  rendered_format = rendered_template.format || lookup_context.formats.first
139
- @rendered_format = Template::Types[rendered_format]
139
+ @_rendered_format = Template::Types[rendered_format]
140
140
 
141
141
  rendered_template.body
142
142
  end
@@ -179,7 +179,7 @@ module ActionView
179
179
  options[:partial] = action_name
180
180
  end
181
181
 
182
- if (options.keys & [:partial, :file, :template]).empty?
182
+ if !options.keys.intersect?([:partial, :file, :template])
183
183
  options[:prefixes] ||= _prefixes
184
184
  end
185
185
 
@@ -14,10 +14,16 @@ module ActionView
14
14
 
15
15
  def render(context, *args)
16
16
  @renderable.render_in(context)
17
+ rescue NoMethodError
18
+ if !@renderable.respond_to?(:render_in)
19
+ raise ArgumentError, "'#{@renderable.inspect}' is not a renderable object. It must implement #render_in."
20
+ else
21
+ raise
22
+ end
17
23
  end
18
24
 
19
25
  def format
20
- @renderable.format
26
+ @renderable.try(:format)
21
27
  end
22
28
  end
23
29
  end
@@ -10,8 +10,6 @@ require "concurrent/map"
10
10
  module ActionView
11
11
  # = Action View Resolver
12
12
  class Resolver
13
- include ActiveSupport::Deprecation::DeprecatedConstantAccessor
14
-
15
13
  class PathParser # :nodoc:
16
14
  ParsedPath = Struct.new(:path, :details)
17
15
 
@@ -148,6 +148,20 @@ module ActionView
148
148
  # <p><%= alert %></p>
149
149
  # <% end %>
150
150
  #
151
+ # By default, templates will accept any <tt>locals</tt> as keyword arguments
152
+ # and make them available to <tt>local_assigns</tt>. To restrict what
153
+ # <tt>local_assigns</tt> a template will accept, add a <tt>locals:</tt> magic comment:
154
+ #
155
+ # <%# locals: (headline:, alerts: []) %>
156
+ #
157
+ # <h1><%= headline %></h1>
158
+ #
159
+ # <% alerts.each do |alert| %>
160
+ # <p><%= alert %></p>
161
+ # <% end %>
162
+ #
163
+ # Read more about strict locals in {Action View Overview}[https://guides.rubyonrails.org/action_view_overview.html#strict-locals]
164
+ # in the guides.
151
165
 
152
166
  eager_autoload do
153
167
  autoload :Error
@@ -531,12 +545,15 @@ module ActionView
531
545
  end
532
546
  end
533
547
 
548
+ RUBY_RESERVED_KEYWORDS = ::ActiveSupport::Delegation::RUBY_RESERVED_KEYWORDS
549
+ private_constant :RUBY_RESERVED_KEYWORDS
550
+
534
551
  def locals_code
535
552
  return "" if strict_locals?
536
553
 
537
554
  # Only locals with valid variable names get set directly. Others will
538
555
  # still be available in local_assigns.
539
- locals = @locals - Module::RUBY_RESERVED_KEYWORDS
556
+ locals = @locals - RUBY_RESERVED_KEYWORDS
540
557
 
541
558
  locals = locals.grep(/\A(?![A-Z0-9])(?:[[:alnum:]_]|[^\0-\177])+\z/)
542
559
 
@@ -171,10 +171,9 @@ module ActionView
171
171
  # Almost a duplicate from ActionController::Helpers
172
172
  methods.flatten.each do |method|
173
173
  _helpers_for_modification.module_eval <<~end_eval, __FILE__, __LINE__ + 1
174
- def #{method}(*args, &block) # def current_user(*args, &block)
175
- _test_case.send(:'#{method}', *args, &block) # _test_case.send(:'current_user', *args, &block)
176
- end # end
177
- ruby2_keywords(:'#{method}')
174
+ def #{method}(...) # def current_user(...)
175
+ _test_case.send(:'#{method}', ...) # _test_case.send(:'current_user', ...)
176
+ end # end
178
177
  end_eval
179
178
  end
180
179
  end
@@ -202,7 +201,7 @@ module ActionView
202
201
 
203
202
  setup :setup_with_controller
204
203
 
205
- register_parser :html, -> rendered { Rails::Dom::Testing.html_document.parse(rendered).root }
204
+ register_parser :html, -> rendered { Rails::Dom::Testing.html_document_fragment.parse(rendered) }
206
205
  register_parser :json, -> rendered { JSON.parse(rendered, object_class: ActiveSupport::HashWithIndifferentAccess) }
207
206
 
208
207
  ActiveSupport.run_load_hooks(:action_view_test_case, self)
@@ -416,7 +415,7 @@ module ActionView
416
415
  end]
417
416
  end
418
417
 
419
- def method_missing(selector, *args)
418
+ def method_missing(selector, ...)
420
419
  begin
421
420
  routes = @controller.respond_to?(:_routes) && @controller._routes
422
421
  rescue
@@ -426,16 +425,15 @@ module ActionView
426
425
  if routes &&
427
426
  (routes.named_routes.route_defined?(selector) ||
428
427
  routes.mounted_helpers.method_defined?(selector))
429
- @controller.__send__(selector, *args)
428
+ @controller.__send__(selector, ...)
430
429
  else
431
430
  super
432
431
  end
433
432
  end
434
- ruby2_keywords(:method_missing)
435
433
 
436
434
  def respond_to_missing?(name, include_private = false)
437
435
  begin
438
- routes = defined?(@controller) && @controller.respond_to?(:_routes) && @controller._routes
436
+ routes = @controller.respond_to?(:_routes) && @controller._routes
439
437
  rescue
440
438
  # Don't call routes, if there is an error on _routes call
441
439
  end