Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 5415

Show
Ignore:
Timestamp:
11/02/06 20:13:27 (3 years ago)
Author:
nzkoz
Message:

merge xmlsimple update to release branch

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1-2-pre-release/activesupport/CHANGELOG

    r5389 r5415  
    11*SVN* 
     2 
     3* update XmlSimple to 1.0.10. Closes #6532. [nicksieger] 
    24 
    35* 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] 
  • branches/1-2-pre-release/activesupport/lib/active_support/vendor/xml_simple.rb

    r4453 r5415  
    22# 
    33# Author::    Maik Schmidt <contact@maik-schmidt.de> 
    4 # Copyright:: Copyright (c) 2003 Maik Schmidt 
     4# Copyright:: Copyright (c) 2003-2006 Maik Schmidt 
    55# License::   Distributes under the same terms as Ruby. 
    66# 
    77require 'rexml/document' 
     8require 'stringio' 
    89 
    910# Easy API to maintain XML (especially configuration files). 
    10 class XmlSimple #:nodoc: 
     11class XmlSimple 
    1112  include REXML 
    1213 
    13   @@VERSION = '1.0.2
     14  @@VERSION = '1.0.9
    1415 
    1516  # A simple cache for XML documents that were already transformed 
    1617  # by xml_in. 
    17   class Cache #:nodoc: 
     18  class Cache 
    1819    # Creates and initializes a new Cache object. 
    1920    def initialize 
     
    185186        @doc = load_xml_file(filename) 
    186187      end 
    187     elsif string.kind_of?(IO) 
     188    elsif string.kind_of?(IO) || string.kind_of?(StringIO) 
    188189      @doc = parse(string.readlines.to_s) 
    189190    else 
     
    267268      searchpath forcearray suppressempty anonymoustag 
    268269      cache grouptags normalisespace normalizespace 
    269       variables varattr 
     270      variables varattr keytosymbol 
    270271    ), 
    271272    'out' => %w( 
     
    284285  DEF_FORCE_ARRAY     = true 
    285286  DEF_INDENTATION     = '  ' 
     287  DEF_KEY_TO_SYMBOL   = false 
    286288   
    287289  # Normalizes option names in a hash, i.e., turns all 
     
    350352      @options['xmldeclaration'] = DEF_XML_DECLARATION 
    351353    end 
     354 
     355    @options['keytosymbol'] = DEF_KEY_TO_SYMBOL unless @options.has_key?('keytosymbol') 
    352356 
    353357    if @options.has_key?('contentkey') 
     
    655659      end 
    656660    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     
    657669    if hash.has_key?(key) 
    658670      if hash[key].instance_of?(Array) 
     
    880892  #   The string to be escaped. 
    881893  def escape_value(data) 
    882     return data if data.nil? || data == '' 
    883     result = data.dup 
    884     result.gsub!('&', '&amp;') 
    885     result.gsub!('<', '&lt;') 
    886     result.gsub!('>', '&gt;') 
    887     result.gsub!('"', '&quot;') 
    888     result.gsub!("'", '&apos;') 
    889     result 
     894    Text::normalize(data) 
    890895  end 
    891896   
     
    896901  #   String to be normalised. 
    897902  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+/, ' ') 
    902904  end 
    903905 
     
    927929  #   Value to be returned, if node could not be converted. 
    928930  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       return node.value.nil? ? default : node.value.strip 
    933     elsif node.instance_of?(Text) 
    934       return node.to_s.strip 
    935     else 
    936       return default 
     931    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 
    937939    end 
    938940  end