aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/renderer/template_renderer.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2019-02-13 17:59:21 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2019-02-19 13:46:09 -0800
commit1bc0a59d6ee198fa535c04f32527a1d6228b647d (patch)
treebbdbd9cdef5aebd1878df4ee54b1f6e2cd534ebd /actionview/lib/action_view/renderer/template_renderer.rb
parentd0733ba8c0528aa4bc6e890e189afaac62ebe58f (diff)
downloadrails-1bc0a59d6ee198fa535c04f32527a1d6228b647d.tar.gz
rails-1bc0a59d6ee198fa535c04f32527a1d6228b647d.tar.bz2
rails-1bc0a59d6ee198fa535c04f32527a1d6228b647d.zip
Return rendered template information instead of just strings
This commit introduces "rendered template" and "rendered collection" objects. The template renderers can now return a more complex object than just strings. This allows the framework to get more information about the templates that were rendered. In this commit we use the rendered template object to set the "rendered_format" on the lookup context in the controller rather than all the way in the template renderer. That means we don't need to check the "rendered_format" every time we render a template, we just do it once after all templates have been rendered.
Diffstat (limited to 'actionview/lib/action_view/renderer/template_renderer.rb')
-rw-r--r--actionview/lib/action_view/renderer/template_renderer.rb9
1 files changed, 4 insertions, 5 deletions
diff --git a/actionview/lib/action_view/renderer/template_renderer.rb b/actionview/lib/action_view/renderer/template_renderer.rb
index c36baeffcd..7052fe0961 100644
--- a/actionview/lib/action_view/renderer/template_renderer.rb
+++ b/actionview/lib/action_view/renderer/template_renderer.rb
@@ -10,8 +10,6 @@ module ActionView
prepend_formats(template.formats)
- @lookup_context.rendered_format ||= (template.formats.first || formats.first)
-
render_template(context, template, options[:layout], options[:locals] || {})
end
@@ -46,23 +44,24 @@ module ActionView
# Renders the given template. A string representing the layout can be
# supplied as well.
def render_template(view, template, layout_name, locals)
- render_with_layout(view, layout_name, locals) do |layout|
+ render_with_layout(view, layout_name, template, locals) do |layout|
instrument(:template, identifier: template.identifier, layout: layout.try(:virtual_path)) do
template.render(view, locals) { |*name| view._layout_for(*name) }
end
end
end
- def render_with_layout(view, path, locals)
+ def render_with_layout(view, path, template, locals)
layout = path && find_layout(path, locals.keys, [formats.first])
content = yield(layout)
- if layout
+ body = if layout
view.view_flow.set(:layout, content)
layout.render(view, locals) { |*name| view._layout_for(*name) }
else
content
end
+ build_rendered_template(body, layout, template)
end
# This is the method which actually finds the layout using details in the lookup