plist_lite 1.2.0-java → 1.2.1-java

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0dcfb56440d322942e1c4761dc5d42bcb5c937aef7852c27b29c2e44e41c3107
4
- data.tar.gz: d258101d6bb92d74390dd6439c2fc695a6c46685d617bc7eec8f99390a39ff6c
3
+ metadata.gz: 67205520969a742f335583938bdbf841ec6741398e3d58e9aa6e4e0ef3c92d9b
4
+ data.tar.gz: 4da7e3a7c5276764bca068cfab9e5690f5f7efc8578854a3cb34cb68f6eb521c
5
5
  SHA512:
6
- metadata.gz: 20e2391d22e7cf6585d791af35ee1565469f8e613f7597f9e3fbe6d72f3824d5e045a2a869358ea77f83668d5332e107679e326fc04e5e80b9ed9c6d2ef78d45
7
- data.tar.gz: 9ec6cd45b59cb2c294a3e8acf604b98931f07a536d7fbe7ad9c13c7fe9f03ddc84dcd02cbd045fc4d3a172713de21a300e2e2cc4eb46bb85dfb3a94c95ce8ce6
6
+ metadata.gz: 00e6ec83eaa132331301b0ebbebd7179bd82fa9bac46d84a91a95ae6c60ee8ef3012c83e8522dc3ce3177d575b6dabbeabb1ae0eed8ab239c410775735e846be
7
+ data.tar.gz: 97fc0ad015b7c5fc6185918c8f770cc3bf7d264e18d47d5d3f62d4b8159c2c84e16086c45533aa7ac933cb0bf7358ac066f708b21a996139c8b3193850d50b46
Binary file
@@ -0,0 +1 @@
1
+ <?xml version="1.0"?><!DOCTYPE plist SYSTEM "plist.dtd"><_/>
@@ -0,0 +1,19 @@
1
+ <!ENTITY % plistObject "(array | data | date | dict | real | integer | string | true | false )" >
2
+ <!ELEMENT plist %plistObject;>
3
+ <!ATTLIST plist version CDATA "1.0" >
4
+
5
+ <!-- Collections -->
6
+ <!ELEMENT array (%plistObject;)*>
7
+ <!ELEMENT dict (key, %plistObject;)*>
8
+ <!ELEMENT key (#PCDATA)>
9
+
10
+ <!--- Primitive types -->
11
+ <!ELEMENT string (#PCDATA)>
12
+ <!ELEMENT data (#PCDATA)> <!-- Contents interpreted as Base-64 encoded -->
13
+ <!ELEMENT date (#PCDATA)> <!-- Contents should conform to a subset of ISO 8601 (in particular, YYYY '-' MM '-' DD 'T' HH ':' MM ':' SS 'Z'. Smaller units may be omitted with a loss of precision) -->
14
+
15
+ <!-- Numerical primitives -->
16
+ <!ELEMENT true EMPTY> <!-- Boolean constant true -->
17
+ <!ELEMENT false EMPTY> <!-- Boolean constant false -->
18
+ <!ELEMENT real (#PCDATA)> <!-- Contents should represent a floating point number matching ("+" | "-")? d+ ("."d*)? ("E" ("+" | "-") d+)? where d is a digit 0-9. -->
19
+ <!ELEMENT integer (#PCDATA)> <!-- Contents should represent a (possibly signed) integer number in base 10 -->
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plist_lite
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: java
6
6
  authors:
7
7
  - Weihang Jian
@@ -88,6 +88,10 @@ extra_rdoc_files: []
88
88
  files:
89
89
  - ext/plist_lite/ext/extconf.rb
90
90
  - lib/plist_lite.rb
91
+ - lib/plist_lite/ext.bundle
92
+ - lib/plist_lite/minimal.plist
93
+ - lib/plist_lite/plist.dtd
94
+ - lib/plist_lite/pure_ruby.rb
91
95
  homepage: https://github.com/tonytonyjan/plist_lite
92
96
  licenses:
93
97
  - MIT