Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
merge xmlsimple update to release branch
git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-pre-release@5415 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
NZKoz committed Nov 2, 2006
1 parent 53c4903 commit 2029b8a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
2 changes: 2 additions & 0 deletions activesupport/CHANGELOG
@@ -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]
Expand Down
52 changes: 27 additions & 25 deletions 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 = {}
Expand Down Expand Up @@ -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}>."
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 2029b8a

Please sign in to comment.