Changeset 5414
- Timestamp:
- 11/02/06 20:10:53 (2 years ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/vendor/xml_simple.rb (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r5410 r5414 1 1 *SVN* 2 3 * update XmlSimple to 1.0.10. Closes #6532. [nicksieger] 2 4 3 5 * 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] trunk/activesupport/lib/active_support/vendor/xml_simple.rb
r4453 r5414 2 2 # 3 3 # Author:: Maik Schmidt <contact@maik-schmidt.de> 4 # Copyright:: Copyright (c) 2003 Maik Schmidt4 # Copyright:: Copyright (c) 2003-2006 Maik Schmidt 5 5 # License:: Distributes under the same terms as Ruby. 6 6 # 7 7 require 'rexml/document' 8 require 'stringio' 8 9 9 10 # Easy API to maintain XML (especially configuration files). 10 class XmlSimple #:nodoc:11 class XmlSimple 11 12 include REXML 12 13 13 @@VERSION = '1.0. 2'14 @@VERSION = '1.0.9' 14 15 15 16 # A simple cache for XML documents that were already transformed 16 17 # by xml_in. 17 class Cache #:nodoc:18 class Cache 18 19 # Creates and initializes a new Cache object. 19 20 def initialize … … 185 186 @doc = load_xml_file(filename) 186 187 end 187 elsif string.kind_of?(IO) 188 elsif string.kind_of?(IO) || string.kind_of?(StringIO) 188 189 @doc = parse(string.readlines.to_s) 189 190 else … … 267 268 searchpath forcearray suppressempty anonymoustag 268 269 cache grouptags normalisespace normalizespace 269 variables varattr 270 variables varattr keytosymbol 270 271 ), 271 272 'out' => %w( … … 284 285 DEF_FORCE_ARRAY = true 285 286 DEF_INDENTATION = ' ' 287 DEF_KEY_TO_SYMBOL = false 286 288 287 289 # Normalizes option names in a hash, i.e., turns all … … 350 352 @options['xmldeclaration'] = DEF_XML_DECLARATION 351 353 end 354 355 @options['keytosymbol'] = DEF_KEY_TO_SYMBOL unless @options.has_key?('keytosymbol') 352 356 353 357 if @options.has_key?('contentkey') … … 655 659 end 656 660 end 661 662 #patch for converting keys to symbols 663 if @options.has_key?('keytosymbol') 664 if @options['keytosymbol'] == true 665 key = key.to_s.downcase.to_sym 666 end 667 end 668 657 669 if hash.has_key?(key) 658 670 if hash[key].instance_of?(Array) … … 880 892 # The string to be escaped. 881 893 def escape_value(data) 882 return data if data.nil? || data == '' 883 result = data.dup 884 result.gsub!('&', '&') 885 result.gsub!('<', '<') 886 result.gsub!('>', '>') 887 result.gsub!('"', '"') 888 result.gsub!("'", ''') 889 result 894 Text::normalize(data) 890 895 end 891 896 … … 896 901 # String to be normalised. 897 902 def normalise_space(text) 898 text.sub!(/^\s+/, '') 899 text.sub!(/\s+$/, '') 900 text.gsub!(/\s\s+/, ' ') 901 text 903 text.strip.gsub(/\s\s+/, ' ') 902 904 end 903 905 … … 927 929 # Value to be returned, if node could not be converted. 928 930 def node_to_text(node, default = nil) 929 if node.instance_of?( Element)930 return node.texts.join('')931 elsif node.instance_of?( Attribute)932 returnnode.value.nil? ? default : node.value.strip933 elsif node.instance_of?( Text)934 return node.to_s.strip935 else 936 returndefault931 if node.instance_of?(REXML::Element) 932 node.texts.map { |t| t.value }.join('') 933 elsif node.instance_of?(REXML::Attribute) 934 node.value.nil? ? default : node.value.strip 935 elsif node.instance_of?(REXML::Text) 936 node.value.strip 937 else 938 default 937 939 end 938 940 end