diff options
author | José Valim <jose.valim@gmail.com> | 2012-01-17 23:31:43 -0800 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2012-01-17 23:31:43 -0800 |
commit | 2de2ea8879a670b40da99c65bd2f520d1fd182af (patch) | |
tree | 5ef821e19b4b9dd03370abd2c6a7b1e3602a565a /actionpack/lib | |
parent | 5b9a506ef6b72c93901e94a0f738c1991f8d5852 (diff) | |
parent | 8470fc9902b97a5341d3afc5cab1a361d21e52de (diff) | |
download | rails-2de2ea8879a670b40da99c65bd2f520d1fd182af.tar.gz rails-2de2ea8879a670b40da99c65bd2f520d1fd182af.tar.bz2 rails-2de2ea8879a670b40da99c65bd2f520d1fd182af.zip |
Merge pull request #4510 from carlosantoniodasilva/av-content-tag-for
ActionView content_tag_for refactoring and improvements
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/helpers/record_tag_helper.rb | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/actionpack/lib/action_view/helpers/record_tag_helper.rb b/actionpack/lib/action_view/helpers/record_tag_helper.rb index b351302d01..1a15459406 100644 --- a/actionpack/lib/action_view/helpers/record_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/record_tag_helper.rb @@ -81,13 +81,11 @@ module ActionView # <li id="person_123" class="person bar">... # def content_tag_for(tag_name, single_or_multiple_records, prefix = nil, options = nil, &block) - if single_or_multiple_records.respond_to?(:to_ary) - single_or_multiple_records.to_ary.map do |single_record| - capture { content_tag_for_single_record(tag_name, single_record, prefix, options, &block) } - end.join("\n").html_safe - else - content_tag_for_single_record(tag_name, single_or_multiple_records, prefix, options, &block) - end + options, prefix = prefix, nil if prefix.is_a?(Hash) + + Array(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 end private @@ -95,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.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 = options ? options.dup : {} + 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 |