diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-01-17 23:11:55 -0200 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-01-18 00:45:03 -0200 |
commit | dcad38542039154156d79510dbdb1be4a6cfbf76 (patch) | |
tree | ebbdc77a71f246e6a1519320242311a0dc3059f4 | |
parent | ba77ff3c1b583fdacf733404bbf4508042b45656 (diff) | |
download | rails-dcad38542039154156d79510dbdb1be4a6cfbf76.tar.gz rails-dcad38542039154156d79510dbdb1be4a6cfbf76.tar.bz2 rails-dcad38542039154156d79510dbdb1be4a6cfbf76.zip |
Refactor content tag to not detect options Hash always
Only check for options and prefix arguments order once when running
content_tag_for with a collection.
-rw-r--r-- | actionpack/lib/action_view/helpers/record_tag_helper.rb | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/actionpack/lib/action_view/helpers/record_tag_helper.rb b/actionpack/lib/action_view/helpers/record_tag_helper.rb index 8dcead64fb..4cd5fa2ad1 100644 --- a/actionpack/lib/action_view/helpers/record_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/record_tag_helper.rb @@ -81,6 +81,8 @@ module ActionView # <li id="person_123" class="person bar">... # def content_tag_for(tag_name, single_or_multiple_records, prefix = nil, options = nil, &block) + options, prefix = prefix, nil if prefix.is_a?(Hash) + Array.wrap(single_or_multiple_records).map do |single_record| content_tag_for_single_record tag_name, single_record, prefix, options, &block end.join("\n").html_safe @@ -91,14 +93,11 @@ module ActionView # Called by <tt>content_tag_for</tt> internally to render a content tag # for each record. def content_tag_for_single_record(tag_name, record, prefix, options, &block) - options, prefix = prefix, nil if prefix.is_a?(Hash) options = options ? options.dup : {} - options.merge!(:class => "#{dom_class(record, prefix)} #{options[:class]}".strip, :id => dom_id(record, prefix)) - if block.arity == 0 - content_tag(tag_name, capture(&block), options) - else - content_tag(tag_name, capture(record, &block), options) - end + options.merge!(:class => "#{dom_class(record, prefix)} #{options[:class]}".rstrip, :id => dom_id(record, prefix)) + + content = block.arity == 0 ? capture(&block) : capture(record, &block) + content_tag(tag_name, content, options) end end end |