Permalink
Browse files

Continue reworking the partial path.

  * TODO: Review ActionController calling render_template for certain partials.
    Might we be able to save logic by always delegating to AV's render_partial?
  • Loading branch information...
1 parent 493d84c commit d94ba11295c74e5a661a78a93d6d0259ab01fa50 @wycats wycats committed Aug 7, 2009
Showing with 22 additions and 47 deletions.
  1. +16 −44 actionpack/lib/action_view/render/partials.rb
  2. +6 −3 actionpack/lib/action_view/render/rendering.rb
@@ -185,10 +185,10 @@ def _partial_names
def render_partial(options)
@assigns_added = false
- _render_partial_unknown_type(options)
+ _render_partial(options)
end
- def _render_partial_unknown_type(options, &block) #:nodoc:
+ def _render_partial(options, &block) #:nodoc:
options[:locals] ||= {}
path = partial = options[:partial]
@@ -200,21 +200,10 @@ def _render_partial_unknown_type(options, &block) #:nodoc:
path = _partial_path(object)
end
- _render_partial_path(path, options, &block)
+ _render_partial_object(_pick_partial_template(path), options, &block)
end
private
- def _render_partial_path(path, options, &block)
- return '' if path.nil?
-
- parts = [path, {:formats => formats}]
- parts.push path.include?(?/) ? nil : controller_path
- parts.push true
-
- template = find_by_parts(*parts)
- _render_partial_object(template, options, &block)
- end
-
def _partial_path(object)
self.class._partial_names[[controller.class, object.class]] ||= begin
name = object.class.model_name
@@ -226,62 +215,45 @@ def _partial_path(object)
end
end
- def _render_partial(layout, options, &block)
- if block_given?
- concat(_render_partial_unknown_type(options.merge(:partial => layout), &block))
- 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
+ def _render_partial_template(template, locals, object, options = {}, &block)
+ options[:_template] = template
+ locals[:object] = locals[template.variable_name] = object
+ locals[options[:as]] = object if options[:as]
+
+ _render_single_template(template, locals, &block)
end
def _render_partial_object(template, options, &block)
- object = options[:object]
-
if options.key?(:collection)
_render_partial_collection(options.delete(:collection), options, template, &block)
else
locals = (options[:locals] ||= {})
- object ||= locals[:object] || locals[template.variable_name]
-
- _set_locals(object, locals, template, options)
-
- options[:_template] = template
+ object = options[:object] || locals[:object] || locals[template.variable_name]
- _render_single_template(template, locals, &block)
+ _render_partial_template(template, locals, object, options, &block)
end
end
- def _set_locals(object, locals, template, options)
- locals[:object] = locals[template.variable_name] = object
- locals[options[:as]] = object if options[:as]
- end
-
def _render_partial_collection(collection, options = {}, template = nil, &block) #:nodoc:
return nil if collection.blank?
- spacer = _render_partial_path(options[:spacer_template], {})
+ if options.key?(:spacer_template)
+ spacer = _render_partial(:partial => options[:spacer_template])
+ end
locals, index = options[:locals] || {}, 0
collection.map do |object|
tmp = template || _pick_partial_template(_partial_path(object))
- options[:_template] = tmp
-
- _set_locals(object, locals, tmp, options)
locals[tmp.counter_name] = index
-
index += 1
- _render_single_template(tmp, locals, &block)
+ _render_partial_template(tmp, locals, object, options, &block)
end.join(spacer)
end
def _pick_partial_template(partial_path) #:nodoc:
- prefix = controller_path unless partial_path.include?('/')
+ prefix = controller_path unless partial_path.include?(?/)
find_by_parts(partial_path, {:formats => formats}, prefix, true)
end
end
@@ -13,12 +13,15 @@ module Rendering
def render(options = {}, locals = {}, &block) #:nodoc:
case options
when String, NilClass
- _render_partial_unknown_type(:partial => options, :locals => locals || {})
+ _render_partial(:partial => options, :locals => locals || {})
when Hash
layout = options[:layout]
- if options.key?(:partial) || block_given?
- return _render_partial(layout, options, &block)
+ if block_given?
+ return concat(_render_partial(options.merge(:partial => layout), &block))
+ elsif options.key?(:partial)
+ layout = _pick_partial_template(layout) if layout
+ return _render_content(_render_partial(options), layout, options[:locals])
end
layout = find_by_parts(layout, {:formats => formats}) if layout

0 comments on commit d94ba11

Please sign in to comment.