diff options
author | Yehuda Katz <wycats@gmail.com> | 2009-08-07 11:33:54 -0300 |
---|---|---|
committer | Yehuda Katz <wycats@gmail.com> | 2009-08-07 11:33:54 -0300 |
commit | bfe58ac05d4b7ba5d5c04c3aa9a719e340b2111e (patch) | |
tree | b0551d64290678ecf8d0ab02a8b7b89607ccfa14 | |
parent | 606e950ccbd02a10f724c73543575a2a4e1ed8cb (diff) | |
download | rails-bfe58ac05d4b7ba5d5c04c3aa9a719e340b2111e.tar.gz rails-bfe58ac05d4b7ba5d5c04c3aa9a719e340b2111e.tar.bz2 rails-bfe58ac05d4b7ba5d5c04c3aa9a719e340b2111e.zip |
Get all ActionController partial rendering to use ActionView's partial code. Consequences:
* It is not possible to always pre-determine the layout before going to ActionView.
This was *already* broken for render :partial => @object, :layout => true. This is
now handled by overriding render_to_body in layouts.rb and manually injecting the
partial's response. This needs to be done in ActionController since ActionController
knows enough to get _layout_for_option. There is probably a better abstraction here.
* As a result, all partial rendering can correctly restrict their layouts to the mime
type of the rendered partial. This could have previously caused a bug in some edge cases.
* If other layout-like options are added, they might need to add special code for the
case of render :partial. We should try to think of an alternate solution, if possible,
but this works for the cases we know of now.
-rw-r--r-- | actionpack/lib/abstract_controller/layouts.rb | 16 | ||||
-rw-r--r-- | actionpack/lib/abstract_controller/renderer.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/metal/renderer.rb | 15 | ||||
-rw-r--r-- | actionpack/lib/action_view/render/partials.rb | 4 |
4 files changed, 23 insertions, 14 deletions
diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb index f021dd8b62..038598a3b3 100644 --- a/actionpack/lib/abstract_controller/layouts.rb +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -88,6 +88,22 @@ module AbstractController end end + def render_to_body(options = {}) + response = super + + if options.key?(:partial) + # This is a little bit messy. We need to explicitly handle partial + # layouts here since the core lookup logic is in the view, but + # we need to determine the layout based on the controller + if options.key?(:layout) + layout = _layout_for_option(options[:layout], options[:_template].details) + response = layout.render(view_context, options[:locals]) { response } + end + end + + response + end + private # This will be overwritten by _write_layout_method def _layout(details) end diff --git a/actionpack/lib/abstract_controller/renderer.rb b/actionpack/lib/abstract_controller/renderer.rb index 73e6b2a4dc..da57d0ff4d 100644 --- a/actionpack/lib/abstract_controller/renderer.rb +++ b/actionpack/lib/abstract_controller/renderer.rb @@ -54,7 +54,7 @@ module AbstractController # :api: plugin def render_to_body(options = {}) # TODO: Refactor so we can just use the normal template logic for this - if options.key?(:_partial_object) + if options.key?(:partial) view_context.render_partial(options) else _determine_template(options) diff --git a/actionpack/lib/action_controller/metal/renderer.rb b/actionpack/lib/action_controller/metal/renderer.rb index 5a458764ad..31ba7e582a 100644 --- a/actionpack/lib/action_controller/metal/renderer.rb +++ b/actionpack/lib/action_controller/metal/renderer.rb @@ -22,7 +22,8 @@ module ActionController _process_options(options) if options.key?(:partial) - _render_partial(options[:partial], options) + options[:partial] = action_name if options[:partial] == true + options[:_details] = {:formats => formats} end super @@ -53,18 +54,6 @@ module ActionController end def _render_partial(partial, options) - case partial - when true - options[:_prefix] = _prefix - when String - options[:_prefix] = _prefix unless partial.include?(?/) - options[:_template_name] = partial - else - options[:_partial_object] = true - return - end - - options[:_partial] = options[:object] || true end def _process_options(options) diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb index b7b14e9007..48cba9c02b 100644 --- a/actionpack/lib/action_view/render/partials.rb +++ b/actionpack/lib/action_view/render/partials.rb @@ -185,6 +185,8 @@ module ActionView def render_partial(options) @assigns_added = false + # TODO: Handle other details here. + self.formats = options[:_details][:formats] _render_partial(options) end @@ -235,6 +237,8 @@ module ActionView end def _render_partial_collection(collection, options = {}, template = nil, &block) #:nodoc: + options[:_template] ||= template + return nil if collection.blank? if options.key?(:spacer_template) |