diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-03-09 23:35:43 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-03-09 23:35:43 +0000 |
commit | 0c6d1785529ab2f9c86908f03a10c871512311e5 (patch) | |
tree | 544d3d4ad3aa218db856941aa581ab17352fb498 /activesupport/lib/active_support/core_ext/array/conversions.rb | |
parent | d872281975b2bdcfcd06e21b55d78c8fb53ba5d1 (diff) | |
download | rails-0c6d1785529ab2f9c86908f03a10c871512311e5.tar.gz rails-0c6d1785529ab2f9c86908f03a10c871512311e5.tar.bz2 rails-0c6d1785529ab2f9c86908f03a10c871512311e5.zip |
Implemented nested to_xml and named elements for array xmling [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3830 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/core_ext/array/conversions.rb')
-rw-r--r-- | activesupport/lib/active_support/core_ext/array/conversions.rb | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb index 6f83231487..59ea7262f1 100644 --- a/activesupport/lib/active_support/core_ext/array/conversions.rb +++ b/activesupport/lib/active_support/core_ext/array/conversions.rb @@ -29,13 +29,16 @@ module ActiveSupport #:nodoc: def to_xml(options = {}) raise "Not all elements respond to to_xml" unless all? { |e| e.respond_to? :to_xml } - options[:root] ||= all? { |e| e.is_a? first.class } ? first.class.to_s.underscore.pluralize : "records" - options[:indent] ||= 2 - options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent]) + options[:root] ||= all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? first.class.to_s.underscore.pluralize : "records" + options[:children] ||= options[:root].singularize + options[:indent] ||= 2 + options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent]) + + root = options.delete(:root) + children = options.delete(:children) options[:builder].instruct! unless options.delete(:skip_instruct) - root = options.delete(:root) - options[:builder].__send__(root) { each { |e| e.to_xml(options.merge({ :skip_instruct => true })) } } + options[:builder].__send__(root) { each { |e| e.to_xml(options.merge({ :skip_instruct => true, :root => children })) } } end end end |