diff options
author | Aaron Patterson <tenderlove@github.com> | 2019-02-22 12:48:45 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-22 12:48:45 -0800 |
commit | a342d97d576b5b3f0b31155c019006ff59ea76a3 (patch) | |
tree | 732f10f924f2925a5fa235836f19f28e12120982 /actionview | |
parent | fcbf5f4003bf9ea029b0a27fb983d17601c49b23 (diff) | |
parent | 62cb3ee35c5c0d729c54b057c37b8f6bed4dda7f (diff) | |
download | rails-a342d97d576b5b3f0b31155c019006ff59ea76a3.tar.gz rails-a342d97d576b5b3f0b31155c019006ff59ea76a3.tar.bz2 rails-a342d97d576b5b3f0b31155c019006ff59ea76a3.zip |
Merge pull request #35371 from rails/always-have-a-format
Ensure that rendered templates always have a format
Diffstat (limited to 'actionview')
4 files changed, 18 insertions, 7 deletions
diff --git a/actionview/lib/action_view/renderer/abstract_renderer.rb b/actionview/lib/action_view/renderer/abstract_renderer.rb index 200dc3e10e..f1b4c9b92d 100644 --- a/actionview/lib/action_view/renderer/abstract_renderer.rb +++ b/actionview/lib/action_view/renderer/abstract_renderer.rb @@ -28,6 +28,10 @@ module ActionView end class RenderedCollection # :nodoc: + def self.empty(format) + EmptyCollection.new format + end + attr_reader :rendered_templates def initialize(rendered_templates, spacer) @@ -44,11 +48,14 @@ module ActionView end class EmptyCollection - def format; nil; end + attr_reader :format + + def initialize(format) + @format = format + end + def body; nil; end end - - EMPTY = EmptyCollection.new end class RenderedTemplate # :nodoc: diff --git a/actionview/lib/action_view/renderer/partial_renderer.rb b/actionview/lib/action_view/renderer/partial_renderer.rb index 4ae6f635ae..ed8d5cf54e 100644 --- a/actionview/lib/action_view/renderer/partial_renderer.rb +++ b/actionview/lib/action_view/renderer/partial_renderer.rb @@ -326,7 +326,7 @@ module ActionView def render_collection(view, template) identifier = (template && template.identifier) || @path instrument(:collection, identifier: identifier, count: @collection.size) do |payload| - return RenderedCollection::EMPTY if @collection.blank? + return RenderedCollection.empty(@lookup_context.formats.first) if @collection.blank? spacer = if @options.key?(:spacer_template) spacer_template = find_template(@options[:spacer_template], @locals.keys) diff --git a/actionview/lib/action_view/renderer/template_renderer.rb b/actionview/lib/action_view/renderer/template_renderer.rb index b6861d49fe..a129ef0e15 100644 --- a/actionview/lib/action_view/renderer/template_renderer.rb +++ b/actionview/lib/action_view/renderer/template_renderer.rb @@ -29,7 +29,12 @@ module ActionView @lookup_context.with_fallbacks.find_file(options[:file], nil, false, keys, @details) elsif options.key?(:inline) handler = Template.handler_for_extension(options[:type] || "erb") - Template.new(options[:inline], "inline template", handler, locals: keys) + format = if handler.respond_to?(:default_format) + handler.default_format + else + @lookup_context.formats.first + end + Template.new(options[:inline], "inline template", handler, locals: keys, format: format) elsif options.key?(:template) if options[:template].respond_to?(:render) options[:template] diff --git a/actionview/lib/action_view/rendering.rb b/actionview/lib/action_view/rendering.rb index ac861c44d4..e5e2771323 100644 --- a/actionview/lib/action_view/rendering.rb +++ b/actionview/lib/action_view/rendering.rb @@ -118,8 +118,7 @@ module ActionView renderer.render_to_object(context, options) end - rendered_format = rendered_template.format || lookup_context.formats.first - @rendered_format = Template::Types[rendered_format] + @rendered_format = Template::Types[rendered_template.format] rendered_template.body end |