plist 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,103 @@
1
+ = plist - All-purpose Property List manipulation library
2
+
3
+ === Release version 3.0.0!
4
+
5
+ 2010-02-23:
6
+ * Ruby 1.9.x compatibility!
7
+
8
+ 2010-02-16:
9
+ * excise a bunch of unnecessary @@ variables
10
+ * fix up some tests for cross-version compatibility
11
+
12
+ 2010-02-14:
13
+ * generalized cleanup:
14
+ * fix old file headers
15
+ * modernize rakefile
16
+ * clean up rdoc
17
+
18
+ 2010-01-08:
19
+ * move from RubyForge Subversion to GitHub
20
+
21
+ 2007-02-22 (r81):
22
+ * make the plist parser accept strings contain XML or any object that responds to #read (File and StringIO being the intended targets here). Test and idea contributed by Chuck Remes.
23
+
24
+ 2006-09-20 (r80):
25
+ * tweak a comment in generator.rb to make it clear that we're not using Base64.b64encode because it's broken.
26
+
27
+ === Release version 3.0.0!
28
+
29
+ 2006-09-20 (r77 - r79):
30
+ * move IndentedString inside Plist::Emit and :nodoc: it
31
+ * Tag 3.0.0! (from rev 78)
32
+
33
+ 2006-09-19 (r73 - r75):
34
+ * Really fix the rakefile this time (apparently I deleted some code that I needed...)
35
+ * alter the fix_whitespace rake task to ignore the assets directory
36
+ * cleanup whitespace
37
+
38
+ 2006-09-18 (r70 - r72):
39
+ * Update this file ;)
40
+ * Fix Rakefile
41
+ * gem install -t now works correctly
42
+ * Remove super-sekr1t rdoc staging area from rdoc publishing task
43
+
44
+ 2006-09-15 (r64 - r69):
45
+ * Change behavior of empty collection elements to match What Apple Does
46
+ * Fix some gem packaging infrastructure
47
+
48
+ 2006-09-13 (r61 - r63):
49
+ * Merge generator injection removal branch into trunk!
50
+
51
+ 2006-09-13 (r52 - r60):
52
+ * Fix indentation/newlines in generator (finally!)
53
+ * Refix indentation to be more faithful to the way Apple emits their plists
54
+ * Remove horrific regex and replace it with proper comment parsing
55
+ * Empty plists return nil when parsed
56
+ * Sort hash keys before emitting (now we can test multi-element hashes!)
57
+ * Inject #<=> into Symbol so that sorting Symbol-keyed hashes won't freak out
58
+
59
+ 2006-09-12 (r47 - r51):
60
+ * More test rejiggering
61
+ * New tests to expose some bugs
62
+
63
+ 2006-09-10 (r33 - r46):
64
+ * Update tests for new generator code
65
+ * Rejigger some tests
66
+ * Make the generator try to call #to_plist_node on any object it tries to serialize, thus allowing class authors to define how their objects will be serialized
67
+ * Marshal.dump unrecognized objects into <data> elements
68
+ * Make the parser strip out comments and Marshal.load <data> elements if possible
69
+ * Update some rdoc
70
+
71
+ === Release version 2.1.1!
72
+
73
+ 2006-09-10 (r31 - r32):
74
+ * Added encoding / decoding for entities (&amp; etc)
75
+ * Changed parsing of <data> elements to return StringIO objects
76
+ * Fixed bug with empty <key> tags
77
+
78
+ 2006-08-24 (r25 - r30):
79
+ * Invert ownership of methods in the generator, allowing us to remove the self.extend(self)
80
+ * New branch to remove method inject from parser
81
+
82
+ 2006-08-23 (r22 - r24):
83
+ * Add rcov task to Rakefile
84
+ * Add some tests
85
+
86
+ 2006-08-20 (r9 - r21):
87
+ * Add a bunch of rdoc and rdoc infrastructure
88
+ * Add rake task to clean up errant whitespace
89
+ * Spin off a branch to remove a bunch of method injection in the generator code
90
+ * Rename some tests for clarity's sake
91
+ * Replace NARF generation code with Ben's generation code
92
+ * Update tests
93
+ * This broke indentation (will be fixed later)
94
+ * Add Plist::Emit.dump, so you can dump objects which don't include Plist::Emit, update tests to match
95
+ * Fix a bug with the method that wraps output in the plist header/footer
96
+
97
+ 2006-08-19 (r1 - r8):
98
+ * The beginnings of merging the plist project into the NARF plist library (under the plist project's name)
99
+ * fancier project infrastructure (more tests, Rakefile, the like)
100
+ * Add/update copyright notices in the source files
101
+ * Move a bunch of documentation out to README
102
+ * Split library into chunks
103
+ * Properly delete files when cleaning up from tests
@@ -1,5 +1,4 @@
1
- Copyright (c) 2006, Ben Bleything <ben@bleything.net>
2
- and Patrick May <patrick@hexane.org>
1
+ Copyright (c) 2006-2010, Ben Bleything and Patrick May
3
2
 
4
3
  Permission is hereby granted, free of charge, to any person obtaining
5
4
  a copy of this software and associated documentation files (the
@@ -1,4 +1,10 @@
1
- == Parsing
1
+ = All-purpose Property List manipulation library
2
+
3
+ Plist is a library to manipulate Property List files, also known as plists. It can parse plist files into native Ruby data structures as well as generating new plist files from your Ruby objects.
4
+
5
+ == Usage
6
+
7
+ === Parsing
2
8
 
3
9
  result = Plist::parse_xml('path/to/example.plist')
4
10
 
@@ -46,7 +52,7 @@
46
52
  </dict>
47
53
  </plist>
48
54
 
49
- == Generation
55
+ === Generation
50
56
 
51
57
  plist also provides the ability to generate plists from Ruby objects. The following Ruby classes are converted into native plist types:
52
58
  Array, Bignum, Date, DateTime, Fixnum, Float, Hash, Integer, String, Symbol, Time, true, false
@@ -102,3 +108,51 @@ An example:
102
108
  When you attempt to serialize a +MyFancyString+ object, the +to_plist_node+ method will be called and the object's contents will be defancified and placed in the plist.
103
109
 
104
110
  If for whatever reason you can't add this method, your object will be serialized with <tt>Marshal.dump</tt> instead.
111
+
112
+ == Links
113
+
114
+ [Project Page] http://plist.rubyforge.org
115
+ [GitHub] http://github.com/bleything/plist
116
+ [RDoc] http://plist.rubyforge.org
117
+
118
+ == Credits
119
+
120
+ plist is maintained by Ben Bleything <mailto:ben@bleything.net> and Patrick May <mailto:patrick@hexane.org>. Patrick wrote most of the code; Ben is a recent addition to the project, having merged in his plist generation library.
121
+
122
+ Other folks who have helped along the way:
123
+
124
+ [<b>Martin Dittus</b>] who pointed out that +Time+ wasn't enough for plist <tt>Dates</tt>, especially those in <tt>~/Library/Cookies/Cookies.plist</tt>
125
+ [<b>Chuck Remes</b>] who pushed Patrick towards implementing <tt>#to_plist</tt>
126
+ [<b>Mat Schaffer</b>] who supplied code and test cases for <tt><data></tt> elements
127
+ [<b>Michael Granger</b>] for encouragement and help
128
+ [<b>Carsten Bormann, Chris Hoffman, Dana Contreras, Hongli Lai, Johan Sørensen</b>] for contributing Ruby 1.9.x compatibility fixes
129
+
130
+ == License and Copyright
131
+
132
+ plist is released under the MIT License.
133
+
134
+ Portions of the code (notably the Rakefile) contain code pulled and/or adapted from other projects. These files contain a comment at the top describing what was used.
135
+
136
+ === MIT License
137
+
138
+ Copyright (c) 2006-2010, Ben Bleything <ben@bleything.net> and Patrick May <patrick@hexane.org>
139
+
140
+ Permission is hereby granted, free of charge, to any person obtaining
141
+ a copy of this software and associated documentation files (the
142
+ "Software"), to deal in the Software without restriction, including
143
+ without limitation the rights to use, copy, modify, merge, publish,
144
+ distribute, sublicense, and/or sell copies of the Software, and to
145
+ permit persons to whom the Software is furnished to do so, subject to
146
+ the following conditions:
147
+
148
+ The above copyright notice and this permission notice shall be included
149
+ in all copies or substantial portions of the Software.
150
+
151
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
152
+ KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
153
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
154
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
155
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
156
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
157
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
158
+
data/Rakefile CHANGED
@@ -1,21 +1,21 @@
1
- ##############################################################
2
- # Copyright 2006, Ben Bleything <ben@bleything.net> and #
3
- # Patrick May <patrick@hexane.org> #
4
- # #
5
- # Based heavily on Geoffrey Grosenbach's Rakefile for gruff. #
6
- # Includes whitespace-fixing task based on code from Typo. #
7
- # #
8
- # Distributed under the MIT license. #
9
- ##############################################################
1
+ #
2
+ # Plist Rakefile
3
+ #
4
+ # Based heavily on Geoffrey Grosenbach's Rakefile for gruff.
5
+ # Includes whitespace-fixing task based on code from Typo.
6
+ #
7
+ # Copyright 2006-2010 Ben Bleything and Patrick May
8
+ # Distributed under the MIT License
9
+ #
10
10
 
11
11
  require 'fileutils'
12
12
  require 'rubygems'
13
13
  require 'rake'
14
14
  require 'rake/testtask'
15
- require 'rake/rdoctask'
16
15
  require 'rake/packagetask'
17
16
  require 'rake/gempackagetask'
18
17
  require 'rake/contrib/rubyforgepublisher'
18
+ require 'rdoc/task'
19
19
 
20
20
  $:.unshift(File.dirname(__FILE__) + "/lib")
21
21
  require 'plist'
@@ -29,10 +29,10 @@ RELEASE_NAME = "REL #{PKG_VERSION}"
29
29
  RUBYFORGE_PROJECT = "plist"
30
30
  RUBYFORGE_USER = ENV['RUBYFORGE_USER']
31
31
 
32
- TEST_FILES = Dir.glob('test/test_*').delete_if { |item| item.include?( "\.svn" ) }
33
- TEST_ASSETS = Dir.glob('test/assets/*').delete_if { |item| item.include?( "\.svn" ) }
34
- LIB_FILES = Dir.glob('lib/**/*').delete_if { |item| item.include?( "\.svn" ) }
35
- RELEASE_FILES = [ "Rakefile", "README", "MIT-LICENSE", "docs/USAGE" ] + LIB_FILES + TEST_FILES + TEST_ASSETS
32
+ TEST_FILES = Dir.glob('test/test_*')
33
+ TEST_ASSETS = Dir.glob('test/assets/*')
34
+ LIB_FILES = Dir.glob('lib/**/*')
35
+ RELEASE_FILES = [ "Rakefile", "README.rdoc", "CHANGELOG", "LICENSE" ] + LIB_FILES + TEST_FILES + TEST_ASSETS
36
36
 
37
37
  task :default => [ :test ]
38
38
  # Run the unit tests
@@ -104,15 +104,19 @@ task :update_rdoc => [ :rdoc ] do
104
104
  end
105
105
 
106
106
  # Genereate the RDoc documentation
107
- Rake::RDocTask.new { |rdoc|
107
+ RDoc::Task.new do |rdoc|
108
+ rdoc.title = "All-purpose Property List manipulation library"
109
+ rdoc.main = "README.rdoc"
110
+
108
111
  rdoc.rdoc_dir = 'rdoc'
109
- rdoc.title = "All-purpose Property List manipulation library"
110
- rdoc.options << '-SNmREADME'
111
- rdoc.template = "docs/jamis-template.rb"
112
- rdoc.rdoc_files.include('README', 'MIT-LICENSE', 'CHANGELOG')
113
- rdoc.rdoc_files.include Dir.glob('docs/**').delete_if {|f| f.include? 'jamis' }
112
+ rdoc.rdoc_files.include('README.rdoc', 'LICENSE', 'CHANGELOG')
114
113
  rdoc.rdoc_files.include('lib/**')
115
- }
114
+
115
+ rdoc.options = [
116
+ '-H', # show hash marks on method names in comments
117
+ '-N', # show line numbers
118
+ ]
119
+ end
116
120
 
117
121
  # Create compressed packages
118
122
  spec = Gem::Specification.new do |s|
@@ -1,14 +1,13 @@
1
- #--
2
- ##############################################################
3
- # Copyright 2006, Ben Bleything <ben@bleything.net> and #
4
- # Patrick May <patrick@hexane.org> #
5
- # #
6
- # Distributed under the MIT license. #
7
- ##############################################################
8
- #++
9
- # = Plist
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # = plist
4
+ #
5
+ # This is the main file for plist. Everything interesting happens in
6
+ # Plist and Plist::Emit.
7
+ #
8
+ # Copyright 2006-2010 Ben Bleything and Patrick May
9
+ # Distributed under the MIT License
10
10
  #
11
- # This is the main file for plist. Everything interesting happens in Plist and Plist::Emit.
12
11
 
13
12
  require 'base64'
14
13
  require 'cgi'
@@ -18,5 +17,5 @@ require 'plist/generator'
18
17
  require 'plist/parser'
19
18
 
20
19
  module Plist
21
- VERSION = '3.0.0'
20
+ VERSION = '3.1.0'
22
21
  end
@@ -1,208 +1,213 @@
1
- #--###########################################################
2
- # Copyright 2006, Ben Bleything <ben@bleything.net> and #
3
- # Patrick May <patrick@hexane.org> #
4
- # #
5
- # Distributed under the MIT license. #
6
- ##############################################################
7
- #++
8
- # See Plist::Emit.
9
- module Plist
10
- # === Create a plist
11
- # You can dump an object to a plist in one of two ways:
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # = plist
4
+ #
5
+ # Copyright 2006-2010 Ben Bleything and Patrick May
6
+ # Distributed under the MIT License
7
+ #
8
+
9
+ module Plist ; end
10
+
11
+ # === Create a plist
12
+ # You can dump an object to a plist in one of two ways:
13
+ #
14
+ # * <tt>Plist::Emit.dump(obj)</tt>
15
+ # * <tt>obj.to_plist</tt>
16
+ # * This requires that you mixin the <tt>Plist::Emit</tt> module, which is already done for +Array+ and +Hash+.
17
+ #
18
+ # The following Ruby classes are converted into native plist types:
19
+ # Array, Bignum, Date, DateTime, Fixnum, Float, Hash, Integer, String, Symbol, Time, true, false
20
+ # * +Array+ and +Hash+ are both recursive; their elements will be converted into plist nodes inside the <array> and <dict> containers (respectively).
21
+ # * +IO+ (and its descendants) and +StringIO+ objects are read from and their contents placed in a <data> element.
22
+ # * 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.
23
+ #
24
+ # For detailed usage instructions, refer to USAGE[link:files/docs/USAGE.html] and the methods documented below.
25
+ module Plist::Emit
26
+ # Helper method for injecting into classes. Calls <tt>Plist::Emit.dump</tt> with +self+.
27
+ def to_plist(envelope = true)
28
+ return Plist::Emit.dump(self, envelope)
29
+ end
30
+
31
+ # Helper method for injecting into classes. Calls <tt>Plist::Emit.save_plist</tt> with +self+.
32
+ def save_plist(filename)
33
+ Plist::Emit.save_plist(self, filename)
34
+ end
35
+
36
+ # The following Ruby classes are converted into native plist types:
37
+ # Array, Bignum, Date, DateTime, Fixnum, Float, Hash, Integer, String, Symbol, Time
12
38
  #
13
- # * <tt>Plist::Emit.dump(obj)</tt>
14
- # * <tt>obj.to_plist</tt>
15
- # * This requires that you mixin the <tt>Plist::Emit</tt> module, which is already done for +Array+ and +Hash+.
39
+ # Write us (via RubyForge) if you think another class can be coerced safely into one of the expected plist classes.
16
40
  #
17
- # The following Ruby classes are converted into native plist types:
18
- # Array, Bignum, Date, DateTime, Fixnum, Float, Hash, Integer, String, Symbol, Time, true, false
19
- # * +Array+ and +Hash+ are both recursive; their elements will be converted into plist nodes inside the <array> and <dict> containers (respectively).
20
- # * +IO+ (and its descendants) and +StringIO+ objects are read from and their contents placed in a <data> element.
21
- # * 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.
41
+ # +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+.
22
42
  #
23
- # For detailed usage instructions, refer to USAGE[link:files/docs/USAGE.html] and the methods documented below.
24
- module Emit
25
- # Helper method for injecting into classes. Calls <tt>Plist::Emit.dump</tt> with +self+.
26
- def to_plist(envelope = true)
27
- return Plist::Emit.dump(self, envelope)
28
- end
43
+ # 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.
44
+ def self.dump(obj, envelope = true)
45
+ output = plist_node(obj)
29
46
 
30
- # Helper method for injecting into classes. Calls <tt>Plist::Emit.save_plist</tt> with +self+.
31
- def save_plist(filename)
32
- Plist::Emit.save_plist(self, filename)
33
- end
34
-
35
- # The following Ruby classes are converted into native plist types:
36
- # Array, Bignum, Date, DateTime, Fixnum, Float, Hash, Integer, String, Symbol, Time
37
- #
38
- # Write us (via RubyForge) if you think another class can be coerced safely into one of the expected plist classes.
39
- #
40
- # +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+.
41
- #
42
- # 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.
43
- def self.dump(obj, envelope = true)
44
- output = plist_node(obj)
45
-
46
- output = wrap(output) if envelope
47
+ output = wrap(output) if envelope
47
48
 
48
- return output
49
- end
49
+ return output
50
+ end
50
51
 
51
- # Writes the serialized object's plist to the specified filename.
52
- def self.save_plist(obj, filename)
53
- File.open(filename, 'wb') do |f|
54
- f.write(obj.to_plist)
55
- end
52
+ # Writes the serialized object's plist to the specified filename.
53
+ def self.save_plist(obj, filename)
54
+ File.open(filename, 'wb') do |f|
55
+ f.write(obj.to_plist)
56
56
  end
57
+ end
57
58
 
58
- private
59
- def self.plist_node(element)
60
- output = ''
59
+ private
60
+ def self.plist_node(element)
61
+ output = ''
62
+
63
+ if element.respond_to? :to_plist_node
64
+ output << element.to_plist_node
65
+ else
66
+ case element
67
+ when Array
68
+ if element.empty?
69
+ output << "<array/>\n"
70
+ else
71
+ output << tag('array') {
72
+ element.collect {|e| plist_node(e)}
73
+ }
74
+ end
75
+ when Hash
76
+ if element.empty?
77
+ output << "<dict/>\n"
78
+ else
79
+ inner_tags = []
61
80
 
62
- if element.respond_to? :to_plist_node
63
- output << element.to_plist_node
64
- else
65
- case element
66
- when Array
67
- if element.empty?
68
- output << "<array/>\n"
69
- else
70
- output << tag('array') {
71
- element.collect {|e| plist_node(e)}
72
- }
73
- end
74
- when Hash
75
- if element.empty?
76
- output << "<dict/>\n"
77
- else
78
- inner_tags = []
79
-
80
- element.keys.sort.each do |k|
81
- v = element[k]
82
- inner_tags << tag('key', CGI::escapeHTML(k.to_s))
83
- inner_tags << plist_node(v)
84
- end
85
-
86
- output << tag('dict') {
87
- inner_tags
88
- }
81
+ element.keys.sort.each do |k|
82
+ v = element[k]
83
+ inner_tags << tag('key', CGI::escapeHTML(k.to_s))
84
+ inner_tags << plist_node(v)
89
85
  end
90
- when true, false
91
- output << "<#{element}/>\n"
92
- when Time
93
- output << tag('date', element.utc.strftime('%Y-%m-%dT%H:%M:%SZ'))
94
- when Date # also catches DateTime
95
- output << tag('date', element.strftime('%Y-%m-%dT%H:%M:%SZ'))
96
- when String, Symbol, Fixnum, Bignum, Integer, Float
97
- output << tag(element_type(element), CGI::escapeHTML(element.to_s))
98
- when IO, StringIO
99
- element.rewind
100
- contents = element.read
101
- # note that apple plists are wrapped at a different length then
102
- # what ruby's base64 wraps by default.
103
- # I used #encode64 instead of #b64encode (which allows a length arg)
104
- # because b64encode is b0rked and ignores the length arg.
105
- data = "\n"
106
- Base64::encode64(contents).gsub(/\s+/, '').scan(/.{1,68}/o) { data << $& << "\n" }
107
- output << tag('data', data)
108
- else
109
- output << comment( 'The <data> element below contains a Ruby object which has been serialized with Marshal.dump.' )
110
- data = "\n"
111
- Base64::encode64(Marshal.dump(element)).gsub(/\s+/, '').scan(/.{1,68}/o) { data << $& << "\n" }
112
- output << tag('data', data )
86
+
87
+ output << tag('dict') {
88
+ inner_tags
89
+ }
113
90
  end
91
+ when true, false
92
+ output << "<#{element}/>\n"
93
+ when Time
94
+ output << tag('date', element.utc.strftime('%Y-%m-%dT%H:%M:%SZ'))
95
+ when Date # also catches DateTime
96
+ output << tag('date', element.strftime('%Y-%m-%dT%H:%M:%SZ'))
97
+ when String, Symbol, Fixnum, Bignum, Integer, Float
98
+ output << tag(element_type(element), CGI::escapeHTML(element.to_s))
99
+ when IO, StringIO
100
+ element.rewind
101
+ contents = element.read
102
+ # note that apple plists are wrapped at a different length then
103
+ # what ruby's base64 wraps by default.
104
+ # I used #encode64 instead of #b64encode (which allows a length arg)
105
+ # because b64encode is b0rked and ignores the length arg.
106
+ data = "\n"
107
+ Base64::encode64(contents).gsub(/\s+/, '').scan(/.{1,68}/o) { data << $& << "\n" }
108
+ output << tag('data', data)
109
+ else
110
+ output << comment( 'The <data> element below contains a Ruby object which has been serialized with Marshal.dump.' )
111
+ data = "\n"
112
+ Base64::encode64(Marshal.dump(element)).gsub(/\s+/, '').scan(/.{1,68}/o) { data << $& << "\n" }
113
+ output << tag('data', data )
114
114
  end
115
-
116
- return output
117
115
  end
118
116
 
119
- def self.comment(content)
120
- return "<!-- #{content} -->\n"
121
- end
117
+ return output
118
+ end
122
119
 
123
- def self.tag(type, contents = '', &block)
124
- out = nil
120
+ def self.comment(content)
121
+ return "<!-- #{content} -->\n"
122
+ end
125
123
 
126
- if block_given?
127
- out = IndentedString.new
128
- out << "<#{type}>"
129
- out.raise_indent
124
+ def self.tag(type, contents = '', &block)
125
+ out = nil
130
126
 
131
- out << block.call
127
+ if block_given?
128
+ out = IndentedString.new
129
+ out << "<#{type}>"
130
+ out.raise_indent
132
131
 
133
- out.lower_indent
134
- out << "</#{type}>"
135
- else
136
- out = "<#{type}>#{contents.to_s}</#{type}>\n"
137
- end
132
+ out << block.call
138
133
 
139
- return out.to_s
134
+ out.lower_indent
135
+ out << "</#{type}>"
136
+ else
137
+ out = "<#{type}>#{contents.to_s}</#{type}>\n"
140
138
  end
141
139
 
142
- def self.wrap(contents)
143
- output = ''
140
+ return out.to_s
141
+ end
144
142
 
145
- output << '<?xml version="1.0" encoding="UTF-8"?>' + "\n"
146
- output << '<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' + "\n"
147
- output << '<plist version="1.0">' + "\n"
143
+ def self.wrap(contents)
144
+ output = ''
148
145
 
149
- output << contents
146
+ output << '<?xml version="1.0" encoding="UTF-8"?>' + "\n"
147
+ output << '<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' + "\n"
148
+ output << '<plist version="1.0">' + "\n"
150
149
 
151
- output << '</plist>' + "\n"
150
+ output << contents
152
151
 
153
- return output
154
- end
152
+ output << '</plist>' + "\n"
155
153
 
156
- def self.element_type(item)
157
- return case item
158
- when String, Symbol: 'string'
159
- when Fixnum, Bignum, Integer: 'integer'
160
- when Float: 'real'
161
- else
162
- raise "Don't know about this data type... something must be wrong!"
163
- end
164
- end
165
- private
166
- class IndentedString #:nodoc:
167
- attr_accessor :indent_string
154
+ return output
155
+ end
168
156
 
169
- @@indent_level = 0
157
+ def self.element_type(item)
158
+ case item
159
+ when String, Symbol
160
+ 'string'
170
161
 
171
- def initialize(str = "\t")
172
- @indent_string = str
173
- @contents = ''
174
- end
162
+ when Fixnum, Bignum, Integer
163
+ 'integer'
175
164
 
176
- def to_s
177
- return @contents
178
- end
165
+ when Float
166
+ 'real'
179
167
 
180
- def raise_indent
181
- @@indent_level += 1
182
- end
168
+ else
169
+ raise "Don't know about this data type... something must be wrong!"
170
+ end
171
+ end
172
+ private
173
+ class IndentedString #:nodoc:
174
+ attr_accessor :indent_string
175
+
176
+ def initialize(str = "\t")
177
+ @indent_string = str
178
+ @contents = ''
179
+ @indent_level = 0
180
+ end
183
181
 
184
- def lower_indent
185
- @@indent_level -= 1 if @@indent_level > 0
186
- end
182
+ def to_s
183
+ return @contents
184
+ end
187
185
 
188
- def <<(val)
189
- if val.is_a? Array
190
- val.each do |f|
191
- self << f
192
- end
193
- else
194
- # if it's already indented, don't bother indenting further
195
- unless val =~ /\A#{@indent_string}/
196
- indent = @indent_string * @@indent_level
186
+ def raise_indent
187
+ @indent_level += 1
188
+ end
197
189
 
198
- @contents << val.gsub(/^/, indent)
199
- else
200
- @contents << val
201
- end
190
+ def lower_indent
191
+ @indent_level -= 1 if @indent_level > 0
192
+ end
193
+
194
+ def <<(val)
195
+ if val.is_a? Array
196
+ val.each do |f|
197
+ self << f
198
+ end
199
+ else
200
+ # if it's already indented, don't bother indenting further
201
+ unless val =~ /\A#{@indent_string}/
202
+ indent = @indent_string * @indent_level
202
203
 
203
- # it already has a newline, don't add another
204
- @contents << "\n" unless val =~ /\n$/
204
+ @contents << val.gsub(/^/, indent)
205
+ else
206
+ @contents << val
205
207
  end
208
+
209
+ # it already has a newline, don't add another
210
+ @contents << "\n" unless val =~ /\n$/
206
211
  end
207
212
  end
208
213
  end
@@ -1,10 +1,11 @@
1
- #--###########################################################
2
- # Copyright 2006, Ben Bleything <ben@bleything.net> and #
3
- # Patrick May <patrick@hexane.org> #
4
- # #
5
- # Distributed under the MIT license. #
6
- ##############################################################
7
- #++
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # = plist
4
+ #
5
+ # Copyright 2006-2010 Ben Bleything and Patrick May
6
+ # Distributed under the MIT License
7
+ #
8
+
8
9
  # Plist parses Mac OS X xml property list files into ruby data structures.
9
10
  #
10
11
  # === Load a plist file
@@ -59,8 +60,15 @@ module Plist
59
60
  end
60
61
 
61
62
  class StreamParser
62
- def initialize( filename_or_xml, listener )
63
- @filename_or_xml = filename_or_xml
63
+ def initialize( plist_data_or_file, listener )
64
+ if plist_data_or_file.respond_to? :read
65
+ @xml = plist_data_or_file.read
66
+ elsif File.exists? plist_data_or_file
67
+ @xml = File.read( plist_data_or_file )
68
+ else
69
+ @xml = plist_data_or_file
70
+ end
71
+
64
72
  @listener = listener
65
73
  end
66
74
 
@@ -78,15 +86,7 @@ module Plist
78
86
 
79
87
  require 'strscan'
80
88
 
81
- contents = (
82
- if (File.exists? @filename_or_xml)
83
- File.open(@filename_or_xml) {|f| f.read}
84
- else
85
- @filename_or_xml
86
- end
87
- )
88
-
89
- @scanner = StringScanner.new( contents )
89
+ @scanner = StringScanner.new( @xml )
90
90
  until @scanner.eos?
91
91
  if @scanner.scan(COMMENT_START)
92
92
  @scanner.scan(COMMENT_END)
@@ -1,9 +1,4 @@
1
- ##############################################################
2
- # Copyright 2006, Ben Bleything <ben@bleything.net> and #
3
- # Patrick May <patrick@hexane.org> #
4
- # #
5
- # Distributed under the MIT license. #
6
- ##############################################################
1
+ #!/usr/bin/env ruby
7
2
 
8
3
  require 'test/unit'
9
4
  require 'plist'
@@ -18,9 +13,12 @@ class MarshalableObject
18
13
  end
19
14
 
20
15
  class TestDataElements < Test::Unit::TestCase
21
- @@result = Plist::parse_xml('test/assets/test_data_elements.plist')
22
16
 
23
- def test_marshal
17
+ def setup
18
+ @result = Plist.parse_xml( 'test/assets/test_data_elements.plist' )
19
+ end
20
+
21
+ def test_data_object_header
24
22
  expected = <<END
25
23
  <!-- The <data> element below contains a Ruby object which has been serialized with Marshal.dump. -->
26
24
  <data>
@@ -28,14 +26,25 @@ BAhvOhZNYXJzaGFsYWJsZU9iamVjdAY6CUBmb28iHnRoaXMgb2JqZWN0IHdhcyBtYXJz
28
26
  aGFsZWQ=
29
27
  </data>
30
28
  END
29
+ expected_elements = expected.chomp.split( "\n" )
31
30
 
32
- mo = MarshalableObject.new('this object was marshaled')
31
+ actual = Plist::Emit.dump( Object.new, false )
32
+ actual_elements = actual.chomp.split( "\n" )
33
33
 
34
- assert_equal expected.chomp, Plist::Emit.dump(mo, false).chomp
34
+ # check for header
35
+ assert_equal expected_elements.shift, actual_elements.shift
36
+
37
+ # check for opening and closing data tags
38
+ assert_equal expected_elements.shift, actual_elements.shift
39
+ assert_equal expected_elements.pop, actual_elements.pop
40
+ end
35
41
 
36
- assert_instance_of MarshalableObject, @@result['marshal']
42
+ def test_marshal_round_trip
43
+ expected = MarshalableObject.new('this object was marshaled')
44
+ actual = Plist.parse_xml( Plist::Emit.dump(expected, false) )
37
45
 
38
- assert_equal mo.foo, @@result['marshal'].foo
46
+ assert_kind_of expected.class, actual
47
+ assert_equal expected.foo, actual.foo
39
48
  end
40
49
 
41
50
  def test_generator_io_and_file
@@ -57,14 +66,14 @@ END
57
66
  assert_equal expected, Plist::Emit.dump(io, false).chomp
58
67
  assert_equal expected, Plist::Emit.dump(f, false).chomp
59
68
 
60
- assert_instance_of StringIO, @@result['io']
61
- assert_instance_of StringIO, @@result['file']
69
+ assert_instance_of StringIO, @result['io']
70
+ assert_instance_of StringIO, @result['file']
62
71
 
63
72
  io.rewind
64
73
  f.rewind
65
74
 
66
- assert_equal io.read, @@result['io'].read
67
- assert_equal f.read, @@result['file'].read
75
+ assert_equal io.read, @result['io'].read
76
+ assert_equal f.read, @result['file'].read
68
77
 
69
78
  io.close
70
79
  f.close
@@ -81,10 +90,10 @@ END
81
90
 
82
91
  assert_equal expected.chomp, Plist::Emit.dump(sio, false).chomp
83
92
 
84
- assert_instance_of StringIO, @@result['stringio']
93
+ assert_instance_of StringIO, @result['stringio']
85
94
 
86
95
  sio.rewind
87
- assert_equal sio.read, @@result['stringio'].read
96
+ assert_equal sio.read, @result['stringio'].read
88
97
  end
89
98
 
90
99
  # this functionality is credited to Mat Schaffer,
@@ -1,9 +1,4 @@
1
- ##############################################################
2
- # Copyright 2006, Ben Bleything <ben@bleything.net> and #
3
- # Patrick May <patrick@hexane.org> #
4
- # #
5
- # Distributed under the MIT license. #
6
- ##############################################################
1
+ #!/usr/bin/env ruby
7
2
 
8
3
  require 'test/unit'
9
4
  require 'plist'
@@ -22,7 +17,7 @@ end
22
17
 
23
18
  class TestGenerator < Test::Unit::TestCase
24
19
  def test_to_plist_vs_plist_emit_dump_no_envelope
25
- source = [1, :b, true]
20
+ source = [1, :b, true]
26
21
 
27
22
  to_plist = source.to_plist(false)
28
23
  plist_emit_dump = Plist::Emit.dump(source, false)
@@ -1,9 +1,4 @@
1
- ##############################################################
2
- # Copyright 2006, Ben Bleything <ben@bleything.net> and #
3
- # Patrick May <patrick@hexane.org> #
4
- # #
5
- # Distributed under the MIT license. #
6
- ##############################################################
1
+ #!/usr/bin/env ruby
7
2
 
8
3
  require 'test/unit'
9
4
  require 'plist'
@@ -1,9 +1,4 @@
1
- ##############################################################
2
- # Copyright 2006, Ben Bleything <ben@bleything.net> and #
3
- # Patrick May <patrick@hexane.org> #
4
- # #
5
- # Distributed under the MIT license. #
6
- ##############################################################
1
+ #!/usr/bin/env ruby
7
2
 
8
3
  require 'test/unit'
9
4
  require 'plist'
@@ -1,12 +1,6 @@
1
- ##############################################################
2
- # Copyright 2006, Ben Bleything <ben@bleything.net> and #
3
- # Patrick May <patrick@hexane.org> #
4
- # #
5
- # Distributed under the MIT license. #
6
- ##############################################################
1
+ #!/usr/bin/env ruby
7
2
 
8
3
  require 'test/unit'
9
-
10
4
  require 'plist'
11
5
 
12
6
  class TestParser < Test::Unit::TestCase
@@ -15,15 +9,18 @@ class TestParser < Test::Unit::TestCase
15
9
 
16
10
  # dict
17
11
  assert_kind_of( Hash, result )
18
- assert_equal( ["List of Albums",
19
- "Minor Version",
20
- "Master Image List",
21
- "Major Version",
22
- "List of Keywords",
23
- "Archive Path",
24
- "List of Rolls",
25
- "Application Version"],
26
- result.keys )
12
+
13
+ expected = [
14
+ "List of Albums",
15
+ "Minor Version",
16
+ "Master Image List",
17
+ "Major Version",
18
+ "List of Keywords",
19
+ "Archive Path",
20
+ "List of Rolls",
21
+ "Application Version"
22
+ ]
23
+ assert_equal( expected.sort, result.keys.sort )
27
24
 
28
25
  # array
29
26
  assert_kind_of( Array, result["List of Rolls"] )
@@ -62,7 +59,7 @@ class TestParser < Test::Unit::TestCase
62
59
  def test_date_fields
63
60
  result = Plist::parse_xml("test/assets/Cookies.plist")
64
61
  assert_kind_of( DateTime, result.first['Expires'] )
65
- assert_equal( "2007-10-25T12:36:35Z", result.first['Expires'].to_s )
62
+ assert_equal DateTime.parse( "2007-10-25T12:36:35Z" ), result.first['Expires']
66
63
  end
67
64
 
68
65
  # bug fix for empty <key>
@@ -85,6 +82,16 @@ class TestParser < Test::Unit::TestCase
85
82
  assert_nil( Plist::parse_xml( File.read('test/assets/commented.plist') ) )
86
83
  end
87
84
  end
85
+
86
+ def test_filename_or_xml_is_stringio
87
+ require 'stringio'
88
+
89
+ str = StringIO.new
90
+ data = Plist::parse_xml(str)
91
+
92
+ assert_nil data
93
+ end
94
+
88
95
  end
89
96
 
90
97
  __END__
metadata CHANGED
@@ -1,42 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
3
- specification_version: 1
4
2
  name: plist
5
3
  version: !ruby/object:Gem::Version
6
- version: 3.0.0
7
- date: 2006-09-20 00:00:00 -07:00
8
- summary: All-purpose Property List manipulation library.
9
- require_paths:
10
- - lib
11
- email:
12
- homepage: http://plist.rubyforge.org
13
- rubyforge_project: plist
14
- description: Plist is a library to manipulate Property List files, also known as plists. It can parse plist files into native Ruby data structures as well as generating new plist files from your Ruby objects.
15
- autorequire: plist
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ prerelease: false
5
+ segments:
6
+ - 3
7
+ - 1
8
+ - 0
9
+ version: 3.1.0
25
10
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
11
  authors:
30
12
  - Ben Bleything and Patrick May
13
+ autorequire: plist
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-02-23 00:00:00 -08:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: |
22
+ Plist is a library to manipulate Property List files, also known as plists. It can parse plist files into native Ruby data structures as well as generating new plist files from your Ruby objects.
23
+
24
+ email:
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
31
  files:
32
32
  - Rakefile
33
- - README
34
- - MIT-LICENSE
35
- - docs/USAGE
36
- - lib/plist
37
- - lib/plist.rb
33
+ - README.rdoc
34
+ - CHANGELOG
35
+ - LICENSE
38
36
  - lib/plist/generator.rb
39
37
  - lib/plist/parser.rb
38
+ - lib/plist.rb
40
39
  - test/test_data_elements.rb
41
40
  - test/test_generator.rb
42
41
  - test/test_generator_basic_types.rb
@@ -50,21 +49,39 @@ files:
50
49
  - test/assets/example_data.plist
51
50
  - test/assets/test_data_elements.plist
52
51
  - test/assets/test_empty_key.plist
52
+ has_rdoc: true
53
+ homepage: http://plist.rubyforge.org
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options: []
58
+
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ requirements: []
76
+
77
+ rubyforge_project: plist
78
+ rubygems_version: 1.3.6
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: All-purpose Property List manipulation library.
53
82
  test_files:
54
83
  - test/test_data_elements.rb
55
84
  - test/test_generator.rb
56
85
  - test/test_generator_basic_types.rb
57
86
  - test/test_generator_collections.rb
58
87
  - test/test_parser.rb
59
- rdoc_options: []
60
-
61
- extra_rdoc_files: []
62
-
63
- executables: []
64
-
65
- extensions: []
66
-
67
- requirements: []
68
-
69
- dependencies: []
70
-
data/README DELETED
@@ -1,36 +0,0 @@
1
- = All-purpose Property List manipulation library
2
-
3
- Plist is a library to manipulate Property List files, also known as plists. It can parse plist files into native Ruby data structures as well as generating new plist files from your Ruby objects.
4
-
5
- == Usage
6
-
7
- See USAGE[link:files/docs/USAGE.html].
8
-
9
- == Links
10
-
11
- [<b>Project Page</b>] http://plist.rubyforge.org
12
- [<b>Subversion repository</b>] svn://rubyforge.org//var/svn/plist
13
- [<b>RDoc (on RubyForge)</b>] http://plist.rubyforge.org
14
-
15
- == Credits
16
-
17
- plist is maintained by Ben Bleything <mailto:ben@bleything.net> and Patrick May <mailto:patrick@hexane.org>. Patrick wrote most of the code; Ben is a recent addition to the project, having merged in his plist generation library.
18
-
19
- Other folks who have helped along the way:
20
-
21
- [<b>Martin Dittus</b>] who pointed out that +Time+ wasn't enough for plist <tt>Dates</tt>, especially those in <tt>~/Library/Cookies/Cookies.plist</tt>
22
- [<b>Chuck Remes</b>] who pushed Patrick towards implementing <tt>#to_plist</tt>
23
- [<b>Mat Schaffer</b>] who supplied code and test cases for <tt><data></tt> elements
24
- [<b>Michael Granger</b>] for encouragement and help
25
-
26
- == License and Copyright
27
-
28
- plist is released under the MIT License.
29
-
30
- Portions of the code (notably the Rakefile) contain code pulled and/or adapted from other projects. These files contain a comment at the top describing what was used.
31
-
32
- === MIT License
33
-
34
- :include: MIT-LICENSE
35
-
36
-