aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/render/rendering.rb
diff options
context:
space:
mode:
authorYehuda Katz <wycats@gmail.com>2009-08-07 05:40:01 -0300
committerYehuda Katz <wycats@gmail.com>2009-08-07 05:40:01 -0300
commit493d84ce2f1e25081a394fd70ac4e23b6a2be682 (patch)
tree5116c84591ac3ba074cfba406ca92c58dcf33779 /actionpack/lib/action_view/render/rendering.rb
parent59e475e3a66fe647ea74f4daf472d82bc9b4535c (diff)
downloadrails-493d84ce2f1e25081a394fd70ac4e23b6a2be682.tar.gz
rails-493d84ce2f1e25081a394fd70ac4e23b6a2be682.tar.bz2
rails-493d84ce2f1e25081a394fd70ac4e23b6a2be682.zip
Modify various partial methods to carry along the block that can be passed in with render
* _render_single_template, which renders a template without layout * _render_partial_unknown_type, which renders a partial of unknown type (the entry method for most partial rendering; supports strings, objects, and collections) * _render_partial_object, which renders a partial for a single object. * extracted _render_partial_path so it can be used to render the spacer without going through the public render :partial
Diffstat (limited to 'actionpack/lib/action_view/render/rendering.rb')
-rw-r--r--actionpack/lib/action_view/render/rendering.rb33
1 files changed, 23 insertions, 10 deletions
diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb
index 0a5953be88..a721ade4e1 100644
--- a/actionpack/lib/action_view/render/rendering.rb
+++ b/actionpack/lib/action_view/render/rendering.rb
@@ -18,7 +18,7 @@ module ActionView
layout = options[:layout]
if options.key?(:partial) || block_given?
- return _render_partial(layout, options, block)
+ return _render_partial(layout, options, &block)
end
layout = find_by_parts(layout, {:formats => formats}) if layout
@@ -56,10 +56,10 @@ module ActionView
end
end
- # You can think of a layout as a method that is called with a block. This method
- # returns the block that the layout is called with. If the user calls yield :some_name,
- # the block, by default, returns content_for(:some_name). If the user calls yield,
- # the default block returns content_for(:layout).
+ # You can think of a layout as a method that is called with a block. _layout_for
+ # returns the contents that are yielded to the layout. If the user calls yield
+ # :some_name, the block, by default, returns content_for(:some_name). If the user
+ # calls yield, the default block returns content_for(:layout).
#
# The user can override this default by passing a block to the layout.
#
@@ -88,15 +88,28 @@ module ActionView
# In this case, the layout would receive the block passed into <tt>render :layout</tt>,
# and the Struct specified in the layout would be passed into the block. The result
# would be <html>Hello David</html>.
- def layout_proc(name)
- @_default_layout ||= proc { |*names| @_content_for[names.first || :layout] }
- !@_content_for.key?(name) && @_proc_for_layout || @_default_layout
+ def _layout_for(names, &block)
+ with_output_buffer do
+ # This is due to the potentially ambiguous use of yield when
+ # a block is passed in to a template *and* there is a content_for()
+ # of the same name. Suggested solution: require explicit use of content_for
+ # in these ambiguous cases.
+ #
+ # We would be able to continue supporting yield in all non-ambiguous
+ # cases. Question: should we deprecate yield in favor of content_for
+ # and reserve yield for cases where there is a yield into a real block?
+ if @_content_for.key?(names.first) || !block_given?
+ return @_content_for[names.first || :layout]
+ else
+ return yield(names)
+ end
+ end
end
- def _render_single_template(template, locals = {})
+ def _render_single_template(template, locals = {}, &block)
with_template(template) do
template.render(self, locals) do |*names|
- capture(*names, &layout_proc(names.first))
+ _layout_for(names, &block)
end
end
rescue Exception => e