diff options
author | Aaron Patterson <tenderlove@github.com> | 2019-01-23 13:40:24 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-23 13:40:24 -0800 |
commit | c91c71fa154951bde42839b26c9d0f9dd3005fd9 (patch) | |
tree | 3b8aa5457e3da5ac47f55c069a8098126f2a83ab | |
parent | 00650116608620cca16a51027ffc56942ce63645 (diff) | |
parent | 1853b0d0abf87dfdd4c3a277c3badb17ca19652e (diff) | |
download | rails-c91c71fa154951bde42839b26c9d0f9dd3005fd9.tar.gz rails-c91c71fa154951bde42839b26c9d0f9dd3005fd9.tar.bz2 rails-c91c71fa154951bde42839b26c9d0f9dd3005fd9.zip |
Merge pull request #35031 from rails/view-ivar
Pass the view around instead of using an ivar
-rw-r--r-- | actionview/lib/action_view/renderer/streaming_template_renderer.rb | 4 | ||||
-rw-r--r-- | actionview/lib/action_view/renderer/template_renderer.rb | 12 |
2 files changed, 7 insertions, 9 deletions
diff --git a/actionview/lib/action_view/renderer/streaming_template_renderer.rb b/actionview/lib/action_view/renderer/streaming_template_renderer.rb index bb9db21e32..f414620923 100644 --- a/actionview/lib/action_view/renderer/streaming_template_renderer.rb +++ b/actionview/lib/action_view/renderer/streaming_template_renderer.rb @@ -43,14 +43,14 @@ module ActionView # For streaming, instead of rendering a given a template, we return a Body # object that responds to each. This object is initialized with a block # that knows how to render the template. - def render_template(template, layout_name = nil, locals = {}) #:nodoc: + def render_template(view, template, layout_name = nil, locals = {}) #:nodoc: return [super] unless layout_name && template.supports_streaming? locals ||= {} layout = layout_name && find_layout(layout_name, locals.keys, [formats.first]) Body.new do |buffer| - delayed_render(buffer, template, layout, @view, locals) + delayed_render(buffer, template, layout, view, locals) end end diff --git a/actionview/lib/action_view/renderer/template_renderer.rb b/actionview/lib/action_view/renderer/template_renderer.rb index ce8908924a..fb5539e0db 100644 --- a/actionview/lib/action_view/renderer/template_renderer.rb +++ b/actionview/lib/action_view/renderer/template_renderer.rb @@ -5,7 +5,6 @@ require "active_support/core_ext/object/try" module ActionView class TemplateRenderer < AbstractRenderer #:nodoc: def render(context, options) - @view = context @details = extract_details(options) template = determine_template(options) @@ -13,7 +12,7 @@ module ActionView @lookup_context.rendered_format ||= (template.formats.first || formats.first) - render_template(template, options[:layout], options[:locals]) + render_template(context, template, options[:layout], options[:locals]) end private @@ -46,22 +45,21 @@ module ActionView # Renders the given template. A string representing the layout can be # supplied as well. - def render_template(template, layout_name = nil, locals = nil) - view, locals = @view, locals || {} + def render_template(view, template, layout_name = nil, locals = nil) + locals ||= {} - render_with_layout(layout_name, locals) do |layout| + render_with_layout(view, layout_name, 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(path, locals) + def render_with_layout(view, path, locals) layout = path && find_layout(path, locals.keys, [formats.first]) content = yield(layout) if layout - view = @view view.view_flow.set(:layout, content) layout.render(view, locals) { |*name| view._layout_for(*name) } else |