actionview 7.1.3.3 → 7.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +42 -417
  3. data/lib/action_view/base.rb +20 -3
  4. data/lib/action_view/cache_expiry.rb +9 -3
  5. data/lib/action_view/dependency_tracker/{ripper_tracker.rb → ruby_tracker.rb} +4 -3
  6. data/lib/action_view/dependency_tracker.rb +1 -1
  7. data/lib/action_view/gem_version.rb +3 -3
  8. data/lib/action_view/helpers/asset_tag_helper.rb +15 -3
  9. data/lib/action_view/helpers/cache_helper.rb +4 -4
  10. data/lib/action_view/helpers/csrf_helper.rb +1 -1
  11. data/lib/action_view/helpers/form_helper.rb +197 -192
  12. data/lib/action_view/helpers/form_tag_helper.rb +76 -43
  13. data/lib/action_view/helpers/output_safety_helper.rb +4 -4
  14. data/lib/action_view/helpers/tag_helper.rb +208 -18
  15. data/lib/action_view/helpers/url_helper.rb +4 -78
  16. data/lib/action_view/layouts.rb +2 -4
  17. data/lib/action_view/log_subscriber.rb +8 -4
  18. data/lib/action_view/railtie.rb +0 -1
  19. data/lib/action_view/render_parser/prism_render_parser.rb +127 -0
  20. data/lib/action_view/{ripper_ast_parser.rb → render_parser/ripper_render_parser.rb} +152 -9
  21. data/lib/action_view/render_parser.rb +21 -169
  22. data/lib/action_view/renderer/abstract_renderer.rb +1 -1
  23. data/lib/action_view/renderer/renderer.rb +32 -38
  24. data/lib/action_view/rendering.rb +4 -4
  25. data/lib/action_view/template/renderable.rb +7 -1
  26. data/lib/action_view/template/resolver.rb +0 -2
  27. data/lib/action_view/template.rb +28 -4
  28. data/lib/action_view/test_case.rb +12 -14
  29. data/lib/action_view/unbound_template.rb +4 -4
  30. data/lib/action_view.rb +1 -1
  31. metadata +15 -14
@@ -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
@@ -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)&.to_s
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
- "output_buffer, #{set_strict_locals}"
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 - Module::RUBY_RESERVED_KEYWORDS
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}(*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)
@@ -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, *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
@@ -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
@@ -28,7 +28,7 @@ require "active_support/rails"
28
28
  require "action_view/version"
29
29
  require "action_view/deprecator"
30
30
 
31
- # :include: actionview/README.rdoc
31
+ # :include: ../README.rdoc
32
32
  module ActionView
33
33
  extend ActiveSupport::Autoload
34
34
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionview
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.1.3.3
4
+ version: 7.2.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-16 00:00:00.000000000 Z
11
+ date: 2024-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 7.1.3.3
19
+ version: 7.2.0.beta1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 7.1.3.3
26
+ version: 7.2.0.beta1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: builder
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -86,28 +86,28 @@ dependencies:
86
86
  requirements:
87
87
  - - '='
88
88
  - !ruby/object:Gem::Version
89
- version: 7.1.3.3
89
+ version: 7.2.0.beta1
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - '='
95
95
  - !ruby/object:Gem::Version
96
- version: 7.1.3.3
96
+ version: 7.2.0.beta1
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: activemodel
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 7.1.3.3
103
+ version: 7.2.0.beta1
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: 7.1.3.3
110
+ version: 7.2.0.beta1
111
111
  description: Simple, battle-tested conventions and helpers for building web pages.
112
112
  email: david@loudthinking.com
113
113
  executables: []
@@ -126,7 +126,7 @@ files:
126
126
  - lib/action_view/context.rb
127
127
  - lib/action_view/dependency_tracker.rb
128
128
  - lib/action_view/dependency_tracker/erb_tracker.rb
129
- - lib/action_view/dependency_tracker/ripper_tracker.rb
129
+ - lib/action_view/dependency_tracker/ruby_tracker.rb
130
130
  - lib/action_view/deprecator.rb
131
131
  - lib/action_view/digestor.rb
132
132
  - lib/action_view/flows.rb
@@ -204,6 +204,8 @@ files:
204
204
  - lib/action_view/railtie.rb
205
205
  - lib/action_view/record_identifier.rb
206
206
  - lib/action_view/render_parser.rb
207
+ - lib/action_view/render_parser/prism_render_parser.rb
208
+ - lib/action_view/render_parser/ripper_render_parser.rb
207
209
  - lib/action_view/renderer/abstract_renderer.rb
208
210
  - lib/action_view/renderer/collection_renderer.rb
209
211
  - lib/action_view/renderer/object_renderer.rb
@@ -213,7 +215,6 @@ files:
213
215
  - lib/action_view/renderer/streaming_template_renderer.rb
214
216
  - lib/action_view/renderer/template_renderer.rb
215
217
  - lib/action_view/rendering.rb
216
- - lib/action_view/ripper_ast_parser.rb
217
218
  - lib/action_view/routing_url_for.rb
218
219
  - lib/action_view/tasks/cache_digests.rake
219
220
  - lib/action_view/template.rb
@@ -246,10 +247,10 @@ licenses:
246
247
  - MIT
247
248
  metadata:
248
249
  bug_tracker_uri: https://github.com/rails/rails/issues
249
- changelog_uri: https://github.com/rails/rails/blob/v7.1.3.3/actionview/CHANGELOG.md
250
- documentation_uri: https://api.rubyonrails.org/v7.1.3.3/
250
+ changelog_uri: https://github.com/rails/rails/blob/v7.2.0.beta1/actionview/CHANGELOG.md
251
+ documentation_uri: https://api.rubyonrails.org/v7.2.0.beta1/
251
252
  mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
252
- source_code_uri: https://github.com/rails/rails/tree/v7.1.3.3/actionview
253
+ source_code_uri: https://github.com/rails/rails/tree/v7.2.0.beta1/actionview
253
254
  rubygems_mfa_required: 'true'
254
255
  post_install_message:
255
256
  rdoc_options: []
@@ -259,7 +260,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
259
260
  requirements:
260
261
  - - ">="
261
262
  - !ruby/object:Gem::Version
262
- version: 2.7.0
263
+ version: 3.1.0
263
264
  required_rubygems_version: !ruby/object:Gem::Requirement
264
265
  requirements:
265
266
  - - ">="