From 4bb9871509fc1d15c28821179923ed8341b140aa Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sun, 15 Mar 2009 14:50:55 -0700 Subject: [PATCH] no reason to use a recusrive proc --- .../lib/active_support/xml_mini/nokogiri.rb | 34 +++++++------------- 1 files changed, 12 insertions(+), 22 deletions(-) diff --git a/activesupport/lib/active_support/xml_mini/nokogiri.rb b/activesupport/lib/active_support/xml_mini/nokogiri.rb index 1028158..10a71a5 100644 --- a/activesupport/lib/active_support/xml_mini/nokogiri.rb +++ b/activesupport/lib/active_support/xml_mini/nokogiri.rb @@ -12,7 +12,7 @@ module ActiveSupport if string.blank? {} else - doc = Nokogiri::XML(string) + doc = Nokogiri::XML(string, nil, nil, Nokogiri::XML::PARSE_NOBLANKS) raise doc.errors.first if doc.errors.length > 0 doc.to_hash end @@ -33,33 +33,23 @@ module ActiveSupport # hash:: # Hash to merge the converted element into. def to_hash(hash = {}) - hash[name] ||= attributes_as_hash + attributes = attributes_as_hash + if hash[name] + hash[name] = [hash[name]].flatten + hash[name] << attributes + else + hash[name] ||= attributes + end - walker = lambda { |memo, parent, child, callback| - next if child.blank? && 'file' != parent['type'] + children.each { |child| + next if child.blank? && 'file' != self['type'] if child.text? - (memo[CONTENT_ROOT] ||= '') << child.content + (attributes[CONTENT_ROOT] ||= '') << child.content next end - - name = child.name - - child_hash = child.attributes_as_hash - if memo[name] - memo[name] = [memo[name]].flatten - memo[name] << child_hash - else - memo[name] = child_hash - end - - # Recusively walk children - child.children.each { |c| - callback.call(child_hash, child, c, callback) - } + child.to_hash(attributes) } - - children.each { |c| walker.call(hash[name], self, c, walker) } hash end -- 1.6.0.4