actionview 6.0.0.beta1 → 6.0.0.beta2

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 (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +28 -3
  3. data/lib/action_view.rb +1 -1
  4. data/lib/action_view/base.rb +107 -10
  5. data/lib/action_view/context.rb +0 -5
  6. data/lib/action_view/digestor.rb +4 -8
  7. data/lib/action_view/file_template.rb +33 -0
  8. data/lib/action_view/gem_version.rb +1 -1
  9. data/lib/action_view/helpers/asset_tag_helper.rb +5 -5
  10. data/lib/action_view/helpers/cache_helper.rb +5 -5
  11. data/lib/action_view/helpers/csp_helper.rb +4 -2
  12. data/lib/action_view/helpers/rendering_helper.rb +6 -4
  13. data/lib/action_view/helpers/tags/base.rb +1 -1
  14. data/lib/action_view/helpers/translation_helper.rb +1 -1
  15. data/lib/action_view/layouts.rb +5 -5
  16. data/lib/action_view/lookup_context.rb +59 -24
  17. data/lib/action_view/railtie.rb +8 -3
  18. data/lib/action_view/renderer/abstract_renderer.rb +56 -3
  19. data/lib/action_view/renderer/partial_renderer.rb +66 -52
  20. data/lib/action_view/renderer/partial_renderer/collection_caching.rb +14 -14
  21. data/lib/action_view/renderer/renderer.rb +16 -4
  22. data/lib/action_view/renderer/streaming_template_renderer.rb +3 -3
  23. data/lib/action_view/renderer/template_renderer.rb +18 -18
  24. data/lib/action_view/rendering.rb +44 -26
  25. data/lib/action_view/template.rb +58 -36
  26. data/lib/action_view/template/handlers.rb +27 -1
  27. data/lib/action_view/template/handlers/builder.rb +2 -2
  28. data/lib/action_view/template/handlers/erb.rb +5 -5
  29. data/lib/action_view/template/handlers/erb/erubi.rb +7 -3
  30. data/lib/action_view/template/handlers/html.rb +1 -1
  31. data/lib/action_view/template/handlers/raw.rb +2 -2
  32. data/lib/action_view/template/html.rb +14 -5
  33. data/lib/action_view/template/inline.rb +22 -0
  34. data/lib/action_view/template/resolver.rb +14 -7
  35. data/lib/action_view/template/text.rb +5 -3
  36. data/lib/action_view/testing/resolvers.rb +6 -4
  37. data/lib/action_view/view_paths.rb +25 -1
  38. metadata +12 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58d19af0e853c217ca89f2167775195c7a44ebba26e4d9a682aabeb6a25b6af4
4
- data.tar.gz: 15d2c9faa90c17d33772df3ce0eacccecb090e7310af47ab1d82bca6448a2a11
3
+ metadata.gz: ec7748334d455691ff0946d9ffffa3e6265a87b7fb0e9f070ed7b938f9764750
4
+ data.tar.gz: 73d7bdba0ec98f9dd8224c2887d603c8860667981d96b0ef054d66c136374bf1
5
5
  SHA512:
6
- metadata.gz: dc169a10649b5f6cdfb8488bd16cbb7cab049081e7a6c53821cfab497e8035c7843c690e3bffcffc571bf2f610e5f2b7eee80283f622262d5ff9f1f20c8ef210
7
- data.tar.gz: ed371d7bec363bafe775d5a1ed3d11a1002f96589c142c662afabc1862c71314427fc07004d0bfa4bc2ac5078f0c0b38410ccca1ee738594223a1a3a336ffa14
6
+ metadata.gz: '0282f9151c08198bb8e1e3cf3d2e2d6eccf17813c4069c0468003e2abf417ebba04cc6a6fb94ddf490900663561759adbfb74b83a7144641a274caeec33e66ec'
7
+ data.tar.gz: 499a7436942dc63ad515def9e709524fd1d87b26d0e3078ec97abf625134ccd43466dbb22501b079d4383b94bdb1dd997301582e426d179cd872266cec5a2730
@@ -1,5 +1,29 @@
1
+ ## Rails 6.0.0.beta2 (February 25, 2019) ##
2
+
3
+ * ActionView::Template.finalize_compiled_template_methods is deprecated with
4
+ no replacement.
5
+
6
+ *tenderlove*
7
+
8
+ * config.action_view.finalize_compiled_template_methods is deprecated with
9
+ no replacement.
10
+
11
+ *tenderlove*
12
+
13
+ * Ensure unique DOM IDs for collection inputs with float values.
14
+ Fixes #34974
15
+
16
+ *Mark Edmondson*
17
+
18
+
1
19
  ## Rails 6.0.0.beta1 (January 18, 2019) ##
2
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).
24
+
25
+ *Javan Makhmali*
26
+
3
27
  * Remove deprecated `image_alt` helper.
4
28
 
5
29
  *Rafael Mendonça França*
@@ -10,7 +34,8 @@
10
34
  *Genadi Samokovarov*
11
35
 
12
36
  * Fix UJS permanently showing disabled text in a[data-remote][data-disable-with] elements within forms.
13
- Fixes #33889
37
+
38
+ Fixes #33889.
14
39
 
15
40
  *Wolfgang Hobmaier*
16
41
 
@@ -22,7 +47,7 @@
22
47
  <%= link_to 'Remote', remote_path, class: 'remote', remote: true, data: { type: :json } %>
23
48
  ```
24
49
 
25
- Fixes #34541
50
+ Fixes #34541.
26
51
 
27
52
  *Wolfgang Hobmaier*
28
53
 
@@ -39,7 +64,7 @@
39
64
 
40
65
  Calling `word_wrap` should not trim the indents on the first and last lines.
41
66
 
42
- Fixes #34487
67
+ Fixes #34487.
43
68
 
44
69
  *Lyle Mullican*
45
70
 
@@ -35,7 +35,6 @@ module ActionView
35
35
  eager_autoload do
36
36
  autoload :Base
37
37
  autoload :Context
38
- autoload :CompiledTemplates, "action_view/context"
39
38
  autoload :Digestor
40
39
  autoload :Helpers
41
40
  autoload :LookupContext
@@ -45,6 +44,7 @@ module ActionView
45
44
  autoload :Rendering
46
45
  autoload :RoutingUrlFor
47
46
  autoload :Template
47
+ autoload :FileTemplate
48
48
  autoload :ViewPaths
49
49
 
50
50
  autoload_under "renderer" do
@@ -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
- attr_accessor :view_renderer
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
- def initialize(context = nil, assigns = {}, controller = nil, formats = nil) #:nodoc:
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
- if context.is_a?(ActionView::Renderer)
198
- @view_renderer = context
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
- 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)
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
@@ -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,7 +12,6 @@ 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.
@@ -18,11 +18,11 @@ module ActionView
18
18
  # * <tt>name</tt> - Template name
19
19
  # * <tt>finder</tt> - An instance of <tt>ActionView::LookupContext</tt>
20
20
  # * <tt>dependencies</tt> - An array of dependent views
21
- def digest(name:, finder:, dependencies: nil)
21
+ def digest(name:, format:, finder:, dependencies: nil)
22
22
  if dependencies.nil? || dependencies.empty?
23
- cache_key = "#{name}.#{finder.rendered_format}"
23
+ cache_key = "#{name}.#{format}"
24
24
  else
25
- cache_key = [ name, finder.rendered_format, dependencies ].flatten.compact.join(".")
25
+ cache_key = [ name, format, dependencies ].flatten.compact.join(".")
26
26
  end
27
27
 
28
28
  # this is a correctly done double-checked locking idiom
@@ -48,8 +48,6 @@ module ActionView
48
48
  logical_name = name.gsub(%r|/_|, "/")
49
49
 
50
50
  if template = find_template(finder, logical_name, [], partial, [])
51
- finder.rendered_format ||= template.formats.first
52
-
53
51
  if node = seen[template.identifier] # handle cycles in the tree
54
52
  node
55
53
  else
@@ -73,9 +71,7 @@ module ActionView
73
71
  private
74
72
  def find_template(finder, name, prefixes, partial, keys)
75
73
  finder.disable_cache do
76
- format = finder.rendered_format
77
- result = finder.find_all(name, prefixes, partial, keys, formats: [format]).first if format
78
- result || finder.find_all(name, prefixes, partial, keys).first
74
+ finder.find_all(name, prefixes, partial, keys).first
79
75
  end
80
76
  end
81
77
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "action_view/template"
4
+
5
+ module ActionView
6
+ class FileTemplate < Template
7
+ def initialize(filename, handler, details)
8
+ @filename = filename
9
+
10
+ super(nil, filename, handler, details)
11
+ end
12
+
13
+ def source
14
+ File.binread @filename
15
+ end
16
+
17
+ def refresh(_)
18
+ self
19
+ end
20
+
21
+ # Exceptions are marshalled when using the parallel test runner with DRb, so we need
22
+ # to ensure that references to the template object can be marshalled as well. This means forgoing
23
+ # the marshalling of the compiler mutex and instantiating that again on unmarshalling.
24
+ def marshal_dump # :nodoc:
25
+ [ @identifier, @handler, @compiled, @original_encoding, @locals, @virtual_path, @updated_at, @format, @variants ]
26
+ end
27
+
28
+ def marshal_load(array) # :nodoc:
29
+ @identifier, @handler, @compiled, @original_encoding, @locals, @virtual_path, @updated_at, @format, @variants = *array
30
+ @compile_mutex = Mutex.new
31
+ end
32
+ end
33
+ end
@@ -10,7 +10,7 @@ module ActionView
10
10
  MAJOR = 6
11
11
  MINOR = 0
12
12
  TINY = 0
13
- PRE = "beta1"
13
+ PRE = "beta2"
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
16
16
  end
@@ -329,14 +329,14 @@ module ActionView
329
329
  # image_tag("pic.jpg", srcset: [["pic_1024.jpg", "1024w"], ["pic_1980.jpg", "1980w"]], sizes: "100vw")
330
330
  # # => <img src="/assets/pic.jpg" srcset="/assets/pic_1024.jpg 1024w, /assets/pic_1980.jpg 1980w" sizes="100vw">
331
331
  #
332
- # Active Storage (images that are uploaded by the users of your app):
332
+ # Active Storage blobs (images that are uploaded by the users of your app):
333
333
  #
334
334
  # image_tag(user.avatar)
335
335
  # # => <img src="/rails/active_storage/blobs/.../tiger.jpg" />
336
- # image_tag(user.avatar.variant(resize_to_fit: [100, 100]))
337
- # # => <img src="/rails/active_storage/variants/.../tiger.jpg" />
338
- # image_tag(user.avatar.variant(resize_to_fit: [100, 100]), size: '100')
339
- # # => <img width="100" height="100" src="/rails/active_storage/variants/.../tiger.jpg" />
336
+ # image_tag(user.avatar.variant(resize_to_limit: [100, 100]))
337
+ # # => <img src="/rails/active_storage/representations/.../tiger.jpg" />
338
+ # image_tag(user.avatar.variant(resize_to_limit: [100, 100]), size: '100')
339
+ # # => <img width="100" height="100" src="/rails/active_storage/representations/.../tiger.jpg" />
340
340
  def image_tag(source, options = {})
341
341
  options = options.symbolize_keys
342
342
  check_for_image_tag_errors(options)
@@ -216,13 +216,13 @@ module ActionView
216
216
  end
217
217
  end
218
218
 
219
- def digest_path_from_virtual(virtual_path) # :nodoc:
220
- digest = Digestor.digest(name: virtual_path, finder: lookup_context, dependencies: view_cache_dependencies)
219
+ def digest_path_from_template(template) # :nodoc:
220
+ digest = Digestor.digest(name: template.virtual_path, format: template.format, finder: lookup_context, dependencies: view_cache_dependencies)
221
221
 
222
222
  if digest.present?
223
- "#{virtual_path}:#{digest}"
223
+ "#{template.virtual_path}:#{digest}"
224
224
  else
225
- virtual_path
225
+ template.virtual_path
226
226
  end
227
227
  end
228
228
 
@@ -234,7 +234,7 @@ module ActionView
234
234
  if virtual_path || digest_path
235
235
  name = controller.url_for(name).split("://").last if name.is_a?(Hash)
236
236
 
237
- digest_path ||= digest_path_from_virtual(virtual_path)
237
+ digest_path ||= digest_path_from_template(@current_template)
238
238
 
239
239
  [ digest_path, name ]
240
240
  else
@@ -14,9 +14,11 @@ module ActionView
14
14
  # This is used by the Rails UJS helper to create dynamically
15
15
  # loaded inline <script> elements.
16
16
  #
17
- def csp_meta_tag
17
+ def csp_meta_tag(**options)
18
18
  if content_security_policy?
19
- tag("meta", name: "csp-nonce", content: content_security_policy_nonce)
19
+ options[:name] = "csp-nonce"
20
+ options[:content] = content_security_policy_nonce
21
+ tag("meta", options)
20
22
  end
21
23
  end
22
24
  end
@@ -27,10 +27,12 @@ module ActionView
27
27
  def render(options = {}, locals = {}, &block)
28
28
  case options
29
29
  when Hash
30
- if block_given?
31
- view_renderer.render_partial(self, options.merge(partial: options[:layout]), &block)
32
- else
33
- view_renderer.render(self, options)
30
+ in_rendering_context(options) do |renderer|
31
+ if block_given?
32
+ view_renderer.render_partial(self, options.merge(partial: options[:layout]), &block)
33
+ else
34
+ view_renderer.render(self, options)
35
+ end
34
36
  end
35
37
  else
36
38
  view_renderer.render_partial(self, partial: options, locals: locals, &block)
@@ -138,7 +138,7 @@ module ActionView
138
138
  end
139
139
 
140
140
  def sanitized_value(value)
141
- value.to_s.gsub(/\s/, "_").gsub(/[^-[[:word:]]]/, "").mb_chars.downcase.to_s
141
+ value.to_s.gsub(/[\s\.]/, "_").gsub(/[^-[[:word:]]]/, "").mb_chars.downcase.to_s
142
142
  end
143
143
 
144
144
  def select_content_tag(option_tags, options, html_options)
@@ -138,7 +138,7 @@ module ActionView
138
138
  end
139
139
 
140
140
  def html_safe_translation_key?(key)
141
- /(\b|_|\.)html$/.match?(key.to_s)
141
+ /([_.]|\b)html\z/.match?(key.to_s)
142
142
  end
143
143
  end
144
144
  end
@@ -322,7 +322,7 @@ module ActionView
322
322
  end
323
323
 
324
324
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
325
- def _layout(formats)
325
+ def _layout(lookup_context, formats)
326
326
  if _conditional_layout?
327
327
  #{layout_definition}
328
328
  else
@@ -388,8 +388,8 @@ module ActionView
388
388
  case name
389
389
  when String then _normalize_layout(name)
390
390
  when Proc then name
391
- when true then Proc.new { |formats| _default_layout(formats, true) }
392
- when :default then Proc.new { |formats| _default_layout(formats, false) }
391
+ when true then Proc.new { |lookup_context, formats| _default_layout(lookup_context, formats, true) }
392
+ when :default then Proc.new { |lookup_context, formats| _default_layout(lookup_context, formats, false) }
393
393
  when false, nil then nil
394
394
  else
395
395
  raise ArgumentError,
@@ -411,9 +411,9 @@ module ActionView
411
411
  #
412
412
  # ==== Returns
413
413
  # * <tt>template</tt> - The template object for the default layout (or +nil+)
414
- def _default_layout(formats, require_layout = false)
414
+ def _default_layout(lookup_context, formats, require_layout = false)
415
415
  begin
416
- value = _layout(formats) if action_has_layout?
416
+ value = _layout(lookup_context, formats) if action_has_layout?
417
417
  rescue NameError => e
418
418
  raise e, "Could not render layout: #{e.message}"
419
419
  end