actionview 7.1.3.2 → 7.2.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +43 -413
- data/lib/action_view/base.rb +20 -3
- data/lib/action_view/cache_expiry.rb +9 -3
- data/lib/action_view/dependency_tracker/{ripper_tracker.rb → ruby_tracker.rb} +4 -3
- data/lib/action_view/dependency_tracker.rb +1 -1
- data/lib/action_view/gem_version.rb +3 -3
- data/lib/action_view/helpers/asset_tag_helper.rb +15 -3
- data/lib/action_view/helpers/cache_helper.rb +4 -4
- data/lib/action_view/helpers/csrf_helper.rb +1 -1
- data/lib/action_view/helpers/form_helper.rb +197 -192
- data/lib/action_view/helpers/form_tag_helper.rb +76 -43
- data/lib/action_view/helpers/output_safety_helper.rb +4 -4
- data/lib/action_view/helpers/tag_helper.rb +208 -18
- data/lib/action_view/helpers/url_helper.rb +4 -78
- data/lib/action_view/layouts.rb +2 -4
- data/lib/action_view/log_subscriber.rb +8 -4
- data/lib/action_view/railtie.rb +0 -1
- data/lib/action_view/render_parser/prism_render_parser.rb +127 -0
- data/lib/action_view/{ripper_ast_parser.rb → render_parser/ripper_render_parser.rb} +152 -9
- data/lib/action_view/render_parser.rb +21 -169
- data/lib/action_view/renderer/abstract_renderer.rb +1 -1
- data/lib/action_view/renderer/renderer.rb +32 -38
- data/lib/action_view/rendering.rb +4 -4
- data/lib/action_view/template/renderable.rb +7 -1
- data/lib/action_view/template/resolver.rb +0 -2
- data/lib/action_view/template.rb +28 -4
- data/lib/action_view/test_case.rb +12 -14
- data/lib/action_view/unbound_template.rb +4 -4
- data/lib/action_view.rb +1 -1
- data/lib/assets/compiled/rails-ujs.js +777 -0
- metadata +17 -15
@@ -27,10 +27,10 @@ module ActionView
|
|
27
27
|
extend ActiveSupport::Concern
|
28
28
|
include ActionView::ViewPaths
|
29
29
|
|
30
|
-
|
30
|
+
attr_internal_reader :rendered_format
|
31
31
|
|
32
32
|
def initialize
|
33
|
-
@
|
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
|
-
@
|
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
|
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
|
data/lib/action_view/template.rb
CHANGED
@@ -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
|
@@ -258,7 +272,8 @@ module ActionView
|
|
258
272
|
view._run(method_name, self, locals, buffer, add_to_stack: add_to_stack, has_strict_locals: strict_locals?, &block)
|
259
273
|
nil
|
260
274
|
else
|
261
|
-
view._run(method_name, self, locals, OutputBuffer.new, add_to_stack: add_to_stack, has_strict_locals: strict_locals?, &block)
|
275
|
+
result = view._run(method_name, self, locals, OutputBuffer.new, add_to_stack: add_to_stack, has_strict_locals: strict_locals?, &block)
|
276
|
+
result.is_a?(OutputBuffer) ? result.to_s : result
|
262
277
|
end
|
263
278
|
end
|
264
279
|
rescue => e
|
@@ -423,9 +438,13 @@ module ActionView
|
|
423
438
|
|
424
439
|
method_arguments =
|
425
440
|
if set_strict_locals
|
426
|
-
|
441
|
+
if set_strict_locals.include?("&")
|
442
|
+
"output_buffer, #{set_strict_locals}"
|
443
|
+
else
|
444
|
+
"output_buffer, #{set_strict_locals}, &_"
|
445
|
+
end
|
427
446
|
else
|
428
|
-
"local_assigns, output_buffer"
|
447
|
+
"local_assigns, output_buffer, &_"
|
429
448
|
end
|
430
449
|
|
431
450
|
# Make sure that the resulting String to be eval'd is in the
|
@@ -490,6 +509,8 @@ module ActionView
|
|
490
509
|
![:keyreq, :key, :keyrest, :nokey].include?(parameter[0])
|
491
510
|
end
|
492
511
|
|
512
|
+
non_kwarg_parameters.pop if non_kwarg_parameters.last == %i(block _)
|
513
|
+
|
493
514
|
unless non_kwarg_parameters.empty?
|
494
515
|
mod.undef_method(method_name)
|
495
516
|
|
@@ -524,12 +545,15 @@ module ActionView
|
|
524
545
|
end
|
525
546
|
end
|
526
547
|
|
548
|
+
RUBY_RESERVED_KEYWORDS = ::ActiveSupport::Delegation::RUBY_RESERVED_KEYWORDS
|
549
|
+
private_constant :RUBY_RESERVED_KEYWORDS
|
550
|
+
|
527
551
|
def locals_code
|
528
552
|
return "" if strict_locals?
|
529
553
|
|
530
554
|
# Only locals with valid variable names get set directly. Others will
|
531
555
|
# still be available in local_assigns.
|
532
|
-
locals = @locals -
|
556
|
+
locals = @locals - RUBY_RESERVED_KEYWORDS
|
533
557
|
|
534
558
|
locals = locals.grep(/\A(?![A-Z0-9])(?:[[:alnum:]_]|[^\0-\177])+\z/)
|
535
559
|
|
@@ -60,7 +60,7 @@ module ActionView
|
|
60
60
|
include ActiveSupport::Testing::ConstantLookup
|
61
61
|
|
62
62
|
delegate :lookup_context, to: :controller
|
63
|
-
attr_accessor :controller, :request, :output_buffer
|
63
|
+
attr_accessor :controller, :request, :output_buffer, :rendered
|
64
64
|
|
65
65
|
module ClassMethods
|
66
66
|
def inherited(descendant) # :nodoc:
|
@@ -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}(
|
175
|
-
_test_case.send(:'#{method}',
|
176
|
-
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.
|
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)
|
@@ -224,7 +223,7 @@ module ActionView
|
|
224
223
|
@request = @controller.request
|
225
224
|
@view_flow = ActionView::OutputFlow.new
|
226
225
|
@output_buffer = ActionView::OutputBuffer.new
|
227
|
-
@rendered = +""
|
226
|
+
@rendered = self.class.content_class.new(+"")
|
228
227
|
|
229
228
|
test_case_instance = self
|
230
229
|
controller_class.define_method(:_test_case) { test_case_instance }
|
@@ -244,6 +243,9 @@ module ActionView
|
|
244
243
|
@_rendered_views ||= RenderedViewsCollection.new
|
245
244
|
end
|
246
245
|
|
246
|
+
##
|
247
|
+
# :method: rendered
|
248
|
+
#
|
247
249
|
# Returns the content rendered by the last +render+ call.
|
248
250
|
#
|
249
251
|
# The returned object behaves like a string but also exposes a number of methods
|
@@ -291,9 +293,6 @@ module ActionView
|
|
291
293
|
#
|
292
294
|
# assert_pattern { rendered.json => { title: "Hello, world" } }
|
293
295
|
# end
|
294
|
-
def rendered
|
295
|
-
@_rendered ||= self.class.content_class.new(@rendered)
|
296
|
-
end
|
297
296
|
|
298
297
|
def _routes
|
299
298
|
@controller._routes if @controller.respond_to?(:_routes)
|
@@ -416,7 +415,7 @@ module ActionView
|
|
416
415
|
end]
|
417
416
|
end
|
418
417
|
|
419
|
-
def method_missing(selector,
|
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,
|
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 =
|
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
|
@@ -26,15 +26,15 @@ module ActionView
|
|
26
26
|
# while holding the lock.
|
27
27
|
template = (@templates[normalized_locals] ||= build_template(normalized_locals))
|
28
28
|
|
29
|
-
# This may have already been assigned, but we've already de-dup'd so
|
30
|
-
# reassignment is fine.
|
31
|
-
@templates[locals.dup] = template
|
32
|
-
|
33
29
|
if template.strict_locals?
|
34
30
|
# Under strict locals, we only need one template.
|
35
31
|
# This replaces the @templates Concurrent::Map with a hash which
|
36
32
|
# returns this template for every key.
|
37
33
|
@templates = Hash.new(template).freeze
|
34
|
+
else
|
35
|
+
# This may have already been assigned, but we've already de-dup'd so
|
36
|
+
# reassignment is fine.
|
37
|
+
@templates[locals.dup] = template
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
data/lib/action_view.rb
CHANGED