mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Optimize <%= render(@posts) %>.
This commit is contained in:
parent
c86424a72d
commit
ff1a1c0b4d
1 changed files with 14 additions and 4 deletions
|
@ -233,7 +233,17 @@ module ActionView
|
||||||
spacer = find_template(@options[:spacer_template]).render(@view, @locals)
|
spacer = find_template(@options[:spacer_template]).render(@view, @locals)
|
||||||
end
|
end
|
||||||
|
|
||||||
result = template ? collection_with_template(template) : collection_without_template
|
result = if template
|
||||||
|
collection_with_template(template)
|
||||||
|
else
|
||||||
|
paths = @collection.map { |o| partial_path(o) }
|
||||||
|
|
||||||
|
if paths.uniq.size == 1
|
||||||
|
collection_with_template(find_template(paths.first))
|
||||||
|
else
|
||||||
|
collection_without_template(paths)
|
||||||
|
end
|
||||||
|
end
|
||||||
result.join(spacer).html_safe!
|
result.join(spacer).html_safe!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -254,12 +264,12 @@ module ActionView
|
||||||
segments
|
segments
|
||||||
end
|
end
|
||||||
|
|
||||||
def collection_without_template
|
def collection_without_template(collection_paths)
|
||||||
segments, locals, as = [], @locals, @options[:as]
|
segments, locals, as = [], @locals, @options[:as]
|
||||||
index, template = -1, nil
|
index, template = -1, nil
|
||||||
|
|
||||||
@collection.each do |object|
|
@collection.each_with_index do |object, i|
|
||||||
template = find_template(partial_path(object))
|
template = find_template(collection_paths[i])
|
||||||
locals[template.counter_name] = (index += 1)
|
locals[template.counter_name] = (index += 1)
|
||||||
locals[template.variable_name] = object
|
locals[template.variable_name] = object
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue