actionview 5.2.8.1 → 6.0.0.beta2
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.
Potentially problematic release.
This version of actionview might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +121 -152
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -1
- data/lib/action_view/base.rb +107 -10
- data/lib/action_view/buffers.rb +15 -0
- data/lib/action_view/context.rb +5 -9
- data/lib/action_view/digestor.rb +8 -11
- data/lib/action_view/file_template.rb +33 -0
- data/lib/action_view/gem_version.rb +4 -4
- data/lib/action_view/helpers/asset_tag_helper.rb +7 -30
- data/lib/action_view/helpers/asset_url_helper.rb +4 -3
- data/lib/action_view/helpers/cache_helper.rb +18 -10
- data/lib/action_view/helpers/capture_helper.rb +4 -0
- data/lib/action_view/helpers/csp_helper.rb +4 -2
- data/lib/action_view/helpers/csrf_helper.rb +1 -1
- data/lib/action_view/helpers/date_helper.rb +69 -25
- data/lib/action_view/helpers/form_helper.rb +240 -8
- data/lib/action_view/helpers/form_options_helper.rb +23 -15
- data/lib/action_view/helpers/form_tag_helper.rb +9 -9
- data/lib/action_view/helpers/javascript_helper.rb +10 -11
- data/lib/action_view/helpers/number_helper.rb +5 -0
- data/lib/action_view/helpers/rendering_helper.rb +6 -4
- data/lib/action_view/helpers/sanitize_helper.rb +3 -3
- data/lib/action_view/helpers/tag_helper.rb +13 -43
- data/lib/action_view/helpers/tags/base.rb +9 -5
- data/lib/action_view/helpers/tags/color_field.rb +1 -1
- data/lib/action_view/helpers/tags/translator.rb +1 -6
- data/lib/action_view/helpers/text_helper.rb +3 -3
- data/lib/action_view/helpers/translation_helper.rb +12 -19
- data/lib/action_view/helpers/url_helper.rb +14 -14
- data/lib/action_view/helpers.rb +0 -2
- data/lib/action_view/layouts.rb +5 -5
- data/lib/action_view/log_subscriber.rb +6 -6
- data/lib/action_view/lookup_context.rb +63 -28
- data/lib/action_view/railtie.rb +23 -0
- data/lib/action_view/record_identifier.rb +2 -2
- data/lib/action_view/renderer/abstract_renderer.rb +56 -3
- data/lib/action_view/renderer/partial_renderer/collection_caching.rb +49 -10
- data/lib/action_view/renderer/partial_renderer.rb +66 -52
- data/lib/action_view/renderer/renderer.rb +16 -4
- data/lib/action_view/renderer/streaming_template_renderer.rb +4 -4
- data/lib/action_view/renderer/template_renderer.rb +18 -18
- data/lib/action_view/rendering.rb +49 -30
- data/lib/action_view/routing_url_for.rb +12 -11
- data/lib/action_view/template/handlers/builder.rb +2 -2
- data/lib/action_view/template/handlers/erb/erubi.rb +7 -3
- data/lib/action_view/template/handlers/erb.rb +17 -7
- data/lib/action_view/template/handlers/html.rb +1 -1
- data/lib/action_view/template/handlers/raw.rb +2 -2
- data/lib/action_view/template/handlers.rb +27 -1
- data/lib/action_view/template/html.rb +14 -5
- data/lib/action_view/template/inline.rb +22 -0
- data/lib/action_view/template/resolver.rb +70 -23
- data/lib/action_view/template/text.rb +5 -3
- data/lib/action_view/template.rb +75 -36
- data/lib/action_view/test_case.rb +1 -1
- data/lib/action_view/testing/resolvers.rb +7 -5
- data/lib/action_view/view_paths.rb +25 -1
- data/lib/action_view.rb +2 -2
- data/lib/assets/compiled/rails-ujs.js +39 -22
- metadata +19 -18
- data/lib/action_view/helpers/record_tag_helper.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec7748334d455691ff0946d9ffffa3e6265a87b7fb0e9f070ed7b938f9764750
|
4
|
+
data.tar.gz: 73d7bdba0ec98f9dd8224c2887d603c8860667981d96b0ef054d66c136374bf1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0282f9151c08198bb8e1e3cf3d2e2d6eccf17813c4069c0468003e2abf417ebba04cc6a6fb94ddf490900663561759adbfb74b83a7144641a274caeec33e66ec'
|
7
|
+
data.tar.gz: 499a7436942dc63ad515def9e709524fd1d87b26d0e3078ec97abf625134ccd43466dbb22501b079d4383b94bdb1dd997301582e426d179cd872266cec5a2730
|
data/CHANGELOG.md
CHANGED
@@ -1,100 +1,43 @@
|
|
1
|
-
## Rails
|
1
|
+
## Rails 6.0.0.beta2 (February 25, 2019) ##
|
2
2
|
|
3
|
-
*
|
3
|
+
* ActionView::Template.finalize_compiled_template_methods is deprecated with
|
4
|
+
no replacement.
|
4
5
|
|
6
|
+
*tenderlove*
|
5
7
|
|
6
|
-
|
8
|
+
* config.action_view.finalize_compiled_template_methods is deprecated with
|
9
|
+
no replacement.
|
7
10
|
|
8
|
-
*
|
11
|
+
*tenderlove*
|
9
12
|
|
13
|
+
* Ensure unique DOM IDs for collection inputs with float values.
|
14
|
+
Fixes #34974
|
10
15
|
|
11
|
-
|
16
|
+
*Mark Edmondson*
|
12
17
|
|
13
|
-
* Fix and add protections for XSS in `ActionView::Helpers` and `ERB::Util`.
|
14
18
|
|
15
|
-
|
16
|
-
tag helpers, following the XML specification. Rename the option
|
17
|
-
`:escape_attributes` to `:escape`, to simplify by applying the option to the
|
18
|
-
whole tag.
|
19
|
+
## Rails 6.0.0.beta1 (January 18, 2019) ##
|
19
20
|
|
20
|
-
|
21
|
+
* [Rename npm package](https://github.com/rails/rails/pull/34905) from
|
22
|
+
[`rails-ujs`](https://www.npmjs.com/package/rails-ujs) to
|
23
|
+
[`@rails/ujs`](https://www.npmjs.com/package/@rails/ujs).
|
21
24
|
|
25
|
+
*Javan Makhmali*
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
* No changes.
|
26
|
-
|
27
|
-
|
28
|
-
## Rails 5.2.6.3 (March 08, 2022) ##
|
29
|
-
|
30
|
-
* No changes.
|
31
|
-
|
32
|
-
|
33
|
-
## Rails 5.2.6.2 (February 11, 2022) ##
|
34
|
-
|
35
|
-
* No changes.
|
36
|
-
|
37
|
-
|
38
|
-
## Rails 5.2.6.1 (February 11, 2022) ##
|
39
|
-
|
40
|
-
* No changes.
|
41
|
-
|
42
|
-
|
43
|
-
## Rails 5.2.6 (May 05, 2021) ##
|
44
|
-
|
45
|
-
* No changes.
|
46
|
-
|
47
|
-
|
48
|
-
## Rails 5.2.5 (March 26, 2021) ##
|
49
|
-
|
50
|
-
* No changes.
|
51
|
-
|
52
|
-
|
53
|
-
## Rails 5.2.4.6 (May 05, 2021) ##
|
54
|
-
|
55
|
-
* No changes.
|
56
|
-
|
57
|
-
|
58
|
-
## Rails 5.2.4.5 (February 10, 2021) ##
|
59
|
-
|
60
|
-
* No changes.
|
61
|
-
|
62
|
-
|
63
|
-
## Rails 5.2.4.4 (September 09, 2020) ##
|
64
|
-
|
65
|
-
* [CVE-2020-15169] Fix potential XSS vulnerability in the `translate`/`t` helper
|
66
|
-
|
67
|
-
*Jonathan Hefner*
|
68
|
-
|
69
|
-
|
70
|
-
## Rails 5.2.4.3 (May 18, 2020) ##
|
71
|
-
|
72
|
-
* [CVE-2020-8167] Check that request is same-origin prior to including CSRF token in XHRs
|
73
|
-
|
74
|
-
|
75
|
-
## Rails 5.2.4.2 (March 19, 2020) ##
|
76
|
-
|
77
|
-
* Fix possible XSS vector in `escape_javascript` helper
|
78
|
-
|
79
|
-
CVE-2020-5267
|
80
|
-
|
81
|
-
*Aaron Patterson*
|
82
|
-
|
83
|
-
|
84
|
-
## Rails 5.2.4.1 (December 18, 2019) ##
|
85
|
-
|
86
|
-
* No changes.
|
27
|
+
* Remove deprecated `image_alt` helper.
|
87
28
|
|
29
|
+
*Rafael Mendonça França*
|
88
30
|
|
89
|
-
|
31
|
+
* Fix the need of `#protect_against_forgery?` method defined in
|
32
|
+
`ActionView::Base` subclasses. This prevents the use of forms and buttons.
|
90
33
|
|
91
|
-
*
|
92
|
-
Programmatic click events (eg. ones generated by `Rails.fire(link, "click")`) don't specify a button. These events were being incorrectly stopped by code meant to ignore scroll wheel and right clicks introduced in #34573.
|
34
|
+
*Genadi Samokovarov*
|
93
35
|
|
94
|
-
|
36
|
+
* Fix UJS permanently showing disabled text in a[data-remote][data-disable-with] elements within forms.
|
95
37
|
|
38
|
+
Fixes #33889.
|
96
39
|
|
97
|
-
|
40
|
+
*Wolfgang Hobmaier*
|
98
41
|
|
99
42
|
* Prevent non-primary mouse keys from triggering Rails UJS click handlers.
|
100
43
|
Firefox fires click events even if the click was triggered by non-primary mouse keys such as right- or scroll-wheel-clicks.
|
@@ -104,41 +47,54 @@
|
|
104
47
|
<%= link_to 'Remote', remote_path, class: 'remote', remote: true, data: { type: :json } %>
|
105
48
|
```
|
106
49
|
|
107
|
-
Fixes #34541
|
50
|
+
Fixes #34541.
|
108
51
|
|
109
52
|
*Wolfgang Hobmaier*
|
110
53
|
|
54
|
+
* Prevent `ActionView::TextHelper#word_wrap` from unexpectedly stripping white space from the _left_ side of lines.
|
111
55
|
|
112
|
-
|
56
|
+
For example, given input like this:
|
113
57
|
|
114
|
-
|
58
|
+
```
|
59
|
+
This is a paragraph with an initial indent,
|
60
|
+
followed by additional lines that are not indented,
|
61
|
+
and finally terminated with a blockquote:
|
62
|
+
"A pithy saying"
|
63
|
+
```
|
115
64
|
|
116
|
-
|
117
|
-
arbitrary files on the target server or to perform a denial of service
|
118
|
-
attack.
|
65
|
+
Calling `word_wrap` should not trim the indents on the first and last lines.
|
119
66
|
|
120
|
-
Fixes
|
121
|
-
Fixes CVE-2019-5419
|
67
|
+
Fixes #34487.
|
122
68
|
|
123
|
-
*
|
69
|
+
*Lyle Mullican*
|
124
70
|
|
71
|
+
* Add allocations to template rendering instrumentation.
|
125
72
|
|
126
|
-
|
73
|
+
Adds the allocations for template and partial rendering to the server output on render.
|
127
74
|
|
128
|
-
|
75
|
+
```
|
76
|
+
Rendered posts/_form.html.erb (Duration: 7.1ms | Allocations: 6004)
|
77
|
+
Rendered posts/new.html.erb within layouts/application (Duration: 8.3ms | Allocations: 6654)
|
78
|
+
Completed 200 OK in 858ms (Views: 848.4ms | ActiveRecord: 0.4ms | Allocations: 1539564)
|
79
|
+
```
|
129
80
|
|
81
|
+
*Eileen M. Uchitelle*, *Aaron Patterson*
|
130
82
|
|
131
|
-
|
83
|
+
* Respect the `only_path` option passed to `url_for` when the options are passed in as an array
|
132
84
|
|
133
|
-
|
85
|
+
Fixes #33237.
|
134
86
|
|
87
|
+
*Joel Ambass*
|
135
88
|
|
136
|
-
|
89
|
+
* Deprecate calling private model methods from view helpers.
|
137
90
|
|
138
|
-
|
139
|
-
to
|
91
|
+
For example, in methods like `options_from_collection_for_select`
|
92
|
+
and `collection_select` it is possible to call private methods from
|
93
|
+
the objects used.
|
140
94
|
|
141
|
-
|
95
|
+
Fixes #33546.
|
96
|
+
|
97
|
+
*Ana María Martínez Gómez*
|
142
98
|
|
143
99
|
* Fix issue with `button_to`'s `to_form_params`
|
144
100
|
|
@@ -151,97 +107,110 @@
|
|
151
107
|
|
152
108
|
*Georgi Georgiev*
|
153
109
|
|
154
|
-
*
|
155
|
-
Content Security Policy.
|
110
|
+
* Mark arrays of translations as trusted safe by using the `_html` suffix.
|
156
111
|
|
157
|
-
|
112
|
+
Example:
|
158
113
|
|
159
|
-
|
114
|
+
en:
|
115
|
+
foo_html:
|
116
|
+
- "One"
|
117
|
+
- "<strong>Two</strong>"
|
118
|
+
- "Three 👋 🙂"
|
160
119
|
|
161
|
-
*
|
162
|
-
support automatic nonce generation for Content Security Policy.
|
163
|
-
Works the same way as `javascript_tag nonce: true` does.
|
120
|
+
*Juan Broullon*
|
164
121
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
## Rails 5.2.0 (April 09, 2018) ##
|
169
|
-
|
170
|
-
* Pass the `:skip_pipeline` option in `image_submit_tag` when calling `path_to_image`.
|
122
|
+
* Add `year_format` option to date_select tag. This option makes it possible to customize year
|
123
|
+
names. Lambda should be passed to use this option.
|
171
124
|
|
172
|
-
|
125
|
+
Example:
|
173
126
|
|
174
|
-
|
127
|
+
date_select('user_birthday', '', start_year: 1998, end_year: 2000, year_format: ->year { "Heisei #{year - 1988}" })
|
175
128
|
|
176
|
-
|
129
|
+
The HTML produced:
|
177
130
|
|
178
|
-
|
179
|
-
|
180
|
-
|
131
|
+
<select id="user_birthday__1i" name="user_birthday[(1i)]">
|
132
|
+
<option value="1998">Heisei 10</option>
|
133
|
+
<option value="1999">Heisei 11</option>
|
134
|
+
<option value="2000">Heisei 12</option>
|
135
|
+
</select>
|
136
|
+
/* The rest is omitted */
|
181
137
|
|
182
|
-
*
|
138
|
+
*Koki Ryu*
|
183
139
|
|
184
|
-
*
|
140
|
+
* Fix JavaScript views rendering does not work with Firefox when using
|
141
|
+
Content Security Policy.
|
185
142
|
|
186
|
-
|
187
|
-
(different to the specified in `javascript_include_tag` and `stylesheet_link_tag`).
|
188
|
-
Additionally, this sends Early Hints if supported by browser.
|
143
|
+
Fixes #32577.
|
189
144
|
|
190
|
-
*
|
145
|
+
*Yuji Yaginuma*
|
191
146
|
|
192
|
-
*
|
147
|
+
* Add the `nonce: true` option for `javascript_include_tag` helper to
|
148
|
+
support automatic nonce generation for Content Security Policy.
|
149
|
+
Works the same way as `javascript_tag nonce: true` does.
|
193
150
|
|
194
|
-
|
195
|
-
that was enabled in `form_for`. This usually is not an good idea since labels don't work
|
196
|
-
when the input doesn't have an id and it made harder to test with Capybara.
|
151
|
+
*Yaroslav Markin*
|
197
152
|
|
198
|
-
|
199
|
-
to `false.`
|
153
|
+
* Remove `ActionView::Helpers::RecordTagHelper`.
|
200
154
|
|
201
|
-
*
|
155
|
+
*Yoshiyuki Hirano*
|
202
156
|
|
203
|
-
*
|
157
|
+
* Disable `ActionView::Template` finalizers in test environment.
|
204
158
|
|
205
|
-
|
159
|
+
Template finalization can be expensive in large view test suites.
|
160
|
+
Add a configuration option,
|
161
|
+
`action_view.finalize_compiled_template_methods`, and turn it off in
|
162
|
+
the test environment.
|
206
163
|
|
207
|
-
*
|
164
|
+
*Simon Coffey*
|
208
165
|
|
209
|
-
*
|
166
|
+
* Extract the `confirm` call in its own, overridable method in `rails_ujs`.
|
210
167
|
|
211
|
-
|
168
|
+
Example:
|
212
169
|
|
213
|
-
|
170
|
+
Rails.confirm = function(message, element) {
|
171
|
+
return (my_bootstrap_modal_confirm(message));
|
172
|
+
}
|
214
173
|
|
215
|
-
|
174
|
+
*Mathieu Mahé*
|
216
175
|
|
217
|
-
|
176
|
+
* Enable select tag helper to mark `prompt` option as `selected` and/or `disabled` for `required`
|
177
|
+
field.
|
218
178
|
|
219
|
-
|
179
|
+
Example:
|
220
180
|
|
221
|
-
|
181
|
+
select :post,
|
182
|
+
:category,
|
183
|
+
["lifestyle", "programming", "spiritual"],
|
184
|
+
{ selected: "", disabled: "", prompt: "Choose one" },
|
185
|
+
{ required: true }
|
222
186
|
|
223
|
-
|
187
|
+
Placeholder option would be selected and disabled.
|
224
188
|
|
225
|
-
|
189
|
+
The HTML produced:
|
226
190
|
|
227
|
-
|
191
|
+
<select required="required" name="post[category]" id="post_category">
|
192
|
+
<option disabled="disabled" selected="selected" value="">Choose one</option>
|
193
|
+
<option value="lifestyle">lifestyle</option>
|
194
|
+
<option value="programming">programming</option>
|
195
|
+
<option value="spiritual">spiritual</option></select>
|
228
196
|
|
229
|
-
*
|
197
|
+
*Sergey Prikhodko*
|
230
198
|
|
231
|
-
|
199
|
+
* Don't enforce UTF-8 by default.
|
232
200
|
|
233
|
-
|
201
|
+
With the disabling of TLS 1.0 by most major websites, continuing to run
|
202
|
+
IE8 or lower becomes increasingly difficult so default to not enforcing
|
203
|
+
UTF-8 encoding as it's not relevant to other browsers.
|
234
204
|
|
235
|
-
*
|
205
|
+
*Andrew White*
|
236
206
|
|
237
|
-
*
|
207
|
+
* Change translation key of `submit_tag` from `module_name_class_name` to `module_name/class_name`.
|
238
208
|
|
239
|
-
*
|
209
|
+
*Rui Onodera*
|
240
210
|
|
241
|
-
*
|
242
|
-
for bad input.
|
211
|
+
* Rails 6 requires Ruby 2.5.0 or newer.
|
243
212
|
|
244
|
-
*
|
213
|
+
*Jeremy Daer*, *Kasper Timm Hansen*
|
245
214
|
|
246
215
|
|
247
|
-
Please check [5-
|
216
|
+
Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/actionview/CHANGELOG.md) for previous changes.
|
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -13,7 +13,7 @@ The latest version of Action View can be installed with RubyGems:
|
|
13
13
|
|
14
14
|
Source code can be downloaded as part of the Rails project on GitHub:
|
15
15
|
|
16
|
-
* https://github.com/rails/rails/tree/
|
16
|
+
* https://github.com/rails/rails/tree/master/actionview
|
17
17
|
|
18
18
|
|
19
19
|
== License
|
data/lib/action_view/base.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require "active_support/core_ext/module/attr_internal"
|
4
4
|
require "active_support/core_ext/module/attribute_accessors"
|
5
5
|
require "active_support/ordered_options"
|
6
|
+
require "active_support/deprecation"
|
6
7
|
require "action_view/log_subscriber"
|
7
8
|
require "action_view/helpers"
|
8
9
|
require "action_view/context"
|
@@ -179,37 +180,133 @@ module ActionView #:nodoc:
|
|
179
180
|
def xss_safe? #:nodoc:
|
180
181
|
true
|
181
182
|
end
|
183
|
+
|
184
|
+
def with_empty_template_cache # :nodoc:
|
185
|
+
subclass = Class.new(self) {
|
186
|
+
# We can't implement these as self.class because subclasses will
|
187
|
+
# share the same template cache as superclasses, so "changed?" won't work
|
188
|
+
# correctly.
|
189
|
+
define_method(:compiled_method_container) { subclass }
|
190
|
+
define_singleton_method(:compiled_method_container) { subclass }
|
191
|
+
}
|
192
|
+
end
|
193
|
+
|
194
|
+
def changed?(other) # :nodoc:
|
195
|
+
compiled_method_container != other.compiled_method_container
|
196
|
+
end
|
182
197
|
end
|
183
198
|
|
184
|
-
|
199
|
+
attr_reader :view_renderer, :lookup_context
|
185
200
|
attr_internal :config, :assigns
|
186
201
|
|
187
|
-
delegate :lookup_context, to: :view_renderer
|
188
202
|
delegate :formats, :formats=, :locale, :locale=, :view_paths, :view_paths=, to: :lookup_context
|
189
203
|
|
190
204
|
def assign(new_assigns) # :nodoc:
|
191
205
|
@_assigns = new_assigns.each { |key, value| instance_variable_set("@#{key}", value) }
|
192
206
|
end
|
193
207
|
|
194
|
-
|
208
|
+
# :stopdoc:
|
209
|
+
|
210
|
+
def self.build_lookup_context(context)
|
211
|
+
case context
|
212
|
+
when ActionView::Renderer
|
213
|
+
context.lookup_context
|
214
|
+
when Array
|
215
|
+
ActionView::LookupContext.new(context)
|
216
|
+
when ActionView::PathSet
|
217
|
+
ActionView::LookupContext.new(context)
|
218
|
+
when nil
|
219
|
+
ActionView::LookupContext.new([])
|
220
|
+
else
|
221
|
+
raise NotImplementedError, context.class.name
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def self.empty
|
226
|
+
with_view_paths([])
|
227
|
+
end
|
228
|
+
|
229
|
+
def self.with_view_paths(view_paths, assigns = {}, controller = nil)
|
230
|
+
with_context ActionView::LookupContext.new(view_paths), assigns, controller
|
231
|
+
end
|
232
|
+
|
233
|
+
def self.with_context(context, assigns = {}, controller = nil)
|
234
|
+
new context, assigns, controller
|
235
|
+
end
|
236
|
+
|
237
|
+
NULL = Object.new
|
238
|
+
|
239
|
+
# :startdoc:
|
240
|
+
|
241
|
+
def initialize(lookup_context = nil, assigns = {}, controller = nil, formats = NULL) #:nodoc:
|
195
242
|
@_config = ActiveSupport::InheritableOptions.new
|
196
243
|
|
197
|
-
|
198
|
-
|
244
|
+
unless formats == NULL
|
245
|
+
ActiveSupport::Deprecation.warn <<~eowarn
|
246
|
+
Passing formats to ActionView::Base.new is deprecated
|
247
|
+
eowarn
|
248
|
+
end
|
249
|
+
|
250
|
+
case lookup_context
|
251
|
+
when ActionView::LookupContext
|
252
|
+
@lookup_context = lookup_context
|
199
253
|
else
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
@
|
254
|
+
ActiveSupport::Deprecation.warn <<~eowarn
|
255
|
+
ActionView::Base instances should be constructed with a lookup context,
|
256
|
+
assignments, and a controller.
|
257
|
+
eowarn
|
258
|
+
@lookup_context = self.class.build_lookup_context(lookup_context)
|
205
259
|
end
|
206
260
|
|
261
|
+
@view_renderer = ActionView::Renderer.new @lookup_context
|
262
|
+
@current_template = nil
|
263
|
+
|
207
264
|
@cache_hit = {}
|
208
265
|
assign(assigns)
|
209
266
|
assign_controller(controller)
|
210
267
|
_prepare_context
|
211
268
|
end
|
212
269
|
|
270
|
+
def run(method, template, locals, buffer, &block)
|
271
|
+
_old_output_buffer, _old_virtual_path, _old_template = @output_buffer, @virtual_path, @current_template
|
272
|
+
@current_template = template
|
273
|
+
@output_buffer = buffer
|
274
|
+
send(method, locals, buffer, &block)
|
275
|
+
ensure
|
276
|
+
@output_buffer, @virtual_path, @current_template = _old_output_buffer, _old_virtual_path, _old_template
|
277
|
+
end
|
278
|
+
|
279
|
+
def compiled_method_container
|
280
|
+
if self.class == ActionView::Base
|
281
|
+
ActiveSupport::Deprecation.warn <<~eowarn
|
282
|
+
ActionView::Base instances must implement `compiled_method_container`
|
283
|
+
or use the class method `with_empty_template_cache` for constructing
|
284
|
+
an ActionView::Base instances that has an empty cache.
|
285
|
+
eowarn
|
286
|
+
end
|
287
|
+
|
288
|
+
self.class
|
289
|
+
end
|
290
|
+
|
291
|
+
def in_rendering_context(options)
|
292
|
+
old_view_renderer = @view_renderer
|
293
|
+
old_lookup_context = @lookup_context
|
294
|
+
|
295
|
+
if !lookup_context.html_fallback_for_js && options[:formats]
|
296
|
+
formats = Array(options[:formats])
|
297
|
+
if formats == [:js]
|
298
|
+
formats << :html
|
299
|
+
end
|
300
|
+
@lookup_context = lookup_context.with_prepended_formats(formats)
|
301
|
+
@view_renderer = ActionView::Renderer.new @lookup_context
|
302
|
+
end
|
303
|
+
|
304
|
+
yield @view_renderer
|
305
|
+
ensure
|
306
|
+
@view_renderer = old_view_renderer
|
307
|
+
@lookup_context = old_lookup_context
|
308
|
+
end
|
309
|
+
|
213
310
|
ActiveSupport.run_load_hooks(:action_view, self)
|
214
311
|
end
|
215
312
|
end
|
data/lib/action_view/buffers.rb
CHANGED
@@ -3,6 +3,21 @@
|
|
3
3
|
require "active_support/core_ext/string/output_safety"
|
4
4
|
|
5
5
|
module ActionView
|
6
|
+
# Used as a buffer for views
|
7
|
+
#
|
8
|
+
# The main difference between this and ActiveSupport::SafeBuffer
|
9
|
+
# is for the methods `<<` and `safe_expr_append=` the inputs are
|
10
|
+
# checked for nil before they are assigned and `to_s` is called on
|
11
|
+
# the input. For example:
|
12
|
+
#
|
13
|
+
# obuf = ActionView::OutputBuffer.new "hello"
|
14
|
+
# obuf << 5
|
15
|
+
# puts obuf # => "hello5"
|
16
|
+
#
|
17
|
+
# sbuf = ActiveSupport::SafeBuffer.new "hello"
|
18
|
+
# sbuf << 5
|
19
|
+
# puts sbuf # => "hello\u0005"
|
20
|
+
#
|
6
21
|
class OutputBuffer < ActiveSupport::SafeBuffer #:nodoc:
|
7
22
|
def initialize(*)
|
8
23
|
super
|
data/lib/action_view/context.rb
CHANGED
@@ -1,21 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActionView
|
4
|
-
module CompiledTemplates #:nodoc:
|
5
|
-
# holds compiled template code
|
6
|
-
end
|
7
|
-
|
8
4
|
# = Action View Context
|
9
5
|
#
|
10
6
|
# Action View contexts are supplied to Action Controller to render a template.
|
11
7
|
# The default Action View context is ActionView::Base.
|
12
8
|
#
|
13
|
-
# In order to work with
|
14
|
-
# The initialization of the variables used by the context
|
15
|
-
# and @virtual_path) is responsibility of the
|
16
|
-
# (although you can call _prepare_context
|
9
|
+
# In order to work with Action Controller, a Context must just include this
|
10
|
+
# module. The initialization of the variables used by the context
|
11
|
+
# (@output_buffer, @view_flow, and @virtual_path) is responsibility of the
|
12
|
+
# object that includes this module (although you can call _prepare_context
|
13
|
+
# defined below).
|
17
14
|
module Context
|
18
|
-
include CompiledTemplates
|
19
15
|
attr_accessor :output_buffer, :view_flow
|
20
16
|
|
21
17
|
# Prepares the context by setting the appropriate instance variables.
|
data/lib/action_view/digestor.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "concurrent/map"
|
4
3
|
require "action_view/dependency_tracker"
|
5
|
-
require "monitor"
|
6
4
|
|
7
5
|
module ActionView
|
8
6
|
class Digestor
|
@@ -20,9 +18,12 @@ module ActionView
|
|
20
18
|
# * <tt>name</tt> - Template name
|
21
19
|
# * <tt>finder</tt> - An instance of <tt>ActionView::LookupContext</tt>
|
22
20
|
# * <tt>dependencies</tt> - An array of dependent views
|
23
|
-
def digest(name:, finder:, dependencies:
|
24
|
-
dependencies
|
25
|
-
|
21
|
+
def digest(name:, format:, finder:, dependencies: nil)
|
22
|
+
if dependencies.nil? || dependencies.empty?
|
23
|
+
cache_key = "#{name}.#{format}"
|
24
|
+
else
|
25
|
+
cache_key = [ name, format, dependencies ].flatten.compact.join(".")
|
26
|
+
end
|
26
27
|
|
27
28
|
# this is a correctly done double-checked locking idiom
|
28
29
|
# (Concurrent::Map's lookups have volatile semantics)
|
@@ -32,7 +33,7 @@ module ActionView
|
|
32
33
|
root = tree(name, finder, partial)
|
33
34
|
dependencies.each do |injected_dep|
|
34
35
|
root.children << Injected.new(injected_dep, nil, nil)
|
35
|
-
end
|
36
|
+
end if dependencies
|
36
37
|
finder.digest_cache[cache_key] = root.digest(finder)
|
37
38
|
end
|
38
39
|
end
|
@@ -47,8 +48,6 @@ module ActionView
|
|
47
48
|
logical_name = name.gsub(%r|/_|, "/")
|
48
49
|
|
49
50
|
if template = find_template(finder, logical_name, [], partial, [])
|
50
|
-
finder.rendered_format ||= template.formats.first
|
51
|
-
|
52
51
|
if node = seen[template.identifier] # handle cycles in the tree
|
53
52
|
node
|
54
53
|
else
|
@@ -72,9 +71,7 @@ module ActionView
|
|
72
71
|
private
|
73
72
|
def find_template(finder, name, prefixes, partial, keys)
|
74
73
|
finder.disable_cache do
|
75
|
-
|
76
|
-
result = finder.find_all(name, prefixes, partial, keys, formats: [format]).first if format
|
77
|
-
result || finder.find_all(name, prefixes, partial, keys).first
|
74
|
+
finder.find_all(name, prefixes, partial, keys).first
|
78
75
|
end
|
79
76
|
end
|
80
77
|
end
|