Update vendored gems
- backports to 3.11.4 - plist to 3.4.0
This commit is contained in:
parent
5772493e24
commit
a6f25419aa
4
Library/Homebrew/vendor/Gemfile.lock
vendored
4
Library/Homebrew/vendor/Gemfile.lock
vendored
@ -1,8 +1,8 @@
|
|||||||
GEM
|
GEM
|
||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
backports (3.8.0)
|
backports (3.11.4)
|
||||||
plist (3.3.0)
|
plist (3.4.0)
|
||||||
ruby-macho (2.0.0)
|
ruby-macho (2.0.0)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
|
|||||||
@ -3,7 +3,7 @@ require 'rbconfig'
|
|||||||
ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
|
ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
|
||||||
ruby_version = RbConfig::CONFIG["ruby_version"]
|
ruby_version = RbConfig::CONFIG["ruby_version"]
|
||||||
path = File.expand_path('..', __FILE__)
|
path = File.expand_path('..', __FILE__)
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/backports-3.8.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/backports-3.11.4/lib"
|
||||||
$:.unshift "#{path}/"
|
$:.unshift "#{path}/"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/plist-3.3.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/plist-3.4.0/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-macho-2.0.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-macho-2.0.0/lib"
|
||||||
|
|||||||
@ -0,0 +1,7 @@
|
|||||||
|
unless String.method_defined? :match?
|
||||||
|
class String
|
||||||
|
def match?(*args)
|
||||||
|
!match(*args).nil?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -1,11 +0,0 @@
|
|||||||
unless String.method_defined? :match?
|
|
||||||
class String
|
|
||||||
def match?(*args)
|
|
||||||
# Fiber to avoid setting $~
|
|
||||||
f = Fiber.new do
|
|
||||||
!match(*args).nil?
|
|
||||||
end
|
|
||||||
f.resume
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,222 +0,0 @@
|
|||||||
# encoding: utf-8
|
|
||||||
|
|
||||||
# = plist
|
|
||||||
#
|
|
||||||
# Copyright 2006-2010 Ben Bleything and Patrick May
|
|
||||||
# Distributed under the MIT License
|
|
||||||
#
|
|
||||||
|
|
||||||
module Plist; end
|
|
||||||
|
|
||||||
# === Create a plist
|
|
||||||
# You can dump an object to a plist in one of two ways:
|
|
||||||
#
|
|
||||||
# * <tt>Plist::Emit.dump(obj)</tt>
|
|
||||||
# * <tt>obj.to_plist</tt>
|
|
||||||
# * This requires that you mixin the <tt>Plist::Emit</tt> module, which is already done for +Array+ and +Hash+.
|
|
||||||
#
|
|
||||||
# The following Ruby classes are converted into native plist types:
|
|
||||||
# Array, Bignum, Date, DateTime, Fixnum, Float, Hash, Integer, String, Symbol, Time, true, false
|
|
||||||
# * +Array+ and +Hash+ are both recursive; their elements will be converted into plist nodes inside the <array> and <dict> containers (respectively).
|
|
||||||
# * +IO+ (and its descendants) and +StringIO+ objects are read from and their contents placed in a <data> element.
|
|
||||||
# * User classes may implement +to_plist_node+ to dictate how they should be serialized; otherwise the object will be passed to <tt>Marshal.dump</tt> and the result placed in a <data> element.
|
|
||||||
#
|
|
||||||
# For detailed usage instructions, refer to USAGE[link:files/docs/USAGE.html] and the methods documented below.
|
|
||||||
module Plist::Emit
|
|
||||||
# Helper method for injecting into classes. Calls <tt>Plist::Emit.dump</tt> with +self+.
|
|
||||||
def to_plist(envelope = true)
|
|
||||||
return Plist::Emit.dump(self, envelope)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Helper method for injecting into classes. Calls <tt>Plist::Emit.save_plist</tt> with +self+.
|
|
||||||
def save_plist(filename)
|
|
||||||
Plist::Emit.save_plist(self, filename)
|
|
||||||
end
|
|
||||||
|
|
||||||
# The following Ruby classes are converted into native plist types:
|
|
||||||
# Array, Bignum, Date, DateTime, Fixnum, Float, Hash, Integer, String, Symbol, Time
|
|
||||||
#
|
|
||||||
# Write us (via RubyForge) if you think another class can be coerced safely into one of the expected plist classes.
|
|
||||||
#
|
|
||||||
# +IO+ and +StringIO+ objects are encoded and placed in <data> elements; other objects are <tt>Marshal.dump</tt>'ed unless they implement +to_plist_node+.
|
|
||||||
#
|
|
||||||
# The +envelope+ parameters dictates whether or not the resultant plist fragment is wrapped in the normal XML/plist header and footer. Set it to false if you only want the fragment.
|
|
||||||
def self.dump(obj, envelope = true)
|
|
||||||
output = plist_node(obj)
|
|
||||||
|
|
||||||
output = wrap(output) if envelope
|
|
||||||
|
|
||||||
return output
|
|
||||||
end
|
|
||||||
|
|
||||||
# Writes the serialized object's plist to the specified filename.
|
|
||||||
def self.save_plist(obj, filename)
|
|
||||||
File.open(filename, 'wb') do |f|
|
|
||||||
f.write(obj.to_plist)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
def self.plist_node(element)
|
|
||||||
output = ''
|
|
||||||
|
|
||||||
if element.respond_to? :to_plist_node
|
|
||||||
output << element.to_plist_node
|
|
||||||
else
|
|
||||||
case element
|
|
||||||
when Array
|
|
||||||
if element.empty?
|
|
||||||
output << "<array/>\n"
|
|
||||||
else
|
|
||||||
output << tag('array') {
|
|
||||||
element.collect {|e| plist_node(e)}
|
|
||||||
}
|
|
||||||
end
|
|
||||||
when Hash
|
|
||||||
if element.empty?
|
|
||||||
output << "<dict/>\n"
|
|
||||||
else
|
|
||||||
inner_tags = []
|
|
||||||
|
|
||||||
element.keys.sort_by{|k| k.to_s }.each do |k|
|
|
||||||
v = element[k]
|
|
||||||
inner_tags << tag('key', CGI::escapeHTML(k.to_s))
|
|
||||||
inner_tags << plist_node(v)
|
|
||||||
end
|
|
||||||
|
|
||||||
output << tag('dict') {
|
|
||||||
inner_tags
|
|
||||||
}
|
|
||||||
end
|
|
||||||
when true, false
|
|
||||||
output << "<#{element}/>\n"
|
|
||||||
when Time
|
|
||||||
output << tag('date', element.utc.strftime('%Y-%m-%dT%H:%M:%SZ'))
|
|
||||||
when Date # also catches DateTime
|
|
||||||
output << tag('date', element.strftime('%Y-%m-%dT%H:%M:%SZ'))
|
|
||||||
when String, Symbol, Integer, Float
|
|
||||||
output << tag(element_type(element), CGI::escapeHTML(element.to_s))
|
|
||||||
when IO, StringIO
|
|
||||||
element.rewind
|
|
||||||
contents = element.read
|
|
||||||
# note that apple plists are wrapped at a different length then
|
|
||||||
# what ruby's base64 wraps by default.
|
|
||||||
# I used #encode64 instead of #b64encode (which allows a length arg)
|
|
||||||
# because b64encode is b0rked and ignores the length arg.
|
|
||||||
data = "\n"
|
|
||||||
Base64::encode64(contents).gsub(/\s+/, '').scan(/.{1,68}/o) { data << $& << "\n" }
|
|
||||||
output << tag('data', data)
|
|
||||||
else
|
|
||||||
output << comment( 'The <data> element below contains a Ruby object which has been serialized with Marshal.dump.' )
|
|
||||||
data = "\n"
|
|
||||||
Base64::encode64(Marshal.dump(element)).gsub(/\s+/, '').scan(/.{1,68}/o) { data << $& << "\n" }
|
|
||||||
output << tag('data', data )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return output
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.comment(content)
|
|
||||||
return "<!-- #{content} -->\n"
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.tag(type, contents = '', &block)
|
|
||||||
out = nil
|
|
||||||
|
|
||||||
if block_given?
|
|
||||||
out = IndentedString.new
|
|
||||||
out << "<#{type}>"
|
|
||||||
out.raise_indent
|
|
||||||
|
|
||||||
out << block.call
|
|
||||||
|
|
||||||
out.lower_indent
|
|
||||||
out << "</#{type}>"
|
|
||||||
else
|
|
||||||
out = "<#{type}>#{contents.to_s}</#{type}>\n"
|
|
||||||
end
|
|
||||||
|
|
||||||
return out.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.wrap(contents)
|
|
||||||
output = ''
|
|
||||||
|
|
||||||
output << '<?xml version="1.0" encoding="UTF-8"?>' + "\n"
|
|
||||||
output << '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' + "\n"
|
|
||||||
output << '<plist version="1.0">' + "\n"
|
|
||||||
|
|
||||||
output << contents
|
|
||||||
|
|
||||||
output << '</plist>' + "\n"
|
|
||||||
|
|
||||||
return output
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.element_type(item)
|
|
||||||
case item
|
|
||||||
when String, Symbol
|
|
||||||
'string'
|
|
||||||
|
|
||||||
when Integer
|
|
||||||
'integer'
|
|
||||||
|
|
||||||
when Float
|
|
||||||
'real'
|
|
||||||
|
|
||||||
else
|
|
||||||
raise "Don't know about this data type... something must be wrong!"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
private
|
|
||||||
class IndentedString #:nodoc:
|
|
||||||
attr_accessor :indent_string
|
|
||||||
|
|
||||||
def initialize(str = "\t")
|
|
||||||
@indent_string = str
|
|
||||||
@contents = ''
|
|
||||||
@indent_level = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_s
|
|
||||||
return @contents
|
|
||||||
end
|
|
||||||
|
|
||||||
def raise_indent
|
|
||||||
@indent_level += 1
|
|
||||||
end
|
|
||||||
|
|
||||||
def lower_indent
|
|
||||||
@indent_level -= 1 if @indent_level > 0
|
|
||||||
end
|
|
||||||
|
|
||||||
def <<(val)
|
|
||||||
if val.is_a? Array
|
|
||||||
val.each do |f|
|
|
||||||
self << f
|
|
||||||
end
|
|
||||||
else
|
|
||||||
# if it's already indented, don't bother indenting further
|
|
||||||
unless val =~ /\A#{@indent_string}/
|
|
||||||
indent = @indent_string * @indent_level
|
|
||||||
|
|
||||||
@contents << val.gsub(/^/, indent)
|
|
||||||
else
|
|
||||||
@contents << val
|
|
||||||
end
|
|
||||||
|
|
||||||
# it already has a newline, don't add another
|
|
||||||
@contents << "\n" unless val =~ /\n$/
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class Array #:nodoc:
|
|
||||||
include Plist::Emit
|
|
||||||
end
|
|
||||||
|
|
||||||
class Hash #:nodoc:
|
|
||||||
include Plist::Emit
|
|
||||||
end
|
|
||||||
@ -16,6 +16,3 @@ require 'stringio'
|
|||||||
require 'plist/generator'
|
require 'plist/generator'
|
||||||
require 'plist/parser'
|
require 'plist/parser'
|
||||||
require 'plist/version'
|
require 'plist/version'
|
||||||
|
|
||||||
module Plist
|
|
||||||
end
|
|
||||||
230
Library/Homebrew/vendor/bundle-standalone/ruby/2.3.0/gems/plist-3.4.0/lib/plist/generator.rb
vendored
Normal file
230
Library/Homebrew/vendor/bundle-standalone/ruby/2.3.0/gems/plist-3.4.0/lib/plist/generator.rb
vendored
Normal file
@ -0,0 +1,230 @@
|
|||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
|
# = plist
|
||||||
|
#
|
||||||
|
# Copyright 2006-2010 Ben Bleything and Patrick May
|
||||||
|
# Distributed under the MIT License
|
||||||
|
#
|
||||||
|
|
||||||
|
module Plist
|
||||||
|
# === Create a plist
|
||||||
|
# You can dump an object to a plist in one of two ways:
|
||||||
|
#
|
||||||
|
# * <tt>Plist::Emit.dump(obj)</tt>
|
||||||
|
# * <tt>obj.to_plist</tt>
|
||||||
|
# * This requires that you mixin the <tt>Plist::Emit</tt> module, which is already done for +Array+ and +Hash+.
|
||||||
|
#
|
||||||
|
# The following Ruby classes are converted into native plist types:
|
||||||
|
# Array, Bignum, Date, DateTime, Fixnum, Float, Hash, Integer, String, Symbol, Time, true, false
|
||||||
|
# * +Array+ and +Hash+ are both recursive; their elements will be converted into plist nodes inside the <array> and <dict> containers (respectively).
|
||||||
|
# * +IO+ (and its descendants) and +StringIO+ objects are read from and their contents placed in a <data> element.
|
||||||
|
# * User classes may implement +to_plist_node+ to dictate how they should be serialized; otherwise the object will be passed to <tt>Marshal.dump</tt> and the result placed in a <data> element.
|
||||||
|
#
|
||||||
|
# For detailed usage instructions, refer to USAGE[link:files/docs/USAGE.html] and the methods documented below.
|
||||||
|
module Emit
|
||||||
|
DEFAULT_INDENT = "\t"
|
||||||
|
|
||||||
|
# Helper method for injecting into classes. Calls <tt>Plist::Emit.dump</tt> with +self+.
|
||||||
|
def to_plist(envelope = true, options = {})
|
||||||
|
options = { :indent => DEFAULT_INDENT }.merge(options)
|
||||||
|
return Plist::Emit.dump(self, envelope, options)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Helper method for injecting into classes. Calls <tt>Plist::Emit.save_plist</tt> with +self+.
|
||||||
|
def save_plist(filename, options = {})
|
||||||
|
options = { :indent => DEFAULT_INDENT }.merge(options)
|
||||||
|
Plist::Emit.save_plist(self, filename, options)
|
||||||
|
end
|
||||||
|
|
||||||
|
# The following Ruby classes are converted into native plist types:
|
||||||
|
# Array, Bignum, Date, DateTime, Fixnum, Float, Hash, Integer, String, Symbol, Time
|
||||||
|
#
|
||||||
|
# Write us (via RubyForge) if you think another class can be coerced safely into one of the expected plist classes.
|
||||||
|
#
|
||||||
|
# +IO+ and +StringIO+ objects are encoded and placed in <data> elements; other objects are <tt>Marshal.dump</tt>'ed unless they implement +to_plist_node+.
|
||||||
|
#
|
||||||
|
# The +envelope+ parameters dictates whether or not the resultant plist fragment is wrapped in the normal XML/plist header and footer. Set it to false if you only want the fragment.
|
||||||
|
def self.dump(obj, envelope = true, options = {})
|
||||||
|
options = { :indent => DEFAULT_INDENT }.merge(options)
|
||||||
|
output = plist_node(obj, options)
|
||||||
|
|
||||||
|
output = wrap(output) if envelope
|
||||||
|
|
||||||
|
return output
|
||||||
|
end
|
||||||
|
|
||||||
|
# Writes the serialized object's plist to the specified filename.
|
||||||
|
def self.save_plist(obj, filename, options = {})
|
||||||
|
options = { :indent => DEFAULT_INDENT }.merge(options)
|
||||||
|
File.open(filename, 'wb') do |f|
|
||||||
|
f.write(obj.to_plist(true, options))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def self.plist_node(element, options = {})
|
||||||
|
options = { :indent => DEFAULT_INDENT }.merge(options)
|
||||||
|
output = ''
|
||||||
|
|
||||||
|
if element.respond_to? :to_plist_node
|
||||||
|
output << element.to_plist_node
|
||||||
|
else
|
||||||
|
case element
|
||||||
|
when Array
|
||||||
|
if element.empty?
|
||||||
|
output << "<array/>\n"
|
||||||
|
else
|
||||||
|
output << tag('array', '', options) {
|
||||||
|
element.collect {|e| plist_node(e, options)}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
when Hash
|
||||||
|
if element.empty?
|
||||||
|
output << "<dict/>\n"
|
||||||
|
else
|
||||||
|
inner_tags = []
|
||||||
|
|
||||||
|
element.keys.sort_by{|k| k.to_s }.each do |k|
|
||||||
|
v = element[k]
|
||||||
|
inner_tags << tag('key', CGI.escapeHTML(k.to_s), options)
|
||||||
|
inner_tags << plist_node(v, options)
|
||||||
|
end
|
||||||
|
|
||||||
|
output << tag('dict', '', options) {
|
||||||
|
inner_tags
|
||||||
|
}
|
||||||
|
end
|
||||||
|
when true, false
|
||||||
|
output << "<#{element}/>\n"
|
||||||
|
when Time
|
||||||
|
output << tag('date', element.utc.strftime('%Y-%m-%dT%H:%M:%SZ'), options)
|
||||||
|
when Date # also catches DateTime
|
||||||
|
output << tag('date', element.strftime('%Y-%m-%dT%H:%M:%SZ'), options)
|
||||||
|
when String, Symbol, Integer, Float
|
||||||
|
output << tag(element_type(element), CGI.escapeHTML(element.to_s), options)
|
||||||
|
when IO, StringIO
|
||||||
|
element.rewind
|
||||||
|
contents = element.read
|
||||||
|
# note that apple plists are wrapped at a different length then
|
||||||
|
# what ruby's base64 wraps by default.
|
||||||
|
# I used #encode64 instead of #b64encode (which allows a length arg)
|
||||||
|
# because b64encode is b0rked and ignores the length arg.
|
||||||
|
data = "\n"
|
||||||
|
Base64.encode64(contents).gsub(/\s+/, '').scan(/.{1,68}/o) { data << $& << "\n" }
|
||||||
|
output << tag('data', data, options)
|
||||||
|
else
|
||||||
|
output << comment('The <data> element below contains a Ruby object which has been serialized with Marshal.dump.')
|
||||||
|
data = "\n"
|
||||||
|
Base64.encode64(Marshal.dump(element)).gsub(/\s+/, '').scan(/.{1,68}/o) { data << $& << "\n" }
|
||||||
|
output << tag('data', data, options)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return output
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.comment(content)
|
||||||
|
return "<!-- #{content} -->\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.tag(type, contents = '', options = {}, &block)
|
||||||
|
options = { :indent => DEFAULT_INDENT }.merge(options)
|
||||||
|
out = nil
|
||||||
|
|
||||||
|
if block_given?
|
||||||
|
out = IndentedString.new(options[:indent])
|
||||||
|
out << "<#{type}>"
|
||||||
|
out.raise_indent
|
||||||
|
|
||||||
|
out << block.call
|
||||||
|
|
||||||
|
out.lower_indent
|
||||||
|
out << "</#{type}>"
|
||||||
|
else
|
||||||
|
out = "<#{type}>#{contents.to_s}</#{type}>\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
return out.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.wrap(contents)
|
||||||
|
output = ''
|
||||||
|
|
||||||
|
output << '<?xml version="1.0" encoding="UTF-8"?>' + "\n"
|
||||||
|
output << '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' + "\n"
|
||||||
|
output << '<plist version="1.0">' + "\n"
|
||||||
|
|
||||||
|
output << contents
|
||||||
|
|
||||||
|
output << '</plist>' + "\n"
|
||||||
|
|
||||||
|
return output
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.element_type(item)
|
||||||
|
case item
|
||||||
|
when String, Symbol
|
||||||
|
'string'
|
||||||
|
|
||||||
|
when Integer
|
||||||
|
'integer'
|
||||||
|
|
||||||
|
when Float
|
||||||
|
'real'
|
||||||
|
|
||||||
|
else
|
||||||
|
raise "Don't know about this data type... something must be wrong!"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
private
|
||||||
|
class IndentedString #:nodoc:
|
||||||
|
attr_accessor :indent_string
|
||||||
|
|
||||||
|
def initialize(str = "\t")
|
||||||
|
@indent_string = str
|
||||||
|
@contents = ''
|
||||||
|
@indent_level = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
return @contents
|
||||||
|
end
|
||||||
|
|
||||||
|
def raise_indent
|
||||||
|
@indent_level += 1
|
||||||
|
end
|
||||||
|
|
||||||
|
def lower_indent
|
||||||
|
@indent_level -= 1 if @indent_level > 0
|
||||||
|
end
|
||||||
|
|
||||||
|
def <<(val)
|
||||||
|
if val.is_a? Array
|
||||||
|
val.each do |f|
|
||||||
|
self << f
|
||||||
|
end
|
||||||
|
else
|
||||||
|
# if it's already indented, don't bother indenting further
|
||||||
|
unless val =~ /\A#{@indent_string}/
|
||||||
|
indent = @indent_string * @indent_level
|
||||||
|
|
||||||
|
@contents << val.gsub(/^/, indent)
|
||||||
|
else
|
||||||
|
@contents << val
|
||||||
|
end
|
||||||
|
|
||||||
|
# it already has a newline, don't add another
|
||||||
|
@contents << "\n" unless val =~ /\n$/
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Array #:nodoc:
|
||||||
|
include Plist::Emit
|
||||||
|
end
|
||||||
|
|
||||||
|
class Hash #:nodoc:
|
||||||
|
include Plist::Emit
|
||||||
|
end
|
||||||
@ -11,41 +11,41 @@
|
|||||||
# === Load a plist file
|
# === Load a plist file
|
||||||
# This is the main point of the library:
|
# This is the main point of the library:
|
||||||
#
|
#
|
||||||
# r = Plist::parse_xml( filename_or_xml )
|
# r = Plist.parse_xml(filename_or_xml)
|
||||||
module Plist
|
module Plist
|
||||||
# Note that I don't use these two elements much:
|
# Note that I don't use these two elements much:
|
||||||
#
|
#
|
||||||
# + Date elements are returned as DateTime objects.
|
# + Date elements are returned as DateTime objects.
|
||||||
# + Data elements are implemented as Tempfiles
|
# + Data elements are implemented as Tempfiles
|
||||||
#
|
#
|
||||||
# Plist::parse_xml will blow up if it encounters a Date element.
|
# Plist.parse_xml will blow up if it encounters a Date element.
|
||||||
# If you encounter such an error, or if you have a Date element which
|
# If you encounter such an error, or if you have a Date element which
|
||||||
# can't be parsed into a Time object, please send your plist file to
|
# can't be parsed into a Time object, please create an issue
|
||||||
# plist@hexane.org so that I can implement the proper support.
|
# attaching your plist file at https://github.com/patsplat/plist/issues
|
||||||
def Plist::parse_xml( filename_or_xml )
|
# so folks can implement the proper support.
|
||||||
|
def self.parse_xml(filename_or_xml)
|
||||||
listener = Listener.new
|
listener = Listener.new
|
||||||
#parser = REXML::Parsers::StreamParser.new(File.new(filename), listener)
|
# parser = REXML::Parsers::StreamParser.new(File.new(filename), listener)
|
||||||
parser = StreamParser.new(filename_or_xml, listener)
|
parser = StreamParser.new(filename_or_xml, listener)
|
||||||
parser.parse
|
parser.parse
|
||||||
listener.result
|
listener.result
|
||||||
end
|
end
|
||||||
|
|
||||||
class Listener
|
class Listener
|
||||||
#include REXML::StreamListener
|
# include REXML::StreamListener
|
||||||
|
|
||||||
attr_accessor :result, :open
|
attr_accessor :result, :open
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@result = nil
|
@result = nil
|
||||||
@open = Array.new
|
@open = []
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def tag_start(name, attributes)
|
def tag_start(name, attributes)
|
||||||
@open.push PTag::mappings[name].new
|
@open.push PTag.mappings[name].new
|
||||||
end
|
end
|
||||||
|
|
||||||
def text( contents )
|
def text(contents)
|
||||||
@open.last.text = contents if @open.last
|
@open.last.text = contents if @open.last
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -60,11 +60,11 @@ module Plist
|
|||||||
end
|
end
|
||||||
|
|
||||||
class StreamParser
|
class StreamParser
|
||||||
def initialize( plist_data_or_file, listener )
|
def initialize(plist_data_or_file, listener)
|
||||||
if plist_data_or_file.respond_to? :read
|
if plist_data_or_file.respond_to? :read
|
||||||
@xml = plist_data_or_file.read
|
@xml = plist_data_or_file.read
|
||||||
elsif File.exist? plist_data_or_file
|
elsif File.exist? plist_data_or_file
|
||||||
@xml = File.read( plist_data_or_file )
|
@xml = File.read(plist_data_or_file)
|
||||||
else
|
else
|
||||||
@xml = plist_data_or_file
|
@xml = plist_data_or_file
|
||||||
end
|
end
|
||||||
@ -78,15 +78,14 @@ module Plist
|
|||||||
COMMENT_START = /\A<!--/
|
COMMENT_START = /\A<!--/
|
||||||
COMMENT_END = /.*?-->/m
|
COMMENT_END = /.*?-->/m
|
||||||
|
|
||||||
|
|
||||||
def parse
|
def parse
|
||||||
plist_tags = PTag::mappings.keys.join('|')
|
plist_tags = PTag.mappings.keys.join('|')
|
||||||
start_tag = /<(#{plist_tags})([^>]*)>/i
|
start_tag = /<(#{plist_tags})([^>]*)>/i
|
||||||
end_tag = /<\/(#{plist_tags})[^>]*>/i
|
end_tag = /<\/(#{plist_tags})[^>]*>/i
|
||||||
|
|
||||||
require 'strscan'
|
require 'strscan'
|
||||||
|
|
||||||
@scanner = StringScanner.new( @xml )
|
@scanner = StringScanner.new(@xml)
|
||||||
until @scanner.eos?
|
until @scanner.eos?
|
||||||
if @scanner.scan(COMMENT_START)
|
if @scanner.scan(COMMENT_START)
|
||||||
@scanner.scan(COMMENT_END)
|
@scanner.scan(COMMENT_END)
|
||||||
@ -132,22 +131,21 @@ module Plist
|
|||||||
end
|
end
|
||||||
|
|
||||||
class PTag
|
class PTag
|
||||||
@@mappings = { }
|
def self.mappings
|
||||||
def PTag::mappings
|
@mappings ||= {}
|
||||||
@@mappings
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def PTag::inherited( sub_class )
|
def self.inherited(sub_class)
|
||||||
key = sub_class.to_s.downcase
|
key = sub_class.to_s.downcase
|
||||||
key.gsub!(/^plist::/, '' )
|
key.gsub!(/^plist::/, '')
|
||||||
key.gsub!(/^p/, '') unless key == "plist"
|
key.gsub!(/^p/, '') unless key == "plist"
|
||||||
|
|
||||||
@@mappings[key] = sub_class
|
mappings[key] = sub_class
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_accessor :text, :children
|
attr_accessor :text, :children
|
||||||
def initialize
|
def initialize
|
||||||
@children = Array.new
|
@children = []
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_ruby
|
def to_ruby
|
||||||
@ -163,7 +161,7 @@ module Plist
|
|||||||
|
|
||||||
class PDict < PTag
|
class PDict < PTag
|
||||||
def to_ruby
|
def to_ruby
|
||||||
dict = Hash.new
|
dict = {}
|
||||||
key = nil
|
key = nil
|
||||||
|
|
||||||
children.each do |c|
|
children.each do |c|
|
||||||
@ -181,13 +179,13 @@ module Plist
|
|||||||
|
|
||||||
class PKey < PTag
|
class PKey < PTag
|
||||||
def to_ruby
|
def to_ruby
|
||||||
CGI::unescapeHTML(text || '')
|
CGI.unescapeHTML(text || '')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class PString < PTag
|
class PString < PTag
|
||||||
def to_ruby
|
def to_ruby
|
||||||
CGI::unescapeHTML(text || '')
|
CGI.unescapeHTML(text || '')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
module Plist
|
module Plist
|
||||||
VERSION = '3.3.0'.freeze
|
VERSION = '3.4.0'.freeze
|
||||||
end
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user