actionview 7.0.8.1 → 7.2.2.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 +60 -425
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -1
- data/app/assets/javascripts/rails-ujs.esm.js +686 -0
- data/app/assets/javascripts/rails-ujs.js +630 -0
- data/lib/action_view/base.rb +52 -14
- data/lib/action_view/buffers.rb +106 -8
- data/lib/action_view/cache_expiry.rb +44 -41
- data/lib/action_view/context.rb +1 -1
- 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/deprecator.rb +7 -0
- data/lib/action_view/digestor.rb +1 -1
- data/lib/action_view/gem_version.rb +3 -3
- data/lib/action_view/helpers/active_model_helper.rb +1 -1
- data/lib/action_view/helpers/asset_tag_helper.rb +151 -55
- data/lib/action_view/helpers/asset_url_helper.rb +6 -5
- data/lib/action_view/helpers/atom_feed_helper.rb +5 -5
- data/lib/action_view/helpers/cache_helper.rb +7 -13
- data/lib/action_view/helpers/capture_helper.rb +30 -10
- data/lib/action_view/helpers/content_exfiltration_prevention_helper.rb +70 -0
- data/lib/action_view/helpers/controller_helper.rb +6 -0
- data/lib/action_view/helpers/csp_helper.rb +2 -2
- data/lib/action_view/helpers/csrf_helper.rb +3 -3
- data/lib/action_view/helpers/date_helper.rb +17 -19
- data/lib/action_view/helpers/debug_helper.rb +3 -3
- data/lib/action_view/helpers/form_helper.rb +248 -214
- data/lib/action_view/helpers/form_options_helper.rb +2 -1
- data/lib/action_view/helpers/form_tag_helper.rb +125 -58
- data/lib/action_view/helpers/javascript_helper.rb +1 -0
- data/lib/action_view/helpers/number_helper.rb +37 -330
- data/lib/action_view/helpers/output_safety_helper.rb +6 -6
- data/lib/action_view/helpers/rendering_helper.rb +1 -1
- data/lib/action_view/helpers/sanitize_helper.rb +51 -21
- data/lib/action_view/helpers/tag_helper.rb +210 -42
- data/lib/action_view/helpers/tags/base.rb +11 -52
- data/lib/action_view/helpers/tags/collection_check_boxes.rb +1 -0
- data/lib/action_view/helpers/tags/collection_radio_buttons.rb +1 -0
- data/lib/action_view/helpers/tags/collection_select.rb +3 -0
- data/lib/action_view/helpers/tags/date_field.rb +1 -1
- data/lib/action_view/helpers/tags/date_select.rb +2 -0
- data/lib/action_view/helpers/tags/datetime_field.rb +14 -6
- data/lib/action_view/helpers/tags/datetime_local_field.rb +11 -2
- data/lib/action_view/helpers/tags/grouped_collection_select.rb +3 -0
- data/lib/action_view/helpers/tags/month_field.rb +1 -1
- data/lib/action_view/helpers/tags/select.rb +3 -0
- data/lib/action_view/helpers/tags/select_renderer.rb +56 -0
- data/lib/action_view/helpers/tags/time_field.rb +1 -1
- data/lib/action_view/helpers/tags/time_zone_select.rb +3 -0
- data/lib/action_view/helpers/tags/week_field.rb +1 -1
- data/lib/action_view/helpers/tags/weekday_select.rb +3 -0
- data/lib/action_view/helpers/tags.rb +2 -0
- data/lib/action_view/helpers/text_helper.rb +157 -85
- data/lib/action_view/helpers/translation_helper.rb +3 -3
- data/lib/action_view/helpers/url_helper.rb +35 -80
- data/lib/action_view/helpers.rb +2 -0
- data/lib/action_view/layouts.rb +8 -8
- data/lib/action_view/log_subscriber.rb +57 -36
- data/lib/action_view/lookup_context.rb +29 -13
- data/lib/action_view/path_registry.rb +57 -0
- data/lib/action_view/path_set.rb +13 -14
- data/lib/action_view/railtie.rb +25 -3
- data/lib/action_view/record_identifier.rb +15 -8
- data/lib/action_view/render_parser/prism_render_parser.rb +127 -0
- data/lib/action_view/render_parser/ripper_render_parser.rb +341 -0
- data/lib/action_view/render_parser.rb +21 -169
- data/lib/action_view/renderer/abstract_renderer.rb +2 -2
- data/lib/action_view/renderer/collection_renderer.rb +10 -2
- data/lib/action_view/renderer/partial_renderer/collection_caching.rb +2 -1
- data/lib/action_view/renderer/partial_renderer.rb +2 -1
- data/lib/action_view/renderer/renderer.rb +34 -38
- data/lib/action_view/renderer/streaming_template_renderer.rb +3 -2
- data/lib/action_view/renderer/template_renderer.rb +3 -2
- data/lib/action_view/rendering.rb +26 -8
- data/lib/action_view/template/error.rb +14 -1
- data/lib/action_view/template/handlers/builder.rb +4 -4
- data/lib/action_view/template/handlers/erb/erubi.rb +23 -27
- data/lib/action_view/template/handlers/erb.rb +73 -1
- data/lib/action_view/template/handlers.rb +1 -1
- data/lib/action_view/template/html.rb +1 -1
- data/lib/action_view/template/raw_file.rb +1 -1
- data/lib/action_view/template/renderable.rb +8 -2
- data/lib/action_view/template/resolver.rb +9 -3
- data/lib/action_view/template/text.rb +1 -1
- data/lib/action_view/template/types.rb +25 -34
- data/lib/action_view/template.rb +278 -55
- data/lib/action_view/template_path.rb +2 -0
- data/lib/action_view/test_case.rb +181 -28
- data/lib/action_view/unbound_template.rb +17 -7
- data/lib/action_view/version.rb +1 -1
- data/lib/action_view/view_paths.rb +15 -24
- data/lib/action_view.rb +4 -1
- metadata +31 -31
- data/lib/action_view/ripper_ast_parser.rb +0 -198
- data/lib/assets/compiled/rails-ujs.js +0 -777
@@ -1,176 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "action_view/ripper_ast_parser"
|
4
|
-
|
5
3
|
module ActionView
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@code = code
|
10
|
-
@parser = RipperASTParser
|
11
|
-
end
|
12
|
-
|
13
|
-
def render_calls
|
14
|
-
render_nodes = @parser.parse_render_nodes(@code)
|
15
|
-
|
16
|
-
render_nodes.map do |method, nodes|
|
17
|
-
nodes.map { |n| send(:parse_render, n) }
|
18
|
-
end.flatten.compact
|
19
|
-
end
|
4
|
+
module RenderParser # :nodoc:
|
5
|
+
ALL_KNOWN_KEYS = [:partial, :template, :layout, :formats, :locals, :object, :collection, :as, :status, :content_type, :location, :spacer_template]
|
6
|
+
RENDER_TYPE_KEYS = [:partial, :template, :layout]
|
20
7
|
|
21
|
-
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
def resolve_path_directory(path)
|
27
|
-
if path.include?("/")
|
28
|
-
path
|
29
|
-
else
|
30
|
-
"#{directory}/#{path}"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# Convert
|
35
|
-
# render("foo", ...)
|
36
|
-
# into either
|
37
|
-
# render(template: "foo", ...)
|
38
|
-
# or
|
39
|
-
# render(partial: "foo", ...)
|
40
|
-
def normalize_args(string, options_hash)
|
41
|
-
if options_hash
|
42
|
-
{ partial: string, locals: options_hash }
|
43
|
-
else
|
44
|
-
{ partial: string }
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def parse_render(node)
|
49
|
-
node = node.argument_nodes
|
50
|
-
|
51
|
-
if (node.length == 1 || node.length == 2) && !node[0].hash?
|
52
|
-
if node.length == 1
|
53
|
-
options = normalize_args(node[0], nil)
|
54
|
-
elsif node.length == 2
|
55
|
-
options = normalize_args(node[0], node[1])
|
56
|
-
end
|
57
|
-
|
58
|
-
return nil unless options
|
59
|
-
|
60
|
-
parse_render_from_options(options)
|
61
|
-
elsif node.length == 1 && node[0].hash?
|
62
|
-
options = parse_hash_to_symbols(node[0])
|
63
|
-
|
64
|
-
return nil unless options
|
65
|
-
|
66
|
-
parse_render_from_options(options)
|
67
|
-
else
|
68
|
-
nil
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def parse_hash(node)
|
73
|
-
node.hash? && node.to_hash
|
74
|
-
end
|
75
|
-
|
76
|
-
def parse_hash_to_symbols(node)
|
77
|
-
hash = parse_hash(node)
|
78
|
-
|
79
|
-
return unless hash
|
80
|
-
|
81
|
-
hash.transform_keys do |key_node|
|
82
|
-
key = parse_sym(key_node)
|
83
|
-
|
84
|
-
return unless key
|
85
|
-
|
86
|
-
key
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
ALL_KNOWN_KEYS = [:partial, :template, :layout, :formats, :locals, :object, :collection, :as, :status, :content_type, :location, :spacer_template]
|
91
|
-
|
92
|
-
RENDER_TYPE_KEYS =
|
93
|
-
[:partial, :template, :layout]
|
94
|
-
|
95
|
-
def parse_render_from_options(options_hash)
|
96
|
-
renders = []
|
97
|
-
keys = options_hash.keys
|
98
|
-
|
99
|
-
if (keys & RENDER_TYPE_KEYS).size < 1
|
100
|
-
# Must have at least one of render keys
|
101
|
-
return nil
|
102
|
-
end
|
103
|
-
|
104
|
-
if (keys - ALL_KNOWN_KEYS).any?
|
105
|
-
# de-opt in case of unknown option
|
106
|
-
return nil
|
107
|
-
end
|
108
|
-
|
109
|
-
render_type = (keys & RENDER_TYPE_KEYS)[0]
|
110
|
-
|
111
|
-
node = options_hash[render_type]
|
112
|
-
|
113
|
-
if node.string?
|
114
|
-
template = resolve_path_directory(node.to_string)
|
115
|
-
else
|
116
|
-
if node.variable_reference?
|
117
|
-
dependency = node.variable_name.sub(/\A(?:\$|@{1,2})/, "")
|
118
|
-
elsif node.vcall?
|
119
|
-
dependency = node.variable_name
|
120
|
-
elsif node.call?
|
121
|
-
dependency = node.call_method_name
|
122
|
-
else
|
123
|
-
return
|
124
|
-
end
|
125
|
-
|
126
|
-
object_template = true
|
127
|
-
template = "#{dependency.pluralize}/#{dependency.singularize}"
|
128
|
-
end
|
129
|
-
|
130
|
-
return unless template
|
131
|
-
|
132
|
-
if spacer_template = render_template_with_spacer?(options_hash)
|
133
|
-
virtual_path = partial_to_virtual_path(:partial, spacer_template)
|
134
|
-
renders << virtual_path
|
135
|
-
end
|
136
|
-
|
137
|
-
if options_hash.key?(:object) || options_hash.key?(:collection) || object_template
|
138
|
-
return nil if options_hash.key?(:object) && options_hash.key?(:collection)
|
139
|
-
return nil unless options_hash.key?(:partial)
|
140
|
-
end
|
141
|
-
|
142
|
-
virtual_path = partial_to_virtual_path(render_type, template)
|
143
|
-
renders << virtual_path
|
144
|
-
|
145
|
-
# Support for rendering multiple templates (i.e. a partial with a layout)
|
146
|
-
if layout_template = render_template_with_layout?(render_type, options_hash)
|
147
|
-
virtual_path = partial_to_virtual_path(:layout, layout_template)
|
148
|
-
|
149
|
-
renders << virtual_path
|
150
|
-
end
|
151
|
-
|
152
|
-
renders
|
153
|
-
end
|
154
|
-
|
155
|
-
def parse_str(node)
|
156
|
-
node.string? && node.to_string
|
157
|
-
end
|
158
|
-
|
159
|
-
def parse_sym(node)
|
160
|
-
node.symbol? && node.to_symbol
|
8
|
+
class Base # :nodoc:
|
9
|
+
def initialize(name, code)
|
10
|
+
@name = name
|
11
|
+
@code = code
|
161
12
|
end
|
162
13
|
|
163
14
|
private
|
164
|
-
def
|
165
|
-
|
166
|
-
parse_str(options_hash[:layout])
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
def render_template_with_spacer?(options_hash)
|
171
|
-
if options_hash.key?(:spacer_template)
|
172
|
-
parse_str(options_hash[:spacer_template])
|
173
|
-
end
|
15
|
+
def directory
|
16
|
+
File.dirname(@name)
|
174
17
|
end
|
175
18
|
|
176
19
|
def partial_to_virtual_path(render_type, partial_path)
|
@@ -180,9 +23,18 @@ module ActionView
|
|
180
23
|
partial_path
|
181
24
|
end
|
182
25
|
end
|
26
|
+
end
|
183
27
|
|
184
|
-
|
185
|
-
|
186
|
-
|
28
|
+
# Check if prism is available. If it is, use it. Otherwise, use ripper.
|
29
|
+
begin
|
30
|
+
require "prism"
|
31
|
+
rescue LoadError
|
32
|
+
require "ripper"
|
33
|
+
require_relative "render_parser/ripper_render_parser"
|
34
|
+
Default = RipperRenderParser
|
35
|
+
else
|
36
|
+
require_relative "render_parser/prism_render_parser"
|
37
|
+
Default = PrismRenderParser
|
38
|
+
end
|
187
39
|
end
|
188
40
|
end
|
@@ -31,7 +31,7 @@ module ActionView
|
|
31
31
|
|
32
32
|
module ObjectRendering # :nodoc:
|
33
33
|
PREFIXED_PARTIAL_NAMES = Concurrent::Map.new do |h, k|
|
34
|
-
h
|
34
|
+
h.compute_if_absent(k) { Concurrent::Map.new }
|
35
35
|
end
|
36
36
|
|
37
37
|
def initialize(lookup_context, options)
|
@@ -79,7 +79,7 @@ module ActionView
|
|
79
79
|
path = if object.respond_to?(:to_partial_path)
|
80
80
|
object.to_partial_path
|
81
81
|
else
|
82
|
-
raise ArgumentError.new("'#{object.inspect}' is not an ActiveModel-compatible object. It must implement
|
82
|
+
raise ArgumentError.new("'#{object.inspect}' is not an ActiveModel-compatible object. It must implement #to_partial_path.")
|
83
83
|
end
|
84
84
|
|
85
85
|
if view.prefix_partial_path_with_controller_namespace
|
@@ -51,6 +51,10 @@ module ActionView
|
|
51
51
|
def length
|
52
52
|
@collection.respond_to?(:length) ? @collection.length : size
|
53
53
|
end
|
54
|
+
|
55
|
+
def preload!
|
56
|
+
# no-op
|
57
|
+
end
|
54
58
|
end
|
55
59
|
|
56
60
|
class SameCollectionIterator < CollectionIterator # :nodoc:
|
@@ -84,9 +88,13 @@ module ActionView
|
|
84
88
|
|
85
89
|
def each_with_info
|
86
90
|
return super unless block_given?
|
87
|
-
|
91
|
+
preload!
|
88
92
|
super
|
89
93
|
end
|
94
|
+
|
95
|
+
def preload!
|
96
|
+
@relation.preload_associations(@collection)
|
97
|
+
end
|
90
98
|
end
|
91
99
|
|
92
100
|
class MixedCollectionIterator < CollectionIterator # :nodoc:
|
@@ -186,7 +194,7 @@ module ActionView
|
|
186
194
|
|
187
195
|
_template = (cache[path] ||= (template || find_template(path, @locals.keys + [as, counter, iteration])))
|
188
196
|
|
189
|
-
content = _template.render(view, locals)
|
197
|
+
content = _template.render(view, locals, implicit_locals: [counter, iteration])
|
190
198
|
content = layout.render(view, locals) { content } if layout
|
191
199
|
partial_iteration.iterate!
|
192
200
|
build_rendered_template(content, _template)
|
@@ -59,6 +59,7 @@ module ActionView
|
|
59
59
|
seed = callable_cache_key? ? @options[:cached] : ->(i) { i }
|
60
60
|
|
61
61
|
digest_path = view.digest_path_from_template(template)
|
62
|
+
collection.preload! if callable_cache_key?
|
62
63
|
|
63
64
|
collection.each_with_object([{}, []]) do |item, (hash, ordered_keys)|
|
64
65
|
key = expanded_cache_key(seed.call(item), view, template, digest_path)
|
@@ -100,7 +101,7 @@ module ActionView
|
|
100
101
|
# We want to cache buffers as raw strings. This both improve performance and
|
101
102
|
# avoid creating forward compatibility issues with the internal representation
|
102
103
|
# of these two types.
|
103
|
-
if body.is_a?(ActiveSupport::SafeBuffer)
|
104
|
+
if body.is_a?(ActionView::OutputBuffer) || body.is_a?(ActiveSupport::SafeBuffer)
|
104
105
|
body = body.to_str
|
105
106
|
end
|
106
107
|
|
@@ -246,7 +246,8 @@ module ActionView
|
|
246
246
|
ActiveSupport::Notifications.instrument(
|
247
247
|
"render_partial.action_view",
|
248
248
|
identifier: template.identifier,
|
249
|
-
layout: layout && layout.virtual_path
|
249
|
+
layout: layout && layout.virtual_path,
|
250
|
+
locals: locals
|
250
251
|
) do |payload|
|
251
252
|
content = template.render(view, locals, add_to_stack: !block) do |*name|
|
252
253
|
view._layout_for(*name, &block)
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActionView
|
4
|
+
# = Action View \Renderer
|
5
|
+
#
|
4
6
|
# This is the main entry point for rendering. It basically delegates
|
5
7
|
# to other objects like TemplateRenderer and PartialRenderer which
|
6
8
|
# actually renders the template.
|
@@ -43,12 +45,6 @@ module ActionView
|
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
46
|
-
# Direct access to template rendering.
|
47
|
-
def render_template(context, options) # :nodoc:
|
48
|
-
render_template_to_object(context, options).body
|
49
|
-
end
|
50
|
-
|
51
|
-
# Direct access to partial rendering.
|
52
48
|
def render_partial(context, options, &block) # :nodoc:
|
53
49
|
render_partial_to_object(context, options, &block).body
|
54
50
|
end
|
@@ -57,46 +53,46 @@ module ActionView
|
|
57
53
|
@cache_hits ||= {}
|
58
54
|
end
|
59
55
|
|
60
|
-
|
61
|
-
|
62
|
-
|
56
|
+
private
|
57
|
+
def render_template_to_object(context, options)
|
58
|
+
TemplateRenderer.new(@lookup_context).render(context, options)
|
59
|
+
end
|
63
60
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
61
|
+
def render_partial_to_object(context, options, &block)
|
62
|
+
partial = options[:partial]
|
63
|
+
if String === partial
|
64
|
+
collection = collection_from_options(options)
|
68
65
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
else
|
74
|
-
if options.key?(:object)
|
75
|
-
# Object + Partial
|
76
|
-
renderer = ObjectRenderer.new(@lookup_context, options)
|
77
|
-
renderer.render_object_with_partial(options[:object], partial, context, block)
|
66
|
+
if collection
|
67
|
+
# Collection + Partial
|
68
|
+
renderer = CollectionRenderer.new(@lookup_context, options)
|
69
|
+
renderer.render_collection_with_partial(collection, partial, context, block)
|
78
70
|
else
|
79
|
-
|
80
|
-
|
81
|
-
|
71
|
+
if options.key?(:object)
|
72
|
+
# Object + Partial
|
73
|
+
renderer = ObjectRenderer.new(@lookup_context, options)
|
74
|
+
renderer.render_object_with_partial(options[:object], partial, context, block)
|
75
|
+
else
|
76
|
+
# Partial
|
77
|
+
renderer = PartialRenderer.new(@lookup_context, options)
|
78
|
+
renderer.render(partial, context, block)
|
79
|
+
end
|
82
80
|
end
|
83
|
-
end
|
84
|
-
else
|
85
|
-
collection = collection_from_object(partial) || collection_from_options(options)
|
86
|
-
|
87
|
-
if collection
|
88
|
-
# Collection + Derived Partial
|
89
|
-
renderer = CollectionRenderer.new(@lookup_context, options)
|
90
|
-
renderer.render_collection_derive_partial(collection, context, block)
|
91
81
|
else
|
92
|
-
|
93
|
-
|
94
|
-
|
82
|
+
collection = collection_from_object(partial) || collection_from_options(options)
|
83
|
+
|
84
|
+
if collection
|
85
|
+
# Collection + Derived Partial
|
86
|
+
renderer = CollectionRenderer.new(@lookup_context, options)
|
87
|
+
renderer.render_collection_derive_partial(collection, context, block)
|
88
|
+
else
|
89
|
+
# Object + Derived Partial
|
90
|
+
renderer = ObjectRenderer.new(@lookup_context, options)
|
91
|
+
renderer.render_object_derive_partial(partial, context, block)
|
92
|
+
end
|
95
93
|
end
|
96
94
|
end
|
97
|
-
end
|
98
95
|
|
99
|
-
private
|
100
96
|
def collection_from_options(options)
|
101
97
|
if options.key?(:collection)
|
102
98
|
collection = options[:collection]
|
@@ -46,7 +46,7 @@ module ActionView
|
|
46
46
|
return [super.body] unless layout_name && template.supports_streaming?
|
47
47
|
|
48
48
|
locals ||= {}
|
49
|
-
layout =
|
49
|
+
layout = find_layout(layout_name, locals.keys, [formats.first])
|
50
50
|
|
51
51
|
Body.new do |buffer|
|
52
52
|
delayed_render(buffer, template, layout, view, locals)
|
@@ -65,7 +65,8 @@ module ActionView
|
|
65
65
|
ActiveSupport::Notifications.instrument(
|
66
66
|
"render_template.action_view",
|
67
67
|
identifier: template.identifier,
|
68
|
-
layout: layout && layout.virtual_path
|
68
|
+
layout: layout && layout.virtual_path,
|
69
|
+
locals: locals
|
69
70
|
) do
|
70
71
|
outer_config = I18n.config
|
71
72
|
fiber = Fiber.new do
|
@@ -49,7 +49,7 @@ module ActionView
|
|
49
49
|
@lookup_context.find_template(options[:template], options[:prefixes], false, keys, @details)
|
50
50
|
end
|
51
51
|
else
|
52
|
-
raise ArgumentError, "You invoked render but did not give any of :
|
52
|
+
raise ArgumentError, "You invoked render but did not give any of :body, :file, :html, :inline, :partial, :plain, :renderable, or :template option."
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
@@ -60,7 +60,8 @@ module ActionView
|
|
60
60
|
ActiveSupport::Notifications.instrument(
|
61
61
|
"render_template.action_view",
|
62
62
|
identifier: template.identifier,
|
63
|
-
layout: layout && layout.virtual_path
|
63
|
+
layout: layout && layout.virtual_path,
|
64
|
+
locals: locals
|
64
65
|
) do
|
65
66
|
template.render(view, locals) { |*name| view._layout_for(*name) }
|
66
67
|
end
|
@@ -10,7 +10,8 @@ module ActionView
|
|
10
10
|
|
11
11
|
def initialize(original_config, lookup_context)
|
12
12
|
original_config = original_config.original_config if original_config.respond_to?(:original_config)
|
13
|
-
@original_config
|
13
|
+
@original_config = original_config
|
14
|
+
@lookup_context = lookup_context
|
14
15
|
end
|
15
16
|
|
16
17
|
def locale
|
@@ -26,10 +27,10 @@ module ActionView
|
|
26
27
|
extend ActiveSupport::Concern
|
27
28
|
include ActionView::ViewPaths
|
28
29
|
|
29
|
-
|
30
|
+
attr_internal_reader :rendered_format
|
30
31
|
|
31
32
|
def initialize
|
32
|
-
@
|
33
|
+
@_rendered_format = nil
|
33
34
|
super
|
34
35
|
end
|
35
36
|
|
@@ -48,7 +49,18 @@ module ActionView
|
|
48
49
|
def _helpers
|
49
50
|
end
|
50
51
|
|
52
|
+
def inherit_view_context_class?
|
53
|
+
superclass.respond_to?(:view_context_class) &&
|
54
|
+
supports_path? == superclass.supports_path? &&
|
55
|
+
_routes.equal?(superclass._routes) &&
|
56
|
+
_helpers.equal?(superclass._helpers)
|
57
|
+
end
|
58
|
+
|
51
59
|
def build_view_context_class(klass, supports_path, routes, helpers)
|
60
|
+
if inherit_view_context_class?
|
61
|
+
return superclass.view_context_class
|
62
|
+
end
|
63
|
+
|
52
64
|
Class.new(klass) do
|
53
65
|
if routes
|
54
66
|
include routes.url_helpers(supports_path)
|
@@ -61,8 +73,14 @@ module ActionView
|
|
61
73
|
end
|
62
74
|
end
|
63
75
|
|
76
|
+
def eager_load!
|
77
|
+
super
|
78
|
+
view_context_class
|
79
|
+
nil
|
80
|
+
end
|
81
|
+
|
64
82
|
def view_context_class
|
65
|
-
klass = ActionView::LookupContext::DetailsKey.view_context_class
|
83
|
+
klass = ActionView::LookupContext::DetailsKey.view_context_class
|
66
84
|
|
67
85
|
@view_context_class ||= build_view_context_class(klass, supports_path?, _routes, _helpers)
|
68
86
|
|
@@ -118,7 +136,7 @@ module ActionView
|
|
118
136
|
end
|
119
137
|
|
120
138
|
rendered_format = rendered_template.format || lookup_context.formats.first
|
121
|
-
@
|
139
|
+
@_rendered_format = Template::Types[rendered_format]
|
122
140
|
|
123
141
|
rendered_template.body
|
124
142
|
end
|
@@ -129,8 +147,8 @@ module ActionView
|
|
129
147
|
lookup_context.formats = [format.to_sym] if format.to_sym
|
130
148
|
end
|
131
149
|
|
132
|
-
# Normalize args by converting render "foo" to render :
|
133
|
-
# render "foo/bar" to render :
|
150
|
+
# Normalize args by converting render "foo" to render action: "foo" and
|
151
|
+
# render "foo/bar" to render template: "foo/bar".
|
134
152
|
def _normalize_args(action = nil, options = {})
|
135
153
|
options = super(action, options)
|
136
154
|
case action
|
@@ -161,7 +179,7 @@ module ActionView
|
|
161
179
|
options[:partial] = action_name
|
162
180
|
end
|
163
181
|
|
164
|
-
if
|
182
|
+
if !options.keys.intersect?([:partial, :file, :template])
|
165
183
|
options[:prefixes] ||= _prefixes
|
166
184
|
end
|
167
185
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "active_support/core_ext/enumerable"
|
4
|
+
require "active_support/syntax_error_proxy"
|
4
5
|
|
5
6
|
module ActionView
|
6
7
|
# = Action View Errors
|
@@ -156,13 +157,25 @@ module ActionView
|
|
156
157
|
# Override to prevent #cause resetting during re-raise.
|
157
158
|
attr_reader :cause
|
158
159
|
|
160
|
+
attr_reader :template
|
161
|
+
|
159
162
|
def initialize(template)
|
160
163
|
super($!.message)
|
161
|
-
set_backtrace($!.backtrace)
|
162
164
|
@cause = $!
|
165
|
+
if @cause.is_a?(SyntaxError)
|
166
|
+
@cause = ActiveSupport::SyntaxErrorProxy.new(@cause)
|
167
|
+
end
|
163
168
|
@template, @sub_templates = template, nil
|
164
169
|
end
|
165
170
|
|
171
|
+
def backtrace
|
172
|
+
@cause.backtrace
|
173
|
+
end
|
174
|
+
|
175
|
+
def backtrace_locations
|
176
|
+
@cause.backtrace_locations
|
177
|
+
end
|
178
|
+
|
166
179
|
def file_name
|
167
180
|
@template.identifier
|
168
181
|
end
|
@@ -7,10 +7,10 @@ module ActionView
|
|
7
7
|
|
8
8
|
def call(template, source)
|
9
9
|
require_engine
|
10
|
-
|
11
|
-
|
12
|
-
source
|
13
|
-
"
|
10
|
+
# the double assignment is to silence "assigned but unused variable" warnings
|
11
|
+
"xml = xml = ::Builder::XmlMarkup.new(indent: 2, target: output_buffer.raw);" \
|
12
|
+
"#{source};" \
|
13
|
+
"output_buffer.to_s"
|
14
14
|
end
|
15
15
|
|
16
16
|
private
|
@@ -16,22 +16,16 @@ module ActionView
|
|
16
16
|
|
17
17
|
properties[:bufvar] ||= "@output_buffer"
|
18
18
|
properties[:preamble] ||= ""
|
19
|
-
properties[:postamble] ||= "#{properties[:bufvar]}
|
19
|
+
properties[:postamble] ||= "#{properties[:bufvar]}"
|
20
|
+
|
21
|
+
# Tell Eruby that whether template will be compiled with `frozen_string_literal: true`
|
22
|
+
properties[:freeze_template_literals] = !Template.frozen_string_literal
|
20
23
|
|
21
24
|
properties[:escapefunc] = ""
|
22
25
|
|
23
26
|
super
|
24
27
|
end
|
25
28
|
|
26
|
-
def evaluate(action_view_erb_handler_context)
|
27
|
-
src = @src
|
28
|
-
view = Class.new(ActionView::Base) {
|
29
|
-
include action_view_erb_handler_context._routes.url_helpers
|
30
|
-
class_eval("define_method(:_template) { |local_assigns, output_buffer| #{src} }", defined?(@filename) ? @filename : "(erubi)", 0)
|
31
|
-
}.empty
|
32
|
-
view._run(:_template, nil, {}, ActionView::OutputBuffer.new)
|
33
|
-
end
|
34
|
-
|
35
29
|
private
|
36
30
|
def add_text(text)
|
37
31
|
return if text.empty?
|
@@ -39,30 +33,32 @@ module ActionView
|
|
39
33
|
if text == "\n"
|
40
34
|
@newline_pending += 1
|
41
35
|
else
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
36
|
+
with_buffer do
|
37
|
+
src << ".safe_append='"
|
38
|
+
src << "\n" * @newline_pending if @newline_pending > 0
|
39
|
+
src << text.gsub(/['\\]/, '\\\\\&') << @text_end
|
40
|
+
end
|
47
41
|
@newline_pending = 0
|
48
42
|
end
|
49
43
|
end
|
50
44
|
|
51
|
-
BLOCK_EXPR =
|
45
|
+
BLOCK_EXPR = /((\s|\))do|\{)(\s*\|[^|]*\|)?\s*\Z/
|
52
46
|
|
53
47
|
def add_expression(indicator, code)
|
54
48
|
flush_newline_if_pending(src)
|
55
49
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
50
|
+
with_buffer do
|
51
|
+
if (indicator == "==") || @escape
|
52
|
+
src << ".safe_expr_append="
|
53
|
+
else
|
54
|
+
src << ".append="
|
55
|
+
end
|
56
|
+
|
57
|
+
if BLOCK_EXPR.match?(code)
|
58
|
+
src << " " << code
|
59
|
+
else
|
60
|
+
src << "(" << code << ")"
|
61
|
+
end
|
66
62
|
end
|
67
63
|
end
|
68
64
|
|
@@ -78,7 +74,7 @@ module ActionView
|
|
78
74
|
|
79
75
|
def flush_newline_if_pending(src)
|
80
76
|
if @newline_pending > 0
|
81
|
-
|
77
|
+
with_buffer { src << ".safe_append='#{"\n" * @newline_pending}" << @text_end }
|
82
78
|
@newline_pending = 0
|
83
79
|
end
|
84
80
|
end
|