Permalink
Browse files

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
  • Loading branch information...
1 parent a8bb66a commit ea433f15bf98a426239e985220393f63fa6d56c3 @NZKoz NZKoz committed Nov 2, 2006
Showing with 29 additions and 25 deletions.
  1. +2 −0 activesupport/CHANGELOG
  2. +27 −25 activesupport/lib/active_support/vendor/xml_simple.rb
View
@@ -1,5 +1,7 @@
*SVN*
+* update XmlSimple to 1.0.10. Closes #6532. [nicksieger]
+
* Update dependencies to allow constants to be defined alongside their siblings. A common case for this is AR model classes with STI; user.rb might define User, Administrator and Guest for example. [Nicholas Seckar]
* next_week respects DST changes. #6483, #5617, #2353, #2509, #4551 [marclove, rabiedenharn, rails@roetzel.de, jsolson@damogran.org, drbrain@segment7.net]
@@ -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 @@ def xml_in(string = nil, options = nil)
@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 @@ def XmlSimple.xml_out(hash, options = nil)
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 @@ def XmlSimple.xml_out(hash, options = nil)
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 @@ def handle_options(direction, options)
@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 @@ def merge(hash, key, value)
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 @@ def hash_to_array(parent, hashref)
# data::
# The string to be escaped.
def escape_value(data)
- return data if data.nil? || data == ''
- result = data.dup
- result.gsub!('&', '&amp;')
- result.gsub!('<', '&lt;')
- result.gsub!('>', '&gt;')
- result.gsub!('"', '&quot;')
- result.gsub!("'", '&apos;')
- result
+ Text::normalize(data)
end
# Removes leading and trailing whitespace and sequences of
@@ -895,10 +900,7 @@ def escape_value(data)
# 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 @@ def empty(value)
# 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

0 comments on commit ea433f1

Please sign in to comment.