Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Introduce view renderer.

  • Loading branch information...
commit b73576138529b1344a38f4e4b16c642f3510d514 1 parent 367bdc5
@josevalim josevalim authored
View
13 actionpack/lib/abstract_controller/rendering.rb
@@ -99,7 +99,12 @@ def initialize(*)
#
# 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 @@ def render_to_body(options = {})
# 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.
View
2  actionpack/lib/action_controller/metal/streaming.rb
@@ -51,7 +51,7 @@ def _process_options(options) #: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
View
2  actionpack/lib/action_view/context.rb
@@ -9,6 +9,8 @@ module CompiledTemplates #:nodoc:
# 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
View
33 actionpack/lib/action_view/renderer/renderer.rb
@@ -10,21 +10,6 @@ def initialize(lookup_context, controller)
@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 @@ def render(context, options = {}, locals = {}, &block)
# 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:
View
20 actionpack/lib/action_view/rendering.rb
@@ -15,13 +15,19 @@ module Rendering
# 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
Please sign in to comment.
Something went wrong with that request. Please try again.