diff options
author | José Valim <jose.valim@gmail.com> | 2010-05-15 21:55:03 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-05-15 21:55:03 +0200 |
commit | f055bc05d515b80c89b99b775546b954f270bc5c (patch) | |
tree | 18f0a018a5fec547110af7c38b6b390ba8be1dea /actionpack | |
parent | c5537c1158c91e3244d24751b1e86290b136dc09 (diff) | |
download | rails-f055bc05d515b80c89b99b775546b954f270bc5c.tar.gz rails-f055bc05d515b80c89b99b775546b954f270bc5c.tar.bz2 rails-f055bc05d515b80c89b99b775546b954f270bc5c.zip |
Optimize the code added in fa99de0bd054576336c9
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/render/partials.rb | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb index 5d266c46bf..85f67d4f14 100644 --- a/actionpack/lib/action_view/render/partials.rb +++ b/actionpack/lib/action_view/render/partials.rb @@ -241,16 +241,21 @@ module ActionView end def collection_with_template(template = @template) - segments, locals, as, template = [], @locals, @options[:as] || @template.variable_name, @template + segments, locals, template = [], @locals, @template - counter_name = template.counter_name - locals[counter_name] = -1 + if @options[:as] + as = @options[:as] + counter = "#{as}_counter".to_sym + else + as = template.variable_name + counter = template.counter_name + end + + locals[counter] = -1 @collection.each do |object| - locals[counter_name] += 1 - locals["#{as.to_s}_counter".to_sym] = locals[counter_name] if as + locals[counter] += 1 locals[as] = object - segments << template.render(@view, locals) end @@ -258,13 +263,18 @@ module ActionView end def collection_without_template(collection_paths = @collection_paths) - segments, locals, as = [], @locals, @options[:as] - index, template = -1, nil + segments, locals = [], @locals + index, template = -1, nil + + if @options[:as] + as = @options[:as] + counter = "#{as}_counter" + end @collection.each_with_index do |object, i| template = find_template(collection_paths[i]) - locals[template.counter_name] = (index += 1) locals[as || template.variable_name] = object + locals[counter || template.counter_name] = (index += 1) segments << template.render(@view, locals) end |