diff options
author | José Valim <jose.valim@gmail.com> | 2011-05-01 12:56:04 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-05-01 13:40:13 +0200 |
commit | b73576138529b1344a38f4e4b16c642f3510d514 (patch) | |
tree | af20defc605263df77a2bd22f50103a4c6eacf15 /actionpack/lib/action_view | |
parent | 367bdc53611fe1da9cedda3220a83d3f39409cff (diff) | |
download | rails-b73576138529b1344a38f4e4b16c642f3510d514.tar.gz rails-b73576138529b1344a38f4e4b16c642f3510d514.tar.bz2 rails-b73576138529b1344a38f4e4b16c642f3510d514.zip |
Introduce view renderer.
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/context.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_view/renderer/renderer.rb | 33 | ||||
-rw-r--r-- | actionpack/lib/action_view/rendering.rb | 20 |
3 files changed, 25 insertions, 30 deletions
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 |