From 01129534cde293e3561dd7cc3cb5ae9ac3de9e8c Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Fri, 22 May 2009 12:28:40 -0700 Subject: Cleaned up the #render_to_body chain by extracting determining the templates to render to a separate hook point. --- .../lib/action_controller/abstract/layouts.rb | 4 ---- .../lib/action_controller/abstract/renderer.rb | 24 ++++++++++++++-------- .../lib/action_controller/new_base/renderer.rb | 24 ++++++++++++++-------- 3 files changed, 30 insertions(+), 22 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/abstract/layouts.rb b/actionpack/lib/action_controller/abstract/layouts.rb index 557d68d866..dec394a021 100644 --- a/actionpack/lib/action_controller/abstract/layouts.rb +++ b/actionpack/lib/action_controller/abstract/layouts.rb @@ -57,10 +57,6 @@ module AbstractController end end end - - def _render_template(template, options) - _action_view._render_template_from_controller(template, options[:_layout], options, options[:_partial]) - end private diff --git a/actionpack/lib/action_controller/abstract/renderer.rb b/actionpack/lib/action_controller/abstract/renderer.rb index f2044a35ec..d7c68549e1 100644 --- a/actionpack/lib/action_controller/abstract/renderer.rb +++ b/actionpack/lib/action_controller/abstract/renderer.rb @@ -33,16 +33,12 @@ module AbstractController # # :api: plugin def render_to_body(options = {}) - name = options[:_template_name] || action_name - # TODO: Refactor so we can just use the normal template logic for this if options[:_partial_object] _action_view._render_partial_from_controller(options) - else - options[:_template] ||= view_paths.find_by_parts(name.to_s, {:formats => formats}, - options[:_prefix], options[:_partial]) - - _render_template(options[:_template], options) + else + _determine_template(options) + _render_template(options) end end @@ -56,8 +52,8 @@ module AbstractController AbstractController::Renderer.body_to_s(render_to_body(options)) end - def _render_template(template, options) - _action_view._render_template_from_controller(template, nil, options, options[:_partial]) + def _render_template(options) + _action_view._render_template_from_controller(options[:_template], options[:_layout], options, options[:_partial]) end def view_paths() _view_paths end @@ -74,6 +70,16 @@ module AbstractController end end + private + + def _determine_template(options) + name = (options[:_template_name] || action_name).to_s + + options[:_template] ||= view_paths.find_by_parts( + name, { :formats => formats }, options[:_prefix], options[:_partial] + ) + end + module ClassMethods def append_view_path(path) diff --git a/actionpack/lib/action_controller/new_base/renderer.rb b/actionpack/lib/action_controller/new_base/renderer.rb index 59df3c51da..987751a601 100644 --- a/actionpack/lib/action_controller/new_base/renderer.rb +++ b/actionpack/lib/action_controller/new_base/renderer.rb @@ -27,6 +27,20 @@ module ActionController def render_to_body(options) _process_options(options) + if options.key?(:partial) + _render_partial(options[:partial], options) + end + + super + end + + private + + def _prefix + controller_path + end + + def _determine_template(options) if options.key?(:text) options[:_template] = ActionView::TextTemplate.new(options[:text], formats.first) elsif options.key?(:inline) @@ -37,21 +51,13 @@ module ActionController options[:_template_name] = options[:template] elsif options.key?(:file) options[:_template_name] = options[:file] - elsif options.key?(:partial) - _render_partial(options[:partial], options) - else + elsif !options.key?(:partial) options[:_template_name] = (options[:action] || action_name).to_s options[:_prefix] = _prefix end super end - - private - - def _prefix - controller_path - end def _render_partial(partial, options) case partial -- cgit v1.2.3