aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-05-01 12:56:04 +0200
committerJosé Valim <jose.valim@gmail.com>2011-05-01 13:40:13 +0200
commitb73576138529b1344a38f4e4b16c642f3510d514 (patch)
treeaf20defc605263df77a2bd22f50103a4c6eacf15
parent367bdc53611fe1da9cedda3220a83d3f39409cff (diff)
downloadrails-b73576138529b1344a38f4e4b16c642f3510d514.tar.gz
rails-b73576138529b1344a38f4e4b16c642f3510d514.tar.bz2
rails-b73576138529b1344a38f4e4b16c642f3510d514.zip
Introduce view renderer.
-rw-r--r--actionpack/lib/abstract_controller/rendering.rb13
-rw-r--r--actionpack/lib/action_controller/metal/streaming.rb2
-rw-r--r--actionpack/lib/action_view/context.rb2
-rw-r--r--actionpack/lib/action_view/renderer/renderer.rb33
-rw-r--r--actionpack/lib/action_view/rendering.rb20
5 files changed, 37 insertions, 33 deletions
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