diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-03-10 20:45:14 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-03-10 22:11:15 -0700 |
commit | b9e021df974217b9c6ee273bd6c98b40ebde0cd3 (patch) | |
tree | 617537e481d5a2a2beaffc992679e3747676de9e /activesupport/lib/active_support/xml_mini/nokogiri.rb | |
parent | fa45540cdb30cee44983c9121e3ebfc317d21668 (diff) | |
download | rails-b9e021df974217b9c6ee273bd6c98b40ebde0cd3.tar.gz rails-b9e021df974217b9c6ee273bd6c98b40ebde0cd3.tar.bz2 rails-b9e021df974217b9c6ee273bd6c98b40ebde0cd3.zip |
adding more nokogiri tests and making the main rails tests pass
[#2190 state:resolved]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activesupport/lib/active_support/xml_mini/nokogiri.rb')
-rw-r--r-- | activesupport/lib/active_support/xml_mini/nokogiri.rb | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/activesupport/lib/active_support/xml_mini/nokogiri.rb b/activesupport/lib/active_support/xml_mini/nokogiri.rb index 5c8a6bfe89..10281584fc 100644 --- a/activesupport/lib/active_support/xml_mini/nokogiri.rb +++ b/activesupport/lib/active_support/xml_mini/nokogiri.rb @@ -1,3 +1,5 @@ +require 'nokogiri' + # = XmlMini Nokogiri implementation module ActiveSupport module XmlMini_Nokogiri #:nodoc: @@ -10,7 +12,9 @@ module ActiveSupport if string.blank? {} else - Nokogiri::XML(string).to_hash + doc = Nokogiri::XML(string) + raise doc.errors.first if doc.errors.length > 0 + doc.to_hash end end @@ -31,8 +35,8 @@ module ActiveSupport def to_hash(hash = {}) hash[name] ||= attributes_as_hash - walker = lambda { |child, memo, callback| - next if child.blank? + walker = lambda { |memo, parent, child, callback| + next if child.blank? && 'file' != parent['type'] if child.text? (memo[CONTENT_ROOT] ||= '') << child.content @@ -41,18 +45,21 @@ module ActiveSupport name = child.name + child_hash = child.attributes_as_hash if memo[name] memo[name] = [memo[name]].flatten - memo[name] << child.attributes_as_hash + memo[name] << child_hash else - memo[name] = child.attributes_as_hash + memo[name] = child_hash end # Recusively walk children - child.children.each { |c| callback.call(c, memo[name], callback) } + child.children.each { |c| + callback.call(child_hash, child, c, callback) + } } - children.each { |c| walker.call(c, hash[name], walker) } + children.each { |c| walker.call(hash[name], self, c, walker) } hash end |