actionview 7.1.1 → 7.2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +108 -311
- data/README.rdoc +1 -1
- data/app/assets/javascripts/rails-ujs.esm.js +0 -7
- data/lib/action_view/base.rb +25 -11
- 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/digestor.rb +6 -2
- data/lib/action_view/gem_version.rb +3 -3
- data/lib/action_view/helpers/asset_tag_helper.rb +26 -14
- data/lib/action_view/helpers/atom_feed_helper.rb +1 -1
- data/lib/action_view/helpers/cache_helper.rb +6 -6
- data/lib/action_view/helpers/capture_helper.rb +7 -1
- data/lib/action_view/helpers/csrf_helper.rb +1 -1
- data/lib/action_view/helpers/date_helper.rb +8 -1
- data/lib/action_view/helpers/form_helper.rb +230 -221
- data/lib/action_view/helpers/form_options_helper.rb +6 -3
- data/lib/action_view/helpers/form_tag_helper.rb +86 -53
- data/lib/action_view/helpers/number_helper.rb +35 -329
- data/lib/action_view/helpers/output_safety_helper.rb +5 -6
- data/lib/action_view/helpers/sanitize_helper.rb +25 -14
- data/lib/action_view/helpers/tag_helper.rb +213 -20
- data/lib/action_view/helpers/tags/collection_helpers.rb +2 -1
- data/lib/action_view/helpers/text_helper.rb +135 -72
- data/lib/action_view/helpers/url_helper.rb +8 -80
- data/lib/action_view/layouts.rb +10 -12
- 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/collection_renderer.rb +1 -1
- data/lib/action_view/renderer/partial_renderer.rb +2 -2
- data/lib/action_view/renderer/renderer.rb +32 -38
- data/lib/action_view/renderer/template_renderer.rb +3 -3
- data/lib/action_view/rendering.rb +4 -4
- data/lib/action_view/template/error.rb +11 -0
- data/lib/action_view/template/handlers/erb.rb +45 -37
- data/lib/action_view/template/renderable.rb +7 -1
- data/lib/action_view/template/resolver.rb +0 -2
- data/lib/action_view/template.rb +68 -19
- data/lib/action_view/test_case.rb +33 -34
- data/lib/action_view/unbound_template.rb +4 -4
- data/lib/action_view.rb +2 -1
- metadata +30 -19
- data/lib/assets/compiled/rails-ujs.js +0 -777
|
@@ -27,6 +27,17 @@ module ActionView
|
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
+
class StrictLocalsError < ArgumentError # :nodoc:
|
|
31
|
+
def initialize(argument_error, template)
|
|
32
|
+
message = argument_error.message.
|
|
33
|
+
gsub("unknown keyword:", "unknown local:").
|
|
34
|
+
gsub("missing keyword:", "missing local:").
|
|
35
|
+
gsub("no keywords accepted", "no locals accepted").
|
|
36
|
+
concat(" for #{template.short_identifier}")
|
|
37
|
+
super(message)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
30
41
|
class MissingTemplate < ActionViewError # :nodoc:
|
|
31
42
|
attr_reader :path, :paths, :prefixes, :partial
|
|
32
43
|
|
|
@@ -42,7 +42,9 @@ module ActionView
|
|
|
42
42
|
# source location inside the template.
|
|
43
43
|
def translate_location(spot, backtrace_location, source)
|
|
44
44
|
# Tokenize the source line
|
|
45
|
-
|
|
45
|
+
source_lines = source.lines
|
|
46
|
+
return nil if source_lines.size < backtrace_location.lineno
|
|
47
|
+
tokens = ::ERB::Util.tokenize(source_lines[backtrace_location.lineno - 1])
|
|
46
48
|
new_first_column = find_offset(spot[:snippet], tokens, spot[:first_column])
|
|
47
49
|
lineno_delta = spot[:first_lineno] - backtrace_location.lineno
|
|
48
50
|
spot[:first_lineno] -= lineno_delta
|
|
@@ -51,7 +53,7 @@ module ActionView
|
|
|
51
53
|
column_delta = spot[:first_column] - new_first_column
|
|
52
54
|
spot[:first_column] -= column_delta
|
|
53
55
|
spot[:last_column] -= column_delta
|
|
54
|
-
spot[:script_lines] =
|
|
56
|
+
spot[:script_lines] = source_lines
|
|
55
57
|
|
|
56
58
|
spot
|
|
57
59
|
rescue NotImplementedError, LocationParsingError
|
|
@@ -105,51 +107,57 @@ module ActionView
|
|
|
105
107
|
raise WrongEncodingError.new(string, string.encoding)
|
|
106
108
|
end
|
|
107
109
|
|
|
110
|
+
# Find which token in the source template spans the byte range that
|
|
111
|
+
# contains the error_column, then return the offset compared to the
|
|
112
|
+
# original source template.
|
|
113
|
+
#
|
|
114
|
+
# Iterate consecutive pairs of CODE or TEXT tokens, requiring
|
|
115
|
+
# a match of the first token before matching either token.
|
|
116
|
+
#
|
|
117
|
+
# For example, if we want to find tokens A, B, C, we do the following:
|
|
118
|
+
# 1. Find a match for A: test error_column or advance scanner.
|
|
119
|
+
# 2. Find a match for B or A:
|
|
120
|
+
# a. If B: start over with next token set (B, C).
|
|
121
|
+
# b. If A: test error_column or advance scanner.
|
|
122
|
+
# c. Otherwise: Advance 1 byte
|
|
123
|
+
#
|
|
124
|
+
# Prioritize matching the next token over the current token once
|
|
125
|
+
# a match for the current token has been found. This is to prevent
|
|
126
|
+
# the current token from looping past the next token if they both
|
|
127
|
+
# match (i.e. if the current token is a single space character).
|
|
108
128
|
def find_offset(compiled, source_tokens, error_column)
|
|
109
129
|
compiled = StringScanner.new(compiled)
|
|
130
|
+
offset_source_tokens(source_tokens).each_cons(2) do |(name, str, offset), (_, next_str, _)|
|
|
131
|
+
matched_str = false
|
|
110
132
|
|
|
111
|
-
|
|
133
|
+
until compiled.eos?
|
|
134
|
+
if matched_str && next_str && compiled.match?(next_str)
|
|
135
|
+
break
|
|
136
|
+
elsif compiled.match?(str)
|
|
137
|
+
matched_str = true
|
|
112
138
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
when :TEXT
|
|
117
|
-
loop do
|
|
118
|
-
break if compiled.match?(str)
|
|
119
|
-
compiled.getch
|
|
120
|
-
end
|
|
121
|
-
raise LocationParsingError unless compiled.scan(str)
|
|
122
|
-
when :CODE
|
|
123
|
-
if compiled.pos > error_column
|
|
124
|
-
raise LocationParsingError, "We went too far"
|
|
125
|
-
end
|
|
139
|
+
if name == :CODE && compiled.pos <= error_column && compiled.pos + str.bytesize >= error_column
|
|
140
|
+
return error_column - compiled.pos + offset
|
|
141
|
+
end
|
|
126
142
|
|
|
127
|
-
|
|
128
|
-
offset = error_column - compiled.pos
|
|
129
|
-
return passed_tokens.map(&:last).join.bytesize + offset
|
|
143
|
+
compiled.pos += str.bytesize
|
|
130
144
|
else
|
|
131
|
-
|
|
132
|
-
raise LocationParsingError, "Couldn't find code snippet"
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
when :OPEN
|
|
136
|
-
next_tok = source_tokens.first.last
|
|
137
|
-
loop do
|
|
138
|
-
break if compiled.match?(next_tok)
|
|
139
|
-
compiled.getch
|
|
145
|
+
compiled.pos += 1
|
|
140
146
|
end
|
|
141
|
-
when :CLOSE
|
|
142
|
-
next_tok = source_tokens.first.last
|
|
143
|
-
loop do
|
|
144
|
-
break if compiled.match?(next_tok)
|
|
145
|
-
compiled.getch
|
|
146
|
-
end
|
|
147
|
-
else
|
|
148
|
-
raise LocationParsingError, "Not implemented: #{tok.first}"
|
|
149
147
|
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
raise LocationParsingError, "Couldn't find code snippet"
|
|
151
|
+
end
|
|
150
152
|
|
|
151
|
-
|
|
153
|
+
def offset_source_tokens(source_tokens)
|
|
154
|
+
source_offset = 0
|
|
155
|
+
with_offset = source_tokens.filter_map do |(name, str)|
|
|
156
|
+
result = [name, str, source_offset] if name == :CODE || name == :TEXT
|
|
157
|
+
source_offset += str.bytesize
|
|
158
|
+
result
|
|
152
159
|
end
|
|
160
|
+
with_offset << [:EOS, nil, source_offset]
|
|
153
161
|
end
|
|
154
162
|
end
|
|
155
163
|
end
|
|
@@ -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
|
|
@@ -201,6 +215,7 @@ module ActionView
|
|
|
201
215
|
@variant = variant
|
|
202
216
|
@compile_mutex = Mutex.new
|
|
203
217
|
@strict_locals = NONE
|
|
218
|
+
@strict_local_keys = nil
|
|
204
219
|
@type = nil
|
|
205
220
|
end
|
|
206
221
|
|
|
@@ -215,11 +230,21 @@ module ActionView
|
|
|
215
230
|
end
|
|
216
231
|
|
|
217
232
|
def spot(location) # :nodoc:
|
|
218
|
-
ast = RubyVM::AbstractSyntaxTree.parse(compiled_source, keep_script_lines: true)
|
|
219
233
|
node_id = RubyVM::AbstractSyntaxTree.node_id_for_backtrace_location(location)
|
|
220
|
-
|
|
234
|
+
found =
|
|
235
|
+
if RubyVM::InstructionSequence.compile("").to_a[4][:parser] == :prism
|
|
236
|
+
require "prism"
|
|
237
|
+
|
|
238
|
+
if Prism::VERSION >= "1.0.0"
|
|
239
|
+
result = Prism.parse(compiled_source).value
|
|
240
|
+
result.breadth_first_search { |node| node.node_id == node_id }
|
|
241
|
+
end
|
|
242
|
+
else
|
|
243
|
+
node = RubyVM::AbstractSyntaxTree.parse(compiled_source, keep_script_lines: true)
|
|
244
|
+
find_node_by_id(node, node_id)
|
|
245
|
+
end
|
|
221
246
|
|
|
222
|
-
ErrorHighlight.spot(
|
|
247
|
+
ErrorHighlight.spot(found) if found
|
|
223
248
|
end
|
|
224
249
|
|
|
225
250
|
# Translate an error location returned by ErrorHighlight to the correct
|
|
@@ -244,14 +269,21 @@ module ActionView
|
|
|
244
269
|
# This method is instrumented as "!render_template.action_view". Notice that
|
|
245
270
|
# we use a bang in this instrumentation because you don't want to
|
|
246
271
|
# consume this in production. This is only slow if it's being listened to.
|
|
247
|
-
def render(view, locals, buffer = nil, add_to_stack: true, &block)
|
|
272
|
+
def render(view, locals, buffer = nil, implicit_locals: [], add_to_stack: true, &block)
|
|
248
273
|
instrument_render_template do
|
|
249
274
|
compile!(view)
|
|
275
|
+
|
|
276
|
+
if strict_locals? && @strict_local_keys && !implicit_locals.empty?
|
|
277
|
+
locals_to_ignore = implicit_locals - @strict_local_keys
|
|
278
|
+
locals.except!(*locals_to_ignore)
|
|
279
|
+
end
|
|
280
|
+
|
|
250
281
|
if buffer
|
|
251
282
|
view._run(method_name, self, locals, buffer, add_to_stack: add_to_stack, has_strict_locals: strict_locals?, &block)
|
|
252
283
|
nil
|
|
253
284
|
else
|
|
254
|
-
view._run(method_name, self, locals, OutputBuffer.new, add_to_stack: add_to_stack, has_strict_locals: strict_locals?, &block)
|
|
285
|
+
result = view._run(method_name, self, locals, OutputBuffer.new, add_to_stack: add_to_stack, has_strict_locals: strict_locals?, &block)
|
|
286
|
+
result.is_a?(OutputBuffer) ? result.to_s : result
|
|
255
287
|
end
|
|
256
288
|
end
|
|
257
289
|
rescue => e
|
|
@@ -283,7 +315,7 @@ module ActionView
|
|
|
283
315
|
# the same as <tt>Encoding.default_external</tt>.
|
|
284
316
|
#
|
|
285
317
|
# The user can also specify the encoding via a comment on the first
|
|
286
|
-
# line of the template (
|
|
318
|
+
# line of the template (<tt># encoding: NAME-OF-ENCODING</tt>). This will work
|
|
287
319
|
# with any template engine, as we process out the encoding comment
|
|
288
320
|
# before passing the source on to the template engine, leaving a
|
|
289
321
|
# blank line in its stead.
|
|
@@ -416,9 +448,13 @@ module ActionView
|
|
|
416
448
|
|
|
417
449
|
method_arguments =
|
|
418
450
|
if set_strict_locals
|
|
419
|
-
|
|
451
|
+
if set_strict_locals.include?("&")
|
|
452
|
+
"local_assigns, output_buffer, #{set_strict_locals}"
|
|
453
|
+
else
|
|
454
|
+
"local_assigns, output_buffer, #{set_strict_locals}, &_"
|
|
455
|
+
end
|
|
420
456
|
else
|
|
421
|
-
"local_assigns, output_buffer"
|
|
457
|
+
"local_assigns, output_buffer, &_"
|
|
422
458
|
end
|
|
423
459
|
|
|
424
460
|
# Make sure that the resulting String to be eval'd is in the
|
|
@@ -474,23 +510,33 @@ module ActionView
|
|
|
474
510
|
|
|
475
511
|
return unless strict_locals?
|
|
476
512
|
|
|
513
|
+
parameters = mod.instance_method(method_name).parameters
|
|
514
|
+
parameters -= [[:req, :local_assigns], [:req, :output_buffer]]
|
|
515
|
+
|
|
477
516
|
# Check compiled method parameters to ensure that only kwargs
|
|
478
517
|
# were provided as strict locals, preventing `locals: (foo, *foo)` etc
|
|
479
518
|
# and allowing `locals: (foo:)`.
|
|
519
|
+
non_kwarg_parameters = parameters.select do |parameter|
|
|
520
|
+
![:keyreq, :key, :keyrest, :nokey].include?(parameter[0])
|
|
521
|
+
end
|
|
480
522
|
|
|
481
|
-
non_kwarg_parameters
|
|
482
|
-
(mod.instance_method(method_name).parameters - [[:req, :output_buffer]]).
|
|
483
|
-
select { |parameter| ![:keyreq, :key, :keyrest, :nokey].include?(parameter[0]) }
|
|
523
|
+
non_kwarg_parameters.pop if non_kwarg_parameters.last == %i(block _)
|
|
484
524
|
|
|
485
|
-
|
|
525
|
+
unless non_kwarg_parameters.empty?
|
|
526
|
+
mod.undef_method(method_name)
|
|
486
527
|
|
|
487
|
-
|
|
528
|
+
raise ArgumentError.new(
|
|
529
|
+
"#{non_kwarg_parameters.map { |_, name| "`#{name}`" }.to_sentence} set as non-keyword " \
|
|
530
|
+
"#{'argument'.pluralize(non_kwarg_parameters.length)} for #{short_identifier}. " \
|
|
531
|
+
"Locals can only be set as keyword arguments."
|
|
532
|
+
)
|
|
533
|
+
end
|
|
488
534
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
535
|
+
unless parameters.any? { |type, _| type == :keyrest }
|
|
536
|
+
parameters.map!(&:last)
|
|
537
|
+
parameters.sort!
|
|
538
|
+
@strict_local_keys = parameters.freeze
|
|
539
|
+
end
|
|
494
540
|
end
|
|
495
541
|
|
|
496
542
|
def offset
|
|
@@ -510,12 +556,15 @@ module ActionView
|
|
|
510
556
|
end
|
|
511
557
|
end
|
|
512
558
|
|
|
559
|
+
RUBY_RESERVED_KEYWORDS = ::ActiveSupport::Delegation::RUBY_RESERVED_KEYWORDS
|
|
560
|
+
private_constant :RUBY_RESERVED_KEYWORDS
|
|
561
|
+
|
|
513
562
|
def locals_code
|
|
514
563
|
return "" if strict_locals?
|
|
515
564
|
|
|
516
565
|
# Only locals with valid variable names get set directly. Others will
|
|
517
566
|
# still be available in local_assigns.
|
|
518
|
-
locals = @locals -
|
|
567
|
+
locals = @locals - RUBY_RESERVED_KEYWORDS
|
|
519
568
|
|
|
520
569
|
locals = locals.grep(/\A(?![A-Z0-9])(?:[[:alnum:]_]|[^\0-\177])+\z/)
|
|
521
570
|
|
|
@@ -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:
|
|
@@ -82,25 +82,27 @@ module ActionView
|
|
|
82
82
|
# method, where +[FORMAT]+ corresponds to the value of the
|
|
83
83
|
# +format+ argument.
|
|
84
84
|
#
|
|
85
|
-
#
|
|
85
|
+
# By default, ActionView::TestCase defines parsers for:
|
|
86
86
|
#
|
|
87
|
-
#
|
|
88
|
-
#
|
|
89
|
-
# value as its only argument.
|
|
90
|
-
# <tt>block</tt> - Block serves as the parser when the
|
|
91
|
-
# <tt>callable</tt> is omitted.
|
|
87
|
+
# * +:html+ - returns an instance of +Nokogiri::XML::Node+
|
|
88
|
+
# * +:json+ - returns an instance of ActiveSupport::HashWithIndifferentAccess
|
|
92
89
|
#
|
|
93
|
-
#
|
|
90
|
+
# These pre-registered parsers also define corresponding helpers:
|
|
94
91
|
#
|
|
95
|
-
#
|
|
96
|
-
#
|
|
92
|
+
# * +:html+ - defines +rendered.html+
|
|
93
|
+
# * +:json+ - defines +rendered.json+
|
|
97
94
|
#
|
|
98
|
-
#
|
|
95
|
+
# ==== Parameters
|
|
99
96
|
#
|
|
100
|
-
#
|
|
101
|
-
#
|
|
97
|
+
# [+format+]
|
|
98
|
+
# The name (as a +Symbol+) of the format used to render the content.
|
|
102
99
|
#
|
|
103
|
-
#
|
|
100
|
+
# [+callable+]
|
|
101
|
+
# The parser. A callable object that accepts the rendered string as
|
|
102
|
+
# its sole argument. Alternatively, the parser can be specified as a
|
|
103
|
+
# block.
|
|
104
|
+
#
|
|
105
|
+
# ==== Examples
|
|
104
106
|
#
|
|
105
107
|
# test "renders HTML" do
|
|
106
108
|
# article = Article.create!(title: "Hello, world")
|
|
@@ -118,7 +120,7 @@ module ActionView
|
|
|
118
120
|
# assert_pattern { rendered.json => { title: "Hello, world" } }
|
|
119
121
|
# end
|
|
120
122
|
#
|
|
121
|
-
# To parse the rendered content into RSS, register a call to
|
|
123
|
+
# To parse the rendered content into RSS, register a call to +RSS::Parser.parse+:
|
|
122
124
|
#
|
|
123
125
|
# register_parser :rss, -> rendered { RSS::Parser.parse(rendered) }
|
|
124
126
|
#
|
|
@@ -130,9 +132,8 @@ module ActionView
|
|
|
130
132
|
# assert_equal "Hello, world", rendered.rss.items.last.title
|
|
131
133
|
# end
|
|
132
134
|
#
|
|
133
|
-
# To parse the rendered content into a Capybara::Simple::Node
|
|
134
|
-
# re-register an
|
|
135
|
-
# <tt>Capybara.string</tt>:
|
|
135
|
+
# To parse the rendered content into a +Capybara::Simple::Node+,
|
|
136
|
+
# re-register an +:html+ parser with a call to +Capybara.string+:
|
|
136
137
|
#
|
|
137
138
|
# register_parser :html, -> rendered { Capybara.string(rendered) }
|
|
138
139
|
#
|
|
@@ -143,6 +144,7 @@ module ActionView
|
|
|
143
144
|
#
|
|
144
145
|
# rendered.html.assert_css "h1", text: "Hello, world"
|
|
145
146
|
# end
|
|
147
|
+
#
|
|
146
148
|
def register_parser(format, callable = nil, &block)
|
|
147
149
|
parser = callable || block || :itself.to_proc
|
|
148
150
|
content_class.redefine_method(format) do
|
|
@@ -169,10 +171,9 @@ module ActionView
|
|
|
169
171
|
# Almost a duplicate from ActionController::Helpers
|
|
170
172
|
methods.flatten.each do |method|
|
|
171
173
|
_helpers_for_modification.module_eval <<~end_eval, __FILE__, __LINE__ + 1
|
|
172
|
-
def #{method}(
|
|
173
|
-
_test_case.send(:'#{method}',
|
|
174
|
-
end
|
|
175
|
-
ruby2_keywords(:'#{method}')
|
|
174
|
+
def #{method}(...) # def current_user(...)
|
|
175
|
+
_test_case.send(:'#{method}', ...) # _test_case.send(:'current_user', ...)
|
|
176
|
+
end # end
|
|
176
177
|
end_eval
|
|
177
178
|
end
|
|
178
179
|
end
|
|
@@ -196,11 +197,11 @@ module ActionView
|
|
|
196
197
|
end
|
|
197
198
|
|
|
198
199
|
included do
|
|
199
|
-
class_attribute :content_class, instance_accessor: false, default:
|
|
200
|
+
class_attribute :content_class, instance_accessor: false, default: RenderedViewContent
|
|
200
201
|
|
|
201
202
|
setup :setup_with_controller
|
|
202
203
|
|
|
203
|
-
register_parser :html, -> rendered { Rails::Dom::Testing.
|
|
204
|
+
register_parser :html, -> rendered { Rails::Dom::Testing.html_document_fragment.parse(rendered) }
|
|
204
205
|
register_parser :json, -> rendered { JSON.parse(rendered, object_class: ActiveSupport::HashWithIndifferentAccess) }
|
|
205
206
|
|
|
206
207
|
ActiveSupport.run_load_hooks(:action_view_test_case, self)
|
|
@@ -222,7 +223,7 @@ module ActionView
|
|
|
222
223
|
@request = @controller.request
|
|
223
224
|
@view_flow = ActionView::OutputFlow.new
|
|
224
225
|
@output_buffer = ActionView::OutputBuffer.new
|
|
225
|
-
@rendered = +""
|
|
226
|
+
@rendered = self.class.content_class.new(+"")
|
|
226
227
|
|
|
227
228
|
test_case_instance = self
|
|
228
229
|
controller_class.define_method(:_test_case) { test_case_instance }
|
|
@@ -242,6 +243,9 @@ module ActionView
|
|
|
242
243
|
@_rendered_views ||= RenderedViewsCollection.new
|
|
243
244
|
end
|
|
244
245
|
|
|
246
|
+
##
|
|
247
|
+
# :method: rendered
|
|
248
|
+
#
|
|
245
249
|
# Returns the content rendered by the last +render+ call.
|
|
246
250
|
#
|
|
247
251
|
# The returned object behaves like a string but also exposes a number of methods
|
|
@@ -289,18 +293,14 @@ module ActionView
|
|
|
289
293
|
#
|
|
290
294
|
# assert_pattern { rendered.json => { title: "Hello, world" } }
|
|
291
295
|
# end
|
|
292
|
-
def rendered
|
|
293
|
-
@_rendered ||= self.class.content_class.new(@rendered)
|
|
294
|
-
end
|
|
295
296
|
|
|
296
297
|
def _routes
|
|
297
298
|
@controller._routes if @controller.respond_to?(:_routes)
|
|
298
299
|
end
|
|
299
300
|
|
|
300
|
-
class
|
|
301
|
+
class RenderedViewContent < String # :nodoc:
|
|
301
302
|
end
|
|
302
303
|
|
|
303
|
-
# Need to experiment if this priority is the best one: rendered => output_buffer
|
|
304
304
|
class RenderedViewsCollection
|
|
305
305
|
def initialize
|
|
306
306
|
@rendered_views ||= Hash.new { |hash, key| hash[key] = [] }
|
|
@@ -414,7 +414,7 @@ module ActionView
|
|
|
414
414
|
end]
|
|
415
415
|
end
|
|
416
416
|
|
|
417
|
-
def method_missing(selector,
|
|
417
|
+
def method_missing(selector, ...)
|
|
418
418
|
begin
|
|
419
419
|
routes = @controller.respond_to?(:_routes) && @controller._routes
|
|
420
420
|
rescue
|
|
@@ -424,16 +424,15 @@ module ActionView
|
|
|
424
424
|
if routes &&
|
|
425
425
|
(routes.named_routes.route_defined?(selector) ||
|
|
426
426
|
routes.mounted_helpers.method_defined?(selector))
|
|
427
|
-
@controller.__send__(selector,
|
|
427
|
+
@controller.__send__(selector, ...)
|
|
428
428
|
else
|
|
429
429
|
super
|
|
430
430
|
end
|
|
431
431
|
end
|
|
432
|
-
ruby2_keywords(:method_missing)
|
|
433
432
|
|
|
434
433
|
def respond_to_missing?(name, include_private = false)
|
|
435
434
|
begin
|
|
436
|
-
routes =
|
|
435
|
+
routes = @controller.respond_to?(:_routes) && @controller._routes
|
|
437
436
|
rescue
|
|
438
437
|
# Don't call routes, if there is an error on _routes call
|
|
439
438
|
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:
|
|
31
|
+
# :include: ../README.rdoc
|
|
32
32
|
module ActionView
|
|
33
33
|
extend ActiveSupport::Autoload
|
|
34
34
|
|
|
@@ -81,6 +81,7 @@ module ActionView
|
|
|
81
81
|
autoload :MissingTemplate
|
|
82
82
|
autoload :ActionViewError
|
|
83
83
|
autoload :EncodingError
|
|
84
|
+
autoload :StrictLocalsError
|
|
84
85
|
autoload :TemplateError
|
|
85
86
|
autoload :SyntaxErrorInTemplate
|
|
86
87
|
autoload :WrongEncodingError
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: actionview
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 7.
|
|
4
|
+
version: 7.2.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- David Heinemeier Hansson
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: activesupport
|
|
@@ -16,14 +15,28 @@ dependencies:
|
|
|
16
15
|
requirements:
|
|
17
16
|
- - '='
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 7.
|
|
18
|
+
version: 7.2.3.1
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
23
|
- - '='
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 7.
|
|
25
|
+
version: 7.2.3.1
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: cgi
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
27
40
|
- !ruby/object:Gem::Dependency
|
|
28
41
|
name: builder
|
|
29
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -86,28 +99,28 @@ dependencies:
|
|
|
86
99
|
requirements:
|
|
87
100
|
- - '='
|
|
88
101
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: 7.
|
|
102
|
+
version: 7.2.3.1
|
|
90
103
|
type: :development
|
|
91
104
|
prerelease: false
|
|
92
105
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
106
|
requirements:
|
|
94
107
|
- - '='
|
|
95
108
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: 7.
|
|
109
|
+
version: 7.2.3.1
|
|
97
110
|
- !ruby/object:Gem::Dependency
|
|
98
111
|
name: activemodel
|
|
99
112
|
requirement: !ruby/object:Gem::Requirement
|
|
100
113
|
requirements:
|
|
101
114
|
- - '='
|
|
102
115
|
- !ruby/object:Gem::Version
|
|
103
|
-
version: 7.
|
|
116
|
+
version: 7.2.3.1
|
|
104
117
|
type: :development
|
|
105
118
|
prerelease: false
|
|
106
119
|
version_requirements: !ruby/object:Gem::Requirement
|
|
107
120
|
requirements:
|
|
108
121
|
- - '='
|
|
109
122
|
- !ruby/object:Gem::Version
|
|
110
|
-
version: 7.
|
|
123
|
+
version: 7.2.3.1
|
|
111
124
|
description: Simple, battle-tested conventions and helpers for building web pages.
|
|
112
125
|
email: david@loudthinking.com
|
|
113
126
|
executables: []
|
|
@@ -126,7 +139,7 @@ files:
|
|
|
126
139
|
- lib/action_view/context.rb
|
|
127
140
|
- lib/action_view/dependency_tracker.rb
|
|
128
141
|
- lib/action_view/dependency_tracker/erb_tracker.rb
|
|
129
|
-
- lib/action_view/dependency_tracker/
|
|
142
|
+
- lib/action_view/dependency_tracker/ruby_tracker.rb
|
|
130
143
|
- lib/action_view/deprecator.rb
|
|
131
144
|
- lib/action_view/digestor.rb
|
|
132
145
|
- lib/action_view/flows.rb
|
|
@@ -204,6 +217,8 @@ files:
|
|
|
204
217
|
- lib/action_view/railtie.rb
|
|
205
218
|
- lib/action_view/record_identifier.rb
|
|
206
219
|
- lib/action_view/render_parser.rb
|
|
220
|
+
- lib/action_view/render_parser/prism_render_parser.rb
|
|
221
|
+
- lib/action_view/render_parser/ripper_render_parser.rb
|
|
207
222
|
- lib/action_view/renderer/abstract_renderer.rb
|
|
208
223
|
- lib/action_view/renderer/collection_renderer.rb
|
|
209
224
|
- lib/action_view/renderer/object_renderer.rb
|
|
@@ -213,7 +228,6 @@ files:
|
|
|
213
228
|
- lib/action_view/renderer/streaming_template_renderer.rb
|
|
214
229
|
- lib/action_view/renderer/template_renderer.rb
|
|
215
230
|
- lib/action_view/rendering.rb
|
|
216
|
-
- lib/action_view/ripper_ast_parser.rb
|
|
217
231
|
- lib/action_view/routing_url_for.rb
|
|
218
232
|
- lib/action_view/tasks/cache_digests.rake
|
|
219
233
|
- lib/action_view/template.rb
|
|
@@ -240,18 +254,16 @@ files:
|
|
|
240
254
|
- lib/action_view/unbound_template.rb
|
|
241
255
|
- lib/action_view/version.rb
|
|
242
256
|
- lib/action_view/view_paths.rb
|
|
243
|
-
- lib/assets/compiled/rails-ujs.js
|
|
244
257
|
homepage: https://rubyonrails.org
|
|
245
258
|
licenses:
|
|
246
259
|
- MIT
|
|
247
260
|
metadata:
|
|
248
261
|
bug_tracker_uri: https://github.com/rails/rails/issues
|
|
249
|
-
changelog_uri: https://github.com/rails/rails/blob/v7.
|
|
250
|
-
documentation_uri: https://api.rubyonrails.org/v7.
|
|
262
|
+
changelog_uri: https://github.com/rails/rails/blob/v7.2.3.1/actionview/CHANGELOG.md
|
|
263
|
+
documentation_uri: https://api.rubyonrails.org/v7.2.3.1/
|
|
251
264
|
mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
|
|
252
|
-
source_code_uri: https://github.com/rails/rails/tree/v7.
|
|
265
|
+
source_code_uri: https://github.com/rails/rails/tree/v7.2.3.1/actionview
|
|
253
266
|
rubygems_mfa_required: 'true'
|
|
254
|
-
post_install_message:
|
|
255
267
|
rdoc_options: []
|
|
256
268
|
require_paths:
|
|
257
269
|
- lib
|
|
@@ -259,7 +271,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
259
271
|
requirements:
|
|
260
272
|
- - ">="
|
|
261
273
|
- !ruby/object:Gem::Version
|
|
262
|
-
version:
|
|
274
|
+
version: 3.1.0
|
|
263
275
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
264
276
|
requirements:
|
|
265
277
|
- - ">="
|
|
@@ -267,8 +279,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
267
279
|
version: '0'
|
|
268
280
|
requirements:
|
|
269
281
|
- none
|
|
270
|
-
rubygems_version:
|
|
271
|
-
signing_key:
|
|
282
|
+
rubygems_version: 4.0.6
|
|
272
283
|
specification_version: 4
|
|
273
284
|
summary: Rendering framework putting the V in MVC (part of Rails).
|
|
274
285
|
test_files: []
|