diff options
author | Michael Koziarski <michael@koziarski.com> | 2006-11-02 20:10:53 +0000 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2006-11-02 20:10:53 +0000 |
commit | ea433f15bf98a426239e985220393f63fa6d56c3 (patch) | |
tree | 162f6a35eab6750a5ecd98855d72ae018106a7cb /activesupport/lib/active_support/vendor | |
parent | a8bb66ace849ecd2516a4ff3488eb339093b8774 (diff) | |
download | rails-ea433f15bf98a426239e985220393f63fa6d56c3.tar.gz rails-ea433f15bf98a426239e985220393f63fa6d56c3.tar.bz2 rails-ea433f15bf98a426239e985220393f63fa6d56c3.zip |
update XmlSimple to 1.0.10. Closes #6532. [nicksieger]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5414 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/vendor')
-rw-r--r-- | activesupport/lib/active_support/vendor/xml_simple.rb | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/activesupport/lib/active_support/vendor/xml_simple.rb b/activesupport/lib/active_support/vendor/xml_simple.rb index e6ce63a839..ec07966ff9 100644 --- a/activesupport/lib/active_support/vendor/xml_simple.rb +++ b/activesupport/lib/active_support/vendor/xml_simple.rb @@ -1,20 +1,21 @@ # = XmlSimple # # Author:: Maik Schmidt <contact@maik-schmidt.de> -# Copyright:: Copyright (c) 2003 Maik Schmidt +# Copyright:: Copyright (c) 2003-2006 Maik Schmidt # License:: Distributes under the same terms as Ruby. # require 'rexml/document' +require 'stringio' # Easy API to maintain XML (especially configuration files). -class XmlSimple #:nodoc: +class XmlSimple include REXML - @@VERSION = '1.0.2' + @@VERSION = '1.0.9' # A simple cache for XML documents that were already transformed # by xml_in. - class Cache #:nodoc: + class Cache # Creates and initializes a new Cache object. def initialize @mem_share_cache = {} @@ -184,7 +185,7 @@ class XmlSimple #:nodoc: @doc = load_xml_file(filename) end - elsif string.kind_of?(IO) + elsif string.kind_of?(IO) || string.kind_of?(StringIO) @doc = parse(string.readlines.to_s) else raise ArgumentError, "Could not parse object of type: <#{string.type}>." @@ -266,7 +267,7 @@ class XmlSimple #:nodoc: keyattr keeproot forcecontent contentkey noattr searchpath forcearray suppressempty anonymoustag cache grouptags normalisespace normalizespace - variables varattr + variables varattr keytosymbol ), 'out' => %w( keyattr keeproot contentkey noattr rootname @@ -283,6 +284,7 @@ class XmlSimple #:nodoc: DEF_ANONYMOUS_TAG = 'anon' DEF_FORCE_ARRAY = true DEF_INDENTATION = ' ' + DEF_KEY_TO_SYMBOL = false # Normalizes option names in a hash, i.e., turns all # characters to lower case and removes all underscores. @@ -350,6 +352,8 @@ class XmlSimple #:nodoc: @options['xmldeclaration'] = DEF_XML_DECLARATION end + @options['keytosymbol'] = DEF_KEY_TO_SYMBOL unless @options.has_key?('keytosymbol') + if @options.has_key?('contentkey') if @options['contentkey'] =~ /^-(.*)$/ @options['contentkey'] = $1 @@ -654,6 +658,14 @@ class XmlSimple #:nodoc: end end end + + #patch for converting keys to symbols + if @options.has_key?('keytosymbol') + if @options['keytosymbol'] == true + key = key.to_s.downcase.to_sym + end + end + if hash.has_key?(key) if hash[key].instance_of?(Array) hash[key] << value @@ -879,14 +891,7 @@ class XmlSimple #:nodoc: # data:: # The string to be escaped. def escape_value(data) - return data if data.nil? || data == '' - result = data.dup - result.gsub!('&', '&') - result.gsub!('<', '<') - result.gsub!('>', '>') - result.gsub!('"', '"') - result.gsub!("'", ''') - result + Text::normalize(data) end # Removes leading and trailing whitespace and sequences of @@ -895,10 +900,7 @@ class XmlSimple #:nodoc: # text:: # String to be normalised. def normalise_space(text) - text.sub!(/^\s+/, '') - text.sub!(/\s+$/, '') - text.gsub!(/\s\s+/, ' ') - text + text.strip.gsub(/\s\s+/, ' ') end # Checks, if an object is nil, an empty String or an empty Hash. @@ -926,14 +928,14 @@ class XmlSimple #:nodoc: # default:: # Value to be returned, if node could not be converted. def node_to_text(node, default = nil) - if node.instance_of?(Element) - return node.texts.join('') - elsif node.instance_of?(Attribute) - return node.value.nil? ? default : node.value.strip - elsif node.instance_of?(Text) - return node.to_s.strip + if node.instance_of?(REXML::Element) + node.texts.map { |t| t.value }.join('') + elsif node.instance_of?(REXML::Attribute) + node.value.nil? ? default : node.value.strip + elsif node.instance_of?(REXML::Text) + node.value.strip else - return default + default end end |