diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 306bd41e2d..db6ff41f55 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -99,7 +99,12 @@ module AbstractController # # Override this method in a module to change the default behavior. def view_context - view_context_class.new(lookup_context, view_assigns, self) + view_context_class.new(view_renderer, view_assigns, self) + end + + # Returns an object that is able to render templates. + def view_renderer + @view_renderer ||= ActionView::Renderer.new(lookup_context, self) end # Normalize arguments, options and then delegates render_to_body and @@ -127,7 +132,11 @@ module AbstractController # Find and renders a template based on the options given. # :api: private def _render_template(options) #:nodoc: - view_context.render(options) + if options.key?(:partial) + view_renderer.render_partial(view_context, options) + else + view_renderer.render_template(view_context, options) + end end # The prefixes used in render "foo" shortcuts. diff --git a/actionpack/lib/action_controller/metal/streaming.rb b/actionpack/lib/action_controller/metal/streaming.rb index b9bd49f670..5b8111f30d 100644 --- a/actionpack/lib/action_controller/metal/streaming.rb +++ b/actionpack/lib/action_controller/metal/streaming.rb @@ -51,7 +51,7 @@ module ActionController #:nodoc: # Call render_to_body if we are streaming instead of usual +render+. def _render_template(options) #:nodoc: if options.delete(:stream) - Rack::Chunked::Body.new view_context.render_body(options) + Rack::Chunked::Body.new view_renderer.render_body(view_context, options) else super end diff --git a/actionpack/lib/action_view/context.rb b/actionpack/lib/action_view/context.rb index c4bebd7d95..01be294284 100644 --- a/actionpack/lib/action_view/context.rb +++ b/actionpack/lib/action_view/context.rb @@ -9,6 +9,8 @@ module ActionView # The default Action View context is ActionView::Base. # # In order to work with ActionController, a Context must just include this module. + # The initialization of the variables used by the context (@output_buffer, @view_flow, + # and @virtual_path) is responsibility of the object that includes this module. module Context include CompiledTemplates attr_accessor :output_buffer, :view_flow diff --git a/actionpack/lib/action_view/renderer/renderer.rb b/actionpack/lib/action_view/renderer/renderer.rb index 582ed2f9f8..3c0126f6bb 100644 --- a/actionpack/lib/action_view/renderer/renderer.rb +++ b/actionpack/lib/action_view/renderer/renderer.rb @@ -10,21 +10,6 @@ module ActionView @controller = controller end - def render(context, options = {}, locals = {}, &block) - case options - when Hash - if block_given? - _render_partial(context, options.merge(:partial => options[:layout]), &block) - elsif options.key?(:partial) - _render_partial(context, options) - else - _render_template(context, options) - end - else - _render_partial(context, :partial => options, :locals => locals) - end - end - # Render but returns a valid Rack body. If fibers are defined, we return # a streaming body that renders the template piece by piece. # @@ -32,24 +17,26 @@ module ActionView # so in such cases, we just wrap them in an array. def render_body(context, options) if options.key?(:partial) - [_render_partial(context, options)] + [render_partial(context, options)] else StreamingTemplateRenderer.new(@lookup_context, @controller).render(context, options) end end - private - - def _render_template(context, options) #:nodoc: + # Direct accessor to template rendering. + def render_template(context, options) #:nodoc: _template_renderer.render(context, options) end - def _template_renderer #:nodoc: - @_template_renderer ||= TemplateRenderer.new(@lookup_context, @controller) + # Direct access to partial rendering. + def render_partial(context, options, &block) #:nodoc: + _partial_renderer.render(context, options, block) end - def _render_partial(context, options, &block) #:nodoc: - _partial_renderer.render(context, options, block) + private + + def _template_renderer #:nodoc: + @_template_renderer ||= TemplateRenderer.new(@lookup_context, @controller) end def _partial_renderer #:nodoc: diff --git a/actionpack/lib/action_view/rendering.rb b/actionpack/lib/action_view/rendering.rb index 2f420dc992..25ec450e6e 100644 --- a/actionpack/lib/action_view/rendering.rb +++ b/actionpack/lib/action_view/rendering.rb @@ -15,13 +15,19 @@ module ActionView # If no options hash is passed or :update specified, the default is to render a partial and use the second parameter # as the locals hash. # def render(options = {}, locals = {}, &block) - def render(*args, &block) - view_renderer.render(self, *args, &block) - end - - # TODO: This is temporary, but the previous render is sticking. - def render_body(*args, &block) - view_renderer.render_body(self, *args, &block) + def render(options = {}, locals = {}, &block) + case options + when Hash + if block_given? + view_renderer.render_partial(self, options.merge(:partial => options[:layout]), &block) + elsif options.key?(:partial) + view_renderer.render_partial(self, options) + else + view_renderer.render_template(self, options) + end + else + view_renderer.render_partial(self, :partial => options, :locals => locals) + end end end end \ No newline at end of file