lib/rbCFPropertyList.rb in CFPropertyList-2.1.1 vs lib/rbCFPropertyList.rb in CFPropertyList-2.1.2

- old
+ new

@@ -41,10 +41,14 @@ # # Author:: Christian Kruse (mailto:cjk@wwwtech.de) # Copyright:: Copyright (c) 2010 # License:: MIT License module CFPropertyList + class << self + attr_accessor :xml_parser_interface + end + # interface class for PList parsers class ParserInterface # load a plist def load(opts={}) return "" @@ -105,20 +109,24 @@ end end begin require dirname + '/rbLibXMLParser.rb' + temp = LibXML::XML::Parser::Options::NOBLANKS; # check if we have a version with parser options try_nokogiri = false -rescue LoadError => e + CFPropertyList.xml_parser_interface = CFPropertyList::LibXMLParser +rescue LoadError, NameError try_nokogiri = true end if try_nokogiri then begin require dirname + '/rbNokogiriParser.rb' + CFPropertyList.xml_parser_interface = CFPropertyList::NokogiriXMLParser rescue LoadError => e require dirname + '/rbREXMLParser.rb' + CFPropertyList.xml_parser_interface = CFPropertyList::ReXMLParser end end module CFPropertyList @@ -218,11 +226,11 @@ FORMAT_XML = 2 # Format constant for automatic format recognizing FORMAT_AUTO = 0 - @@parsers = [Binary,XML] + @@parsers = [Binary, CFPropertyList.xml_parser_interface] # Path of PropertyList attr_accessor :filename # Path of PropertyList attr_accessor :format @@ -289,11 +297,11 @@ prsr = nil if filetype == "bplist" then raise CFFormatError.new("Wong file version #{version}") unless version == "00" prsr = Binary.new else - prsr = XML.new + prsr = CFPropertyList.xml_parser_interface.new end @value = prsr.load({:data => str}) end end @@ -321,11 +329,11 @@ prsr = nil if filetype == "bplist" then raise CFFormatError.new("Wong file version #{version}") unless version == "00" prsr = Binary.new else - prsr = XML.new + prsr = CFPropertyList.xml_parser_interface.new end @value = prsr.load({:file => file}) end end @@ -363,9 +371,10 @@ opts[:root] = @value return prsr.to_str(opts) end end end + class Array # convert an array to plist format def to_plist(options={}) options[:plist_format] ||= CFPropertyList::List::FORMAT_BINARY