Permalink
Browse files

Some more AV work:

  * rename _render_partial to _render_partial_unknown_type to reflect that for this call, 
  	we don't know the type.
  * Merge _render_partial_with_block and _render_partial_with_layout to _render_partial
    * TODO: Check to see if any more logic can be shared
    * TODO: See about streamlining block path so we can get rid of @_proc_for_layout
  * Remove @exempt_from_layout as it is no longer needed
  • Loading branch information...
1 parent 0612fd0 commit 59e475e3a66fe647ea74f4daf472d82bc9b4535c @wycats wycats committed Aug 7, 2009
Showing with 25 additions and 26 deletions.
  1. +18 −15 actionpack/lib/action_view/render/partials.rb
  2. +7 −11 actionpack/lib/action_view/render/rendering.rb
@@ -185,10 +185,10 @@ def _partial_names
def render_partial(options)
@assigns_added = false
- _render_partial(options)
+ _render_partial_unknown_type(options)
end
- def _render_partial(options) #:nodoc:
+ def _render_partial_unknown_type(options) #:nodoc:
options[:locals] ||= {}
path = partial = options[:partial]
@@ -220,19 +220,21 @@ def _partial_path(object)
end
end
- def _render_partial_with_block(layout, block, options)
- @_proc_for_layout = block
- concat(_render_partial(options.merge(:partial => layout)))
- ensure
- @_proc_for_layout = nil
- end
-
- def _render_partial_with_layout(layout, options)
- if layout
- prefix = layout.include?(?/) ? nil : controller_path
- layout = find_by_parts(layout, {:formats => formats}, prefix, true)
+ def _render_partial(layout, options, block = nil)
+ if block
+ begin
+ @_proc_for_layout = block
+ concat(_render_partial_unknown_type(options.merge(:partial => layout)))
+ ensure
+ @_proc_for_layout = nil
+ end
+ else
+ if layout
+ prefix = layout.include?(?/) ? nil : controller_path
+ layout = find_by_parts(layout, {:formats => formats}, prefix, true)
+ end
+ _render_content(_render_partial_unknown_type(options), layout, options[:locals])
end
- _render_content(_render_partial(options), layout, options[:locals])
end
def _render_partial_object(template, options)
@@ -260,7 +262,8 @@ def _set_locals(object, locals, template, options)
def _render_partial_collection(collection, options = {}, passed_template = nil) #:nodoc:
return nil if collection.blank?
- spacer = options[:spacer_template] ? _render_partial(:partial => options[:spacer_template]) : ''
+ spacer = options[:spacer_template] ?
+ _render_partial_unknown_type(:partial => options[:spacer_template]) : ''
locals = (options[:locals] ||= {})
index, @_partial_path = 0, nil
@@ -10,33 +10,29 @@ module Rendering
#
# 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 = {}, local_assigns = {}, &block) #:nodoc:
- local_assigns ||= {}
-
- @exempt_from_layout = true
-
+ def render(options = {}, locals = {}, &block) #:nodoc:
case options
+ when String, NilClass
+ _render_partial_unknown_type(:partial => options, :locals => locals || {})
when Hash
- options[:locals] ||= {}
layout = options[:layout]
- return _render_partial_with_layout(layout, options) if options.key?(:partial)
- return _render_partial_with_block(layout, block, options) if block_given?
+ if options.key?(:partial) || block_given?
+ return _render_partial(layout, options, block)
+ end
layout = find_by_parts(layout, {:formats => formats}) if layout
if file = options[:file]
template = find_by_parts(file, {:formats => formats})
- _render_template(template, layout, :locals => options[:locals])
+ _render_template(template, layout, :locals => options[:locals] || {})
elsif inline = options[:inline]
_render_inline(inline, layout, options)
elsif text = options[:text]
_render_text(text, layout, options)
end
when :update
update_page(&block)
- when String, NilClass
- _render_partial(:partial => options, :locals => local_assigns)
end
end

0 comments on commit 59e475e

Please sign in to comment.