actionview 6.0.0.beta1 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionview might be problematic. Click here for more details.

Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +206 -119
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +4 -2
  5. data/lib/action_view/base.rb +81 -15
  6. data/lib/action_view/cache_expiry.rb +52 -0
  7. data/lib/action_view/context.rb +0 -6
  8. data/lib/action_view/dependency_tracker.rb +10 -4
  9. data/lib/action_view/digestor.rb +11 -19
  10. data/lib/action_view/flows.rb +0 -1
  11. data/lib/action_view/gem_version.rb +2 -2
  12. data/lib/action_view/helpers/active_model_helper.rb +0 -1
  13. data/lib/action_view/helpers/asset_tag_helper.rb +46 -21
  14. data/lib/action_view/helpers/asset_url_helper.rb +6 -4
  15. data/lib/action_view/helpers/atom_feed_helper.rb +2 -1
  16. data/lib/action_view/helpers/cache_helper.rb +16 -23
  17. data/lib/action_view/helpers/csp_helper.rb +4 -2
  18. data/lib/action_view/helpers/date_helper.rb +5 -6
  19. data/lib/action_view/helpers/form_helper.rb +63 -21
  20. data/lib/action_view/helpers/form_options_helper.rb +10 -18
  21. data/lib/action_view/helpers/form_tag_helper.rb +12 -9
  22. data/lib/action_view/helpers/javascript_helper.rb +7 -5
  23. data/lib/action_view/helpers/number_helper.rb +9 -8
  24. data/lib/action_view/helpers/output_safety_helper.rb +1 -1
  25. data/lib/action_view/helpers/rendering_helper.rb +17 -7
  26. data/lib/action_view/helpers/sanitize_helper.rb +10 -16
  27. data/lib/action_view/helpers/tag_helper.rb +94 -19
  28. data/lib/action_view/helpers/tags/base.rb +10 -7
  29. data/lib/action_view/helpers/tags/check_box.rb +0 -1
  30. data/lib/action_view/helpers/tags/collection_check_boxes.rb +0 -1
  31. data/lib/action_view/helpers/tags/collection_helpers.rb +0 -1
  32. data/lib/action_view/helpers/tags/collection_radio_buttons.rb +0 -1
  33. data/lib/action_view/helpers/tags/color_field.rb +0 -1
  34. data/lib/action_view/helpers/tags/date_field.rb +1 -2
  35. data/lib/action_view/helpers/tags/date_select.rb +2 -3
  36. data/lib/action_view/helpers/tags/datetime_field.rb +0 -1
  37. data/lib/action_view/helpers/tags/datetime_local_field.rb +1 -2
  38. data/lib/action_view/helpers/tags/label.rb +4 -1
  39. data/lib/action_view/helpers/tags/month_field.rb +1 -2
  40. data/lib/action_view/helpers/tags/radio_button.rb +0 -1
  41. data/lib/action_view/helpers/tags/select.rb +1 -2
  42. data/lib/action_view/helpers/tags/text_field.rb +0 -1
  43. data/lib/action_view/helpers/tags/time_field.rb +1 -2
  44. data/lib/action_view/helpers/tags/week_field.rb +1 -2
  45. data/lib/action_view/helpers/text_helper.rb +1 -2
  46. data/lib/action_view/helpers/translation_helper.rb +99 -54
  47. data/lib/action_view/helpers/url_helper.rb +109 -15
  48. data/lib/action_view/layouts.rb +8 -10
  49. data/lib/action_view/log_subscriber.rb +26 -11
  50. data/lib/action_view/lookup_context.rb +59 -31
  51. data/lib/action_view/path_set.rb +3 -12
  52. data/lib/action_view/railtie.rb +36 -42
  53. data/lib/action_view/record_identifier.rb +0 -1
  54. data/lib/action_view/renderer/abstract_renderer.rb +142 -11
  55. data/lib/action_view/renderer/collection_renderer.rb +192 -0
  56. data/lib/action_view/renderer/object_renderer.rb +34 -0
  57. data/lib/action_view/renderer/partial_renderer/collection_caching.rb +35 -29
  58. data/lib/action_view/renderer/partial_renderer.rb +21 -273
  59. data/lib/action_view/renderer/renderer.rb +59 -4
  60. data/lib/action_view/renderer/streaming_template_renderer.rb +9 -7
  61. data/lib/action_view/renderer/template_renderer.rb +35 -27
  62. data/lib/action_view/rendering.rb +49 -29
  63. data/lib/action_view/routing_url_for.rb +1 -1
  64. data/lib/action_view/template/error.rb +30 -15
  65. data/lib/action_view/template/handlers/builder.rb +2 -2
  66. data/lib/action_view/template/handlers/erb/erubi.rb +15 -9
  67. data/lib/action_view/template/handlers/erb.rb +14 -19
  68. data/lib/action_view/template/handlers/html.rb +1 -1
  69. data/lib/action_view/template/handlers/raw.rb +2 -2
  70. data/lib/action_view/template/handlers.rb +1 -1
  71. data/lib/action_view/template/html.rb +5 -6
  72. data/lib/action_view/template/inline.rb +22 -0
  73. data/lib/action_view/template/raw_file.rb +25 -0
  74. data/lib/action_view/template/renderable.rb +24 -0
  75. data/lib/action_view/template/resolver.rb +141 -140
  76. data/lib/action_view/template/sources/file.rb +17 -0
  77. data/lib/action_view/template/sources.rb +13 -0
  78. data/lib/action_view/template/text.rb +2 -3
  79. data/lib/action_view/template.rb +49 -75
  80. data/lib/action_view/test_case.rb +20 -28
  81. data/lib/action_view/testing/resolvers.rb +18 -27
  82. data/lib/action_view/unbound_template.rb +31 -0
  83. data/lib/action_view/view_paths.rb +59 -38
  84. data/lib/action_view.rb +7 -2
  85. data/lib/assets/compiled/rails-ujs.js +22 -13
  86. metadata +30 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58d19af0e853c217ca89f2167775195c7a44ebba26e4d9a682aabeb6a25b6af4
4
- data.tar.gz: 15d2c9faa90c17d33772df3ce0eacccecb090e7310af47ab1d82bca6448a2a11
3
+ metadata.gz: 66b9ba4747ae5973f8f784343f64e7201d2bbf8299cb9b9dc2ed7869db55cbc6
4
+ data.tar.gz: da671bc8666ecd9386fa75a7639c837492df9b0d5b81c9f2a66114a522d6dec9
5
5
  SHA512:
6
- metadata.gz: dc169a10649b5f6cdfb8488bd16cbb7cab049081e7a6c53821cfab497e8035c7843c690e3bffcffc571bf2f610e5f2b7eee80283f622262d5ff9f1f20c8ef210
7
- data.tar.gz: ed371d7bec363bafe775d5a1ed3d11a1002f96589c142c662afabc1862c71314427fc07004d0bfa4bc2ac5078f0c0b38410ccca1ee738594223a1a3a336ffa14
6
+ metadata.gz: 409ff7a86026884f20e3fbf1eb0560fc990328369c15e90500f27dc8336020edc59acfb3b8da61806c7eac62ae501c1c5f176c4dc7da641f3da338bcfb2cc6f5
7
+ data.tar.gz: 961932d31d4e46c9674a9ea3229db468dfd922c1b79c9f23403b928763f1a8798848dae25554f09255965968109e7557953b4c3a7d6573e142061a3fc3e360c7
data/CHANGELOG.md CHANGED
@@ -1,191 +1,278 @@
1
- ## Rails 6.0.0.beta1 (January 18, 2019) ##
1
+ ## Rails 6.1.0 (December 09, 2020) ##
2
2
 
3
- * Remove deprecated `image_alt` helper.
3
+ * SanitizeHelper.sanitized_allowed_attributes and SanitizeHelper.sanitized_allowed_tags
4
+ call safe_list_sanitizer's class method
5
+
6
+ Fixes #39586
7
+
8
+ *Taufiq Muhammadi*
9
+
10
+ * Change form_with to generate non-remote forms by default.
11
+
12
+ `form_with` would generate a remote form by default. This would confuse
13
+ users because they were forced to handle remote requests.
14
+
15
+ All new 6.1 applications will generate non-remote forms by default.
16
+ When upgrading a 6.0 application you can enable remote forms by default by
17
+ setting `config.action_view.form_with_generates_remote_forms` to `true`.
18
+
19
+ *Petrik de Heus*
20
+
21
+ * Yield translated strings to calls of `ActionView::FormBuilder#button`
22
+ when a block is given.
23
+
24
+ *Sean Doyle*
25
+
26
+ * Alias `ActionView::Helpers::Tags::Label::LabelBuilder#translation` to
27
+ `#to_s` so that `form.label` calls can yield that value to their blocks.
28
+
29
+ *Sean Doyle*
30
+
31
+ * Rename the new `TagHelper#class_names` method to `TagHelper#token_list`,
32
+ and make the original available as an alias.
33
+
34
+ token_list("foo", "foo bar")
35
+ # => "foo bar"
36
+
37
+ *Sean Doyle*
38
+
39
+ * ARIA Array and Hash attributes are treated as space separated `DOMTokenList`
40
+ values. This is useful when declaring lists of label text identifiers in
41
+ `aria-labelledby` or `aria-describedby`.
42
+
43
+ tag.input type: 'checkbox', name: 'published', aria: {
44
+ invalid: @post.errors[:published].any?,
45
+ labelledby: ['published_context', 'published_label'],
46
+ describedby: { published_errors: @post.errors[:published].any? }
47
+ }
48
+ #=> <input
49
+ type="checkbox" name="published" aria-invalid="true"
50
+ aria-labelledby="published_context published_label"
51
+ aria-describedby="published_errors"
52
+ >
53
+
54
+ *Sean Doyle*
55
+
56
+ * Remove deprecated `escape_whitelist` from `ActionView::Template::Handlers::ERB`.
4
57
 
5
58
  *Rafael Mendonça França*
6
59
 
7
- * Fix the need of `#protect_against_forgery?` method defined in
8
- `ActionView::Base` subclasses. This prevents the use of forms and buttons.
60
+ * Remove deprecated `find_all_anywhere` from `ActionView::Resolver`.
9
61
 
10
- *Genadi Samokovarov*
62
+ *Rafael Mendonça França*
11
63
 
12
- * Fix UJS permanently showing disabled text in a[data-remote][data-disable-with] elements within forms.
13
- Fixes #33889
64
+ * Remove deprecated `formats` from `ActionView::Template::HTML`.
14
65
 
15
- *Wolfgang Hobmaier*
66
+ *Rafael Mendonça França*
16
67
 
17
- * Prevent non-primary mouse keys from triggering Rails UJS click handlers.
18
- Firefox fires click events even if the click was triggered by non-primary mouse keys such as right- or scroll-wheel-clicks.
19
- For example, right-clicking a link such as the one described below (with an underlying ajax request registered on click) should not cause that request to occur.
68
+ * Remove deprecated `formats` from `ActionView::Template::RawFile`.
20
69
 
21
- ```
22
- <%= link_to 'Remote', remote_path, class: 'remote', remote: true, data: { type: :json } %>
23
- ```
70
+ *Rafael Mendonça França*
24
71
 
25
- Fixes #34541
72
+ * Remove deprecated `formats` from `ActionView::Template::Text`.
26
73
 
27
- *Wolfgang Hobmaier*
74
+ *Rafael Mendonça França*
28
75
 
29
- * Prevent `ActionView::TextHelper#word_wrap` from unexpectedly stripping white space from the _left_ side of lines.
76
+ * Remove deprecated `find_file` from `ActionView::PathSet`.
30
77
 
31
- For example, given input like this:
78
+ *Rafael Mendonça França*
32
79
 
33
- ```
34
- This is a paragraph with an initial indent,
35
- followed by additional lines that are not indented,
36
- and finally terminated with a blockquote:
37
- "A pithy saying"
38
- ```
80
+ * Remove deprecated `rendered_format` from `ActionView::LookupContext`.
39
81
 
40
- Calling `word_wrap` should not trim the indents on the first and last lines.
82
+ *Rafael Mendonça França*
41
83
 
42
- Fixes #34487
84
+ * Remove deprecated `find_file` from `ActionView::ViewPaths`.
43
85
 
44
- *Lyle Mullican*
86
+ *Rafael Mendonça França*
45
87
 
46
- * Add allocations to template rendering instrumentation.
88
+ * Require that `ActionView::Base` subclasses implement `#compiled_method_container`.
47
89
 
48
- Adds the allocations for template and partial rendering to the server output on render.
90
+ *Rafael Mendonça França*
49
91
 
50
- ```
51
- Rendered posts/_form.html.erb (Duration: 7.1ms | Allocations: 6004)
52
- Rendered posts/new.html.erb within layouts/application (Duration: 8.3ms | Allocations: 6654)
53
- Completed 200 OK in 858ms (Views: 848.4ms | ActiveRecord: 0.4ms | Allocations: 1539564)
54
- ```
92
+ * Remove deprecated support to pass an object that is not a `ActionView::LookupContext` as the first argument
93
+ in `ActionView::Base#initialize`.
94
+
95
+ *Rafael Mendonça França*
96
+
97
+ * Remove deprecated `format` argument `ActionView::Base#initialize`.
98
+
99
+ *Rafael Mendonça França*
100
+
101
+ * Remove deprecated `ActionView::Template#refresh`.
102
+
103
+ *Rafael Mendonça França*
104
+
105
+ * Remove deprecated `ActionView::Template#original_encoding`.
106
+
107
+ *Rafael Mendonça França*
108
+
109
+ * Remove deprecated `ActionView::Template#variants`.
55
110
 
56
- *Eileen M. Uchitelle*, *Aaron Patterson*
111
+ *Rafael Mendonça França*
57
112
 
58
- * Respect the `only_path` option passed to `url_for` when the options are passed in as an array
113
+ * Remove deprecated `ActionView::Template#formats`.
59
114
 
60
- Fixes #33237.
115
+ *Rafael Mendonça França*
61
116
 
62
- *Joel Ambass*
117
+ * Remove deprecated `ActionView::Template#virtual_path=`.
63
118
 
64
- * Deprecate calling private model methods from view helpers.
119
+ *Rafael Mendonça França*
65
120
 
66
- For example, in methods like `options_from_collection_for_select`
67
- and `collection_select` it is possible to call private methods from
68
- the objects used.
121
+ * Remove deprecated `ActionView::Template#updated_at`.
69
122
 
70
- Fixes #33546.
123
+ *Rafael Mendonça França*
71
124
 
72
- *Ana María Martínez Gómez*
125
+ * Remove deprecated `updated_at` argument required on `ActionView::Template#initialize`.
73
126
 
74
- * Fix issue with `button_to`'s `to_form_params`
127
+ *Rafael Mendonça França*
75
128
 
76
- `button_to` was throwing exception when invoked with `params` hash that
77
- contains symbol and string keys. The reason for the exception was that
78
- `to_form_params` was comparing the given symbol and string keys.
129
+ * Make `locals` argument required on `ActionView::Template#initialize`.
79
130
 
80
- The issue is fixed by turning all keys to strings inside
81
- `to_form_params` before comparing them.
131
+ *Rafael Mendonça França*
82
132
 
83
- *Georgi Georgiev*
133
+ * Remove deprecated `ActionView::Template.finalize_compiled_template_methods`.
84
134
 
85
- * Mark arrays of translations as trusted safe by using the `_html` suffix.
135
+ *Rafael Mendonça França*
86
136
 
87
- Example:
137
+ * Remove deprecated `config.action_view.finalize_compiled_template_methods`
88
138
 
89
- en:
90
- foo_html:
91
- - "One"
92
- - "<strong>Two</strong>"
93
- - "Three &#128075; &#128578;"
139
+ *Rafael Mendonça França*
94
140
 
95
- *Juan Broullon*
141
+ * Remove deprecated support to calling `ActionView::ViewPaths#with_fallback` with a block.
96
142
 
97
- * Add `year_format` option to date_select tag. This option makes it possible to customize year
98
- names. Lambda should be passed to use this option.
143
+ *Rafael Mendonça França*
99
144
 
100
- Example:
145
+ * Remove deprecated support to passing absolute paths to `render template:`.
101
146
 
102
- date_select('user_birthday', '', start_year: 1998, end_year: 2000, year_format: ->year { "Heisei #{year - 1988}" })
147
+ *Rafael Mendonça França*
103
148
 
104
- The HTML produced:
149
+ * Remove deprecated support to passing relative paths to `render file:`.
105
150
 
106
- <select id="user_birthday__1i" name="user_birthday[(1i)]">
107
- <option value="1998">Heisei 10</option>
108
- <option value="1999">Heisei 11</option>
109
- <option value="2000">Heisei 12</option>
110
- </select>
111
- /* The rest is omitted */
151
+ *Rafael Mendonça França*
112
152
 
113
- *Koki Ryu*
153
+ * Remove support to template handlers that don't accept two arguments.
114
154
 
115
- * Fix JavaScript views rendering does not work with Firefox when using
116
- Content Security Policy.
155
+ *Rafael Mendonça França*
117
156
 
118
- Fixes #32577.
157
+ * Remove deprecated pattern argument in `ActionView::Template::PathResolver`.
119
158
 
120
- *Yuji Yaginuma*
159
+ *Rafael Mendonça França*
121
160
 
122
- * Add the `nonce: true` option for `javascript_include_tag` helper to
123
- support automatic nonce generation for Content Security Policy.
124
- Works the same way as `javascript_tag nonce: true` does.
161
+ * Remove deprecated support to call private methods from object in some view helpers.
125
162
 
126
- *Yaroslav Markin*
163
+ *Rafael Mendonça França*
127
164
 
128
- * Remove `ActionView::Helpers::RecordTagHelper`.
165
+ * `ActionView::Helpers::TranslationHelper#translate` accepts a block, yielding
166
+ the translated text and the fully resolved translation key:
129
167
 
130
- *Yoshiyuki Hirano*
168
+ <%= translate(".relative_key") do |translation, resolved_key| %>
169
+ <span title="<%= resolved_key %>"><%= translation %></span>
170
+ <% end %>
131
171
 
132
- * Disable `ActionView::Template` finalizers in test environment.
172
+ *Sean Doyle*
133
173
 
134
- Template finalization can be expensive in large view test suites.
135
- Add a configuration option,
136
- `action_view.finalize_compiled_template_methods`, and turn it off in
137
- the test environment.
174
+ * Ensure cache fragment digests include all relevant template dependencies when
175
+ fragments are contained in a block passed to the render helper. Remove the
176
+ virtual_path keyword arguments found in CacheHelper as they no longer possess
177
+ any function following 1581cab.
138
178
 
139
- *Simon Coffey*
179
+ Fixes #38984.
140
180
 
141
- * Extract the `confirm` call in its own, overridable method in `rails_ujs`.
181
+ *Aaron Lipman*
142
182
 
143
- Example:
183
+ * Deprecate `config.action_view.raise_on_missing_translations` in favor of
184
+ `config.i18n.raise_on_missing_translations`.
144
185
 
145
- Rails.confirm = function(message, element) {
146
- return (my_bootstrap_modal_confirm(message));
147
- }
186
+ New generalized configuration option now determines whether an error should be raised
187
+ for missing translations in controllers and views.
188
+
189
+ *fatkodima*
190
+
191
+ * Instrument layout rendering in `TemplateRenderer#render_with_layout` as `render_layout.action_view`,
192
+ and include (when necessary) the layout's virtual path in notification payloads for collection and partial renders.
193
+
194
+ *Zach Kemp*
195
+
196
+ * `ActionView::Base.annotate_rendered_view_with_filenames` annotates HTML output with template file names.
197
+
198
+ *Joel Hawksley*, *Aaron Patterson*
199
+
200
+ * `ActionView::Helpers::TranslationHelper#translate` returns nil when
201
+ passed `default: nil` without a translation matching `I18n#translate`.
202
+
203
+ *Stefan Wrobel*
204
+
205
+ * `OptimizedFileSystemResolver` prefers template details in order of locale,
206
+ formats, variants, handlers.
207
+
208
+ *Iago Pimenta*
209
+
210
+ * Added `class_names` helper to create a CSS class value with conditional classes.
211
+
212
+ *Joel Hawksley*, *Aaron Patterson*
213
+
214
+ * Add support for conditional values to TagBuilder.
215
+
216
+ *Joel Hawksley*
217
+
218
+ * `ActionView::Helpers::FormOptionsHelper#select` should mark option for `nil` as selected.
219
+
220
+ ```ruby
221
+ @post = Post.new
222
+ @post.category = nil
223
+
224
+ # Before
225
+ select("post", "category", none: nil, programming: 1, economics: 2)
226
+ # =>
227
+ # <select name="post[category]" id="post_category">
228
+ # <option value="">none</option>
229
+ # <option value="1">programming</option>
230
+ # <option value="2">economics</option>
231
+ # </select>
232
+
233
+ # After
234
+ select("post", "category", none: nil, programming: 1, economics: 2)
235
+ # =>
236
+ # <select name="post[category]" id="post_category">
237
+ # <option selected="selected" value="">none</option>
238
+ # <option value="1">programming</option>
239
+ # <option value="2">economics</option>
240
+ # </select>
241
+ ```
242
+
243
+ *bogdanvlviv*
148
244
 
149
- *Mathieu Mahé*
245
+ * Log lines for partial renders and started template renders are now
246
+ emitted at the `DEBUG` level instead of `INFO`.
150
247
 
151
- * Enable select tag helper to mark `prompt` option as `selected` and/or `disabled` for `required`
152
- field.
248
+ Completed template renders are still logged at the `INFO` level.
153
249
 
154
- Example:
250
+ *DHH*
155
251
 
156
- select :post,
157
- :category,
158
- ["lifestyle", "programming", "spiritual"],
159
- { selected: "", disabled: "", prompt: "Choose one" },
160
- { required: true }
252
+ * ActionView::Helpers::SanitizeHelper: support rails-html-sanitizer 1.1.0.
161
253
 
162
- Placeholder option would be selected and disabled.
254
+ *Juanito Fatas*
163
255
 
164
- The HTML produced:
256
+ * Added `phone_to` helper method to create a link from mobile numbers.
165
257
 
166
- <select required="required" name="post[category]" id="post_category">
167
- <option disabled="disabled" selected="selected" value="">Choose one</option>
168
- <option value="lifestyle">lifestyle</option>
169
- <option value="programming">programming</option>
170
- <option value="spiritual">spiritual</option></select>
258
+ *Pietro Moro*
171
259
 
172
- *Sergey Prikhodko*
260
+ * annotated_source_code returns an empty array so TemplateErrors without a
261
+ template in the backtrace are surfaced properly by DebugExceptions.
173
262
 
174
- * Don't enforce UTF-8 by default.
263
+ *Guilherme Mansur*, *Kasper Timm Hansen*
175
264
 
176
- With the disabling of TLS 1.0 by most major websites, continuing to run
177
- IE8 or lower becomes increasingly difficult so default to not enforcing
178
- UTF-8 encoding as it's not relevant to other browsers.
265
+ * Add autoload for SyntaxErrorInTemplate so syntax errors are correctly raised by DebugExceptions.
179
266
 
180
- *Andrew White*
267
+ *Guilherme Mansur*, *Gannon McGibbon*
181
268
 
182
- * Change translation key of `submit_tag` from `module_name_class_name` to `module_name/class_name`.
269
+ * `RenderingHelper` supports rendering objects that `respond_to?` `:render_in`.
183
270
 
184
- *Rui Onodera*
271
+ *Joel Hawksley*, *Natasha Umer*, *Aaron Patterson*, *Shawn Allen*, *Emily Plummer*, *Diana Mounter*, *John Hawthorn*, *Nathan Herald*, *Zaid Zawaideh*, *Zach Ahn*
185
272
 
186
- * Rails 6 requires Ruby 2.5.0 or newer.
273
+ * Fix `select_tag` so that it doesn't change `options` when `include_blank` is present.
187
274
 
188
- *Jeremy Daer*, *Kasper Timm Hansen*
275
+ *Younes SERRAJ*
189
276
 
190
277
 
191
- Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/actionview/CHANGELOG.md) for previous changes.
278
+ Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/actionview/CHANGELOG.md) for previous changes.
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2004-2019 David Heinemeier Hansson
1
+ Copyright (c) 2004-2020 David Heinemeier Hansson
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -5,6 +5,8 @@ view helpers that assist when building HTML forms, Atom feeds and more.
5
5
  Template formats that Action View handles are ERB (embedded Ruby, typically
6
6
  used to inline short Ruby snippets inside HTML), and XML Builder.
7
7
 
8
+ You can read more about Action View in the {Action View Overview}[https://edgeguides.rubyonrails.org/action_view_overview.html] guide.
9
+
8
10
  == Download and installation
9
11
 
10
12
  The latest version of Action View can be installed with RubyGems:
@@ -27,7 +29,7 @@ Action View is released under the MIT license:
27
29
 
28
30
  API documentation is at
29
31
 
30
- * http://api.rubyonrails.org
32
+ * https://api.rubyonrails.org
31
33
 
32
34
  Bug reports for the Ruby on Rails project can be filed here:
33
35
 
@@ -35,4 +37,4 @@ Bug reports for the Ruby on Rails project can be filed here:
35
37
 
36
38
  Feature requests should be discussed on the rails-core mailing list here:
37
39
 
38
- * https://groups.google.com/forum/?fromgroups#!forum/rubyonrails-core
40
+ * https://discuss.rubyonrails.org/c/rubyonrails-core
@@ -27,7 +27,7 @@ module ActionView #:nodoc:
27
27
  # Name: <%= person.name %><br/>
28
28
  # <% end %>
29
29
  #
30
- # The loop is setup in regular embedding tags <tt><% %></tt>, and the name is written using the output embedding tag <tt><%= %></tt>. Note that this
30
+ # The loop is set up in regular embedding tags <tt><% %></tt>, and the name is written using the output embedding tag <tt><%= %></tt>. Note that this
31
31
  # is not just a usage suggestion. Regular output functions like print or puts won't work with ERB templates. So this would be wrong:
32
32
  #
33
33
  # <%# WRONG %>
@@ -151,7 +151,7 @@ module ActionView #:nodoc:
151
151
  # Specify whether rendering within namespaced controllers should prefix
152
152
  # the partial paths for ActiveModel objects with the namespace.
153
153
  # (e.g., an Admin::PostsController would render @post using /admin/posts/_post.erb)
154
- cattr_accessor :prefix_partial_path_with_controller_namespace, default: true
154
+ class_attribute :prefix_partial_path_with_controller_namespace, default: true
155
155
 
156
156
  # Specify default_formats that can be rendered.
157
157
  cattr_accessor :default_formats
@@ -162,6 +162,9 @@ module ActionView #:nodoc:
162
162
  # Specify whether submit_tag should automatically disable on click
163
163
  cattr_accessor :automatically_disable_submit_tag, default: true
164
164
 
165
+ # Annotate rendered view with file names
166
+ cattr_accessor :annotate_rendered_view_with_filenames, default: false
167
+
165
168
  class_attribute :_routes
166
169
  class_attribute :logger
167
170
 
@@ -179,37 +182,100 @@ module ActionView #:nodoc:
179
182
  def xss_safe? #:nodoc:
180
183
  true
181
184
  end
185
+
186
+ def with_empty_template_cache # :nodoc:
187
+ subclass = Class.new(self) {
188
+ # We can't implement these as self.class because subclasses will
189
+ # share the same template cache as superclasses, so "changed?" won't work
190
+ # correctly.
191
+ define_method(:compiled_method_container) { subclass }
192
+ define_singleton_method(:compiled_method_container) { subclass }
193
+
194
+ def inspect
195
+ "#<ActionView::Base:#{'%#016x' % (object_id << 1)}>"
196
+ end
197
+ }
198
+ end
199
+
200
+ def changed?(other) # :nodoc:
201
+ compiled_method_container != other.compiled_method_container
202
+ end
182
203
  end
183
204
 
184
- attr_accessor :view_renderer
205
+ attr_reader :view_renderer, :lookup_context
185
206
  attr_internal :config, :assigns
186
207
 
187
- delegate :lookup_context, to: :view_renderer
188
208
  delegate :formats, :formats=, :locale, :locale=, :view_paths, :view_paths=, to: :lookup_context
189
209
 
190
210
  def assign(new_assigns) # :nodoc:
191
211
  @_assigns = new_assigns.each { |key, value| instance_variable_set("@#{key}", value) }
192
212
  end
193
213
 
194
- def initialize(context = nil, assigns = {}, controller = nil, formats = nil) #:nodoc:
214
+ # :stopdoc:
215
+
216
+ def self.empty
217
+ with_view_paths([])
218
+ end
219
+
220
+ def self.with_view_paths(view_paths, assigns = {}, controller = nil)
221
+ with_context ActionView::LookupContext.new(view_paths), assigns, controller
222
+ end
223
+
224
+ def self.with_context(context, assigns = {}, controller = nil)
225
+ new context, assigns, controller
226
+ end
227
+
228
+ # :startdoc:
229
+
230
+ def initialize(lookup_context, assigns, controller) #:nodoc:
195
231
  @_config = ActiveSupport::InheritableOptions.new
196
232
 
197
- if context.is_a?(ActionView::Renderer)
198
- @view_renderer = context
199
- else
200
- lookup_context = context.is_a?(ActionView::LookupContext) ?
201
- context : ActionView::LookupContext.new(context)
202
- lookup_context.formats = formats if formats
203
- lookup_context.prefixes = controller._prefixes if controller
204
- @view_renderer = ActionView::Renderer.new(lookup_context)
205
- end
233
+ @lookup_context = lookup_context
234
+
235
+ @view_renderer = ActionView::Renderer.new @lookup_context
236
+ @current_template = nil
206
237
 
207
- @cache_hit = {}
208
238
  assign(assigns)
209
239
  assign_controller(controller)
210
240
  _prepare_context
211
241
  end
212
242
 
243
+ def _run(method, template, locals, buffer, add_to_stack: true, &block)
244
+ _old_output_buffer, _old_template = @output_buffer, @current_template
245
+ @current_template = template if add_to_stack
246
+ @output_buffer = buffer
247
+ public_send(method, locals, buffer, &block)
248
+ ensure
249
+ @output_buffer, @current_template = _old_output_buffer, _old_template
250
+ end
251
+
252
+ def compiled_method_container
253
+ raise NotImplementedError, <<~msg.squish
254
+ Subclasses of ActionView::Base must implement `compiled_method_container`
255
+ or use the class method `with_empty_template_cache` for constructing
256
+ an ActionView::Base subclass that has an empty cache.
257
+ msg
258
+ end
259
+
260
+ def in_rendering_context(options)
261
+ old_view_renderer = @view_renderer
262
+ old_lookup_context = @lookup_context
263
+
264
+ if !lookup_context.html_fallback_for_js && options[:formats]
265
+ formats = Array(options[:formats])
266
+ if formats == [:js]
267
+ formats << :html
268
+ end
269
+ @lookup_context = lookup_context.with_prepended_formats(formats)
270
+ @view_renderer = ActionView::Renderer.new @lookup_context
271
+ end
272
+
273
+ yield @view_renderer
274
+ ensure
275
+ @view_renderer = old_view_renderer
276
+ @lookup_context = old_lookup_context
277
+ end
278
+
213
279
  ActiveSupport.run_load_hooks(:action_view, self)
214
280
  end
215
281
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView
4
+ class CacheExpiry
5
+ class Executor
6
+ def initialize(watcher:)
7
+ @cache_expiry = CacheExpiry.new(watcher: watcher)
8
+ end
9
+
10
+ def before(target)
11
+ @cache_expiry.clear_cache_if_necessary
12
+ end
13
+ end
14
+
15
+ def initialize(watcher:)
16
+ @watched_dirs = nil
17
+ @watcher_class = watcher
18
+ @watcher = nil
19
+ @mutex = Mutex.new
20
+ end
21
+
22
+ def clear_cache_if_necessary
23
+ @mutex.synchronize do
24
+ watched_dirs = dirs_to_watch
25
+ return if watched_dirs.empty?
26
+
27
+ if watched_dirs != @watched_dirs
28
+ @watched_dirs = watched_dirs
29
+ @watcher = @watcher_class.new([], watched_dirs) do
30
+ clear_cache
31
+ end
32
+ @watcher.execute
33
+ else
34
+ @watcher.execute_if_updated
35
+ end
36
+ end
37
+ end
38
+
39
+ def clear_cache
40
+ ActionView::LookupContext::DetailsKey.clear
41
+ end
42
+
43
+ private
44
+ def dirs_to_watch
45
+ all_view_paths.grep(FileSystemResolver).map!(&:path).tap(&:uniq!).sort!
46
+ end
47
+
48
+ def all_view_paths
49
+ ActionView::ViewPaths.all_view_paths.flat_map(&:paths)
50
+ end
51
+ end
52
+ end
@@ -1,10 +1,6 @@
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.
@@ -16,14 +12,12 @@ module ActionView
16
12
  # object that includes this module (although you can call _prepare_context
17
13
  # defined below).
18
14
  module Context
19
- include CompiledTemplates
20
15
  attr_accessor :output_buffer, :view_flow
21
16
 
22
17
  # Prepares the context by setting the appropriate instance variables.
23
18
  def _prepare_context
24
19
  @view_flow = OutputFlow.new
25
20
  @output_buffer = nil
26
- @virtual_path = nil
27
21
  end
28
22
 
29
23
  # Encapsulates the interaction with the view flow so it