plist_lite 1.1.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/plist_lite/ext.bundle +0 -0
- data/lib/plist_lite/pure_ruby.rb +97 -0
- data/lib/plist_lite.rb +2 -100
- metadata +6 -8
- /data/lib/{minimal.plist → plist_lite/minimal.plist} +0 -0
- /data/lib/{plist.dtd → plist_lite/plist.dtd} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b63ecbe6820a1a26d882dd4c7a5251faf233ba735d323cd50ae5492ca4bf7e1
|
4
|
+
data.tar.gz: 3c42362ab2d4d67dbf3cffd0fb5ac2d1c1dbda65d7be1b73914094cd858cd427
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcc57a97323b2a43cc539b0e05ef4006059b853651179e577a094fe95886f0c8bafe72918d11be51ec1aed12fe85a9756f3abe9b1d339847918384c564a9d359
|
7
|
+
data.tar.gz: 168e08a2631ed163ba979df1c4524aa2314ca9a72f01ed3b634fdd711d81a1e01e7b8ae886004b1311e0f67cf55fb47f57ae8523794cae1f3557ea0dacc0e3f8
|
data/lib/plist_lite/ext.bundle
CHANGED
Binary file
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'time'
|
5
|
+
module PlistLite
|
6
|
+
DTD = Dir.chdir(__dir__) do
|
7
|
+
Nokogiri::XML::Document.parse(
|
8
|
+
IO.read("#{__dir__}/minimal.plist"), nil, nil,
|
9
|
+
Nokogiri::XML::ParseOptions.new(Nokogiri::XML::ParseOptions::DTDLOAD)
|
10
|
+
)
|
11
|
+
end.external_subset
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def load(source)
|
15
|
+
doc = Nokogiri::XML::Document.parse(
|
16
|
+
source, nil, nil,
|
17
|
+
Nokogiri::XML::ParseOptions.new(Nokogiri::XML::ParseOptions::STRICT)
|
18
|
+
)
|
19
|
+
raise doc.errors.first unless doc.errors.empty?
|
20
|
+
|
21
|
+
errors = DTD.validate(doc)
|
22
|
+
raise errors.first unless errors.empty?
|
23
|
+
|
24
|
+
load_node(doc.root.elements.first)
|
25
|
+
end
|
26
|
+
|
27
|
+
def dump(obj)
|
28
|
+
output = +'<?xml version="1.0" encoding="UTF-8"?>' \
|
29
|
+
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' \
|
30
|
+
'<plist version="1.0">'
|
31
|
+
dump_node(obj, output)
|
32
|
+
output << '</plist>'
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def load_node(node)
|
38
|
+
case node.name
|
39
|
+
when 'dict'
|
40
|
+
hash = {}
|
41
|
+
node.elements.each_slice(2) do |key_node, value_node|
|
42
|
+
hash[key_node.text] = load_node(value_node)
|
43
|
+
end
|
44
|
+
hash
|
45
|
+
when 'array'
|
46
|
+
array = []
|
47
|
+
node.elements.each { |element| array << load_node(element) }
|
48
|
+
array
|
49
|
+
when 'integer' then node.text.to_i
|
50
|
+
when 'real' then node.text.to_f
|
51
|
+
when 'date' then Time.iso8601(node.text)
|
52
|
+
when 'string' then node.text
|
53
|
+
when 'data' then node.text.unpack1('m')
|
54
|
+
when 'true' then true
|
55
|
+
when 'false' then false
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def dump_node(obj, output)
|
60
|
+
case obj
|
61
|
+
when Hash
|
62
|
+
output << '<dict>'
|
63
|
+
obj.each do |key, value|
|
64
|
+
case key
|
65
|
+
when String then output << "<key>#{key.encode(xml: :text)}</key>"
|
66
|
+
when Symbol then output << "<key>#{key}</key>"
|
67
|
+
else output << "<key>#{key}</key>"
|
68
|
+
end
|
69
|
+
dump_node(value, output)
|
70
|
+
end
|
71
|
+
output << '</dict>'
|
72
|
+
when Array
|
73
|
+
output << '<array>'
|
74
|
+
obj.each { |i| dump_node(i, output) }
|
75
|
+
output << '</array>'
|
76
|
+
when Symbol then output << "<string>#{obj}</string>"
|
77
|
+
when String
|
78
|
+
output <<
|
79
|
+
case obj.encoding
|
80
|
+
when Encoding::ASCII_8BIT then "<data>#{[obj].pack('m')}</data>"
|
81
|
+
when Encoding::UTF_8 then "<string>#{obj.encode(xml: :text)}</string>"
|
82
|
+
else "<string>#{obj.encode(Encoding::UTF_8, xml: :text)}</string>"
|
83
|
+
end
|
84
|
+
when Integer then output << "<integer>#{obj}</integer>"
|
85
|
+
when Float then output << "<real>#{obj}</real>"
|
86
|
+
when true then output << '<true/>'
|
87
|
+
when false then output << '<false/>'
|
88
|
+
when Time then output << "<date>#{Time.at(obj).utc.iso8601}</date>"
|
89
|
+
when DateTime then output << "<date>#{obj.to_time.utc.iso8601}</date>"
|
90
|
+
when Date
|
91
|
+
warn 'Consider not using Date object because it does not contain time zone information'
|
92
|
+
output << "<date>#{obj.iso8601}T00:00:00Z</date>"
|
93
|
+
else raise ArgumentError, "unknown type: #{obj.class}"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/lib/plist_lite.rb
CHANGED
@@ -1,100 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'nokogiri'
|
4
|
-
require 'time'
|
5
|
-
module PlistLite
|
6
|
-
DTD = Dir.chdir(__dir__) do
|
7
|
-
Nokogiri::XML::Document.parse(
|
8
|
-
IO.read("#{__dir__}/minimal.plist"), nil, nil,
|
9
|
-
Nokogiri::XML::ParseOptions.new(Nokogiri::XML::ParseOptions::DTDLOAD)
|
10
|
-
)
|
11
|
-
end.external_subset
|
12
|
-
|
13
|
-
class << self
|
14
|
-
def load(source)
|
15
|
-
doc = Nokogiri::XML::Document.parse(
|
16
|
-
source, nil, nil,
|
17
|
-
Nokogiri::XML::ParseOptions.new(Nokogiri::XML::ParseOptions::STRICT)
|
18
|
-
)
|
19
|
-
raise doc.errors.first unless doc.errors.empty?
|
20
|
-
|
21
|
-
errors = DTD.validate(doc)
|
22
|
-
raise errors.first unless errors.empty?
|
23
|
-
|
24
|
-
load_node(doc.root.elements.first)
|
25
|
-
end
|
26
|
-
|
27
|
-
def dump(obj)
|
28
|
-
output = +'<?xml version="1.0" encoding="UTF-8"?>' \
|
29
|
-
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' \
|
30
|
-
'<plist version="1.0">'
|
31
|
-
dump_node(obj, output)
|
32
|
-
output << '</plist>'
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
def load_node(node)
|
38
|
-
case node.name
|
39
|
-
when 'dict'
|
40
|
-
hash = {}
|
41
|
-
node.elements.each_slice(2) do |key_node, value_node|
|
42
|
-
hash[key_node.text] = load_node(value_node)
|
43
|
-
end
|
44
|
-
hash
|
45
|
-
when 'array'
|
46
|
-
array = []
|
47
|
-
node.elements.each { |element| array << load_node(element) }
|
48
|
-
array
|
49
|
-
when 'integer' then node.text.to_i
|
50
|
-
when 'real' then node.text.to_f
|
51
|
-
when 'date' then Time.iso8601(node.text)
|
52
|
-
when 'string' then node.text
|
53
|
-
when 'data' then node.text.unpack1('m')
|
54
|
-
when 'true' then true
|
55
|
-
when 'false' then false
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def dump_node(obj, output)
|
60
|
-
case obj
|
61
|
-
when Hash
|
62
|
-
output << '<dict>'
|
63
|
-
obj.each do |key, value|
|
64
|
-
case key
|
65
|
-
when String then output << "<key>#{key.encode(xml: :text)}</key>"
|
66
|
-
when Symbol then output << "<key>#{key}</key>"
|
67
|
-
else
|
68
|
-
raise TypeError, 'Hash key should be String or Symbol'
|
69
|
-
end
|
70
|
-
dump_node(value, output)
|
71
|
-
end
|
72
|
-
output << '</dict>'
|
73
|
-
when Array
|
74
|
-
output << '<array>'
|
75
|
-
obj.each { |i| dump_node(i, output) }
|
76
|
-
output << '</array>'
|
77
|
-
when Symbol then output << "<string>#{obj}</string>"
|
78
|
-
when String
|
79
|
-
output <<
|
80
|
-
case obj.encoding
|
81
|
-
when Encoding::ASCII_8BIT then "<data>#{[obj].pack('m')}</data>"
|
82
|
-
when Encoding::UTF_8 then "<string>#{obj.encode(xml: :text)}</string>"
|
83
|
-
else "<string>#{obj.encode(Encoding::UTF_8, xml: :text)}</string>"
|
84
|
-
end
|
85
|
-
when Integer then output << "<integer>#{obj}</integer>"
|
86
|
-
when Float then output << "<real>#{obj}</real>"
|
87
|
-
when true then output << '<true/>'
|
88
|
-
when false then output << '<false/>'
|
89
|
-
when Time then output << "<date>#{Time.at(obj).utc.iso8601}</date>"
|
90
|
-
when DateTime then output << "<date>#{obj.to_time.utc.iso8601}</date>"
|
91
|
-
when Date
|
92
|
-
warn 'Consider not using Date object because it does not contain time zone information'
|
93
|
-
output << "<date>#{obj.iso8601}T00:00:00Z</date>"
|
94
|
-
else raise ArgumentError, "unknown type: #{obj.class}"
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
require 'plist_lite/ext'
|
1
|
+
require 'plist_lite/pure_ruby'
|
2
|
+
require 'plist_lite/ext' unless RUBY_PLATFORM == 'java'
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plist_lite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Weihang Jian
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: nokogiri
|
@@ -90,15 +89,15 @@ extra_rdoc_files: []
|
|
90
89
|
files:
|
91
90
|
- ext/plist_lite/ext/ext.c
|
92
91
|
- ext/plist_lite/ext/extconf.rb
|
93
|
-
- lib/minimal.plist
|
94
|
-
- lib/plist.dtd
|
95
92
|
- lib/plist_lite.rb
|
96
93
|
- lib/plist_lite/ext.bundle
|
94
|
+
- lib/plist_lite/minimal.plist
|
95
|
+
- lib/plist_lite/plist.dtd
|
96
|
+
- lib/plist_lite/pure_ruby.rb
|
97
97
|
homepage: https://github.com/tonytonyjan/plist_lite
|
98
98
|
licenses:
|
99
99
|
- MIT
|
100
100
|
metadata: {}
|
101
|
-
post_install_message:
|
102
101
|
rdoc_options: []
|
103
102
|
require_paths:
|
104
103
|
- lib
|
@@ -113,8 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
112
|
- !ruby/object:Gem::Version
|
114
113
|
version: '0'
|
115
114
|
requirements: []
|
116
|
-
rubygems_version: 3.
|
117
|
-
signing_key:
|
115
|
+
rubygems_version: 3.6.9
|
118
116
|
specification_version: 4
|
119
117
|
summary: plist_lite is the fastest plist processor for Ruby written in C.
|
120
118
|
test_files: []
|
File without changes
|
File without changes
|