diff options
author | Ben Bleything <ben@bleything.net> | 2006-09-20 04:59:10 +0000 |
---|---|---|
committer | Ben Bleything <ben@bleything.net> | 2006-09-20 04:59:10 +0000 |
commit | 3156c20b98812a80cda2e0a5365fcb241f1d67df (patch) | |
tree | 53b0d96659222d139f1999cd301bbeee84cc5d5e | |
parent | bb238ac7a844ff6ae9b9165b9eec2daecfa33d25 (diff) | |
download | plist-3156c20b98812a80cda2e0a5365fcb241f1d67df.tar.gz |
fix whitespace
-rw-r--r-- | CHANGELOG | 3 | ||||
-rw-r--r-- | docs/USAGE | 20 | ||||
-rw-r--r-- | lib/plist/generator.rb | 26 | ||||
-rw-r--r-- | lib/plist/parser.rb | 6 | ||||
-rw-r--r-- | test/assets/test_data_elements.plist | 2 | ||||
-rw-r--r-- | test/assets/test_empty_key.plist | 2 | ||||
-rw-r--r-- | test/test_data_elements.rb | 24 | ||||
-rw-r--r-- | test/test_generator.rb | 16 | ||||
-rw-r--r-- | test/test_generator_basic_types.rb | 6 | ||||
-rw-r--r-- | test/test_generator_collections.rb | 6 | ||||
-rw-r--r-- | test/test_parser.rb | 2 |
11 files changed, 57 insertions, 56 deletions
@@ -1,8 +1,9 @@ = plist - All-purpose Property List manipulation library -2006-09-19 (r73): +2006-09-19 (r73 - r75): * Really fix the rakefile this time (apparently I deleted some code that I needed...) * alter the fix_whitespace rake task to ignore the assets directory + * cleanup whitespace 2006-09-18 (r70 - r72): * Update this file ;) @@ -10,7 +10,7 @@ result['ZipPostal'] => "12345" - + ==== Example Property List <?xml version="1.0" encoding="UTF-8"?> @@ -45,12 +45,12 @@ <string>12345</string> </dict> </plist> - + == Generation plist also provides the ability to generate plists from Ruby objects. 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. See below for more details. @@ -60,11 +60,11 @@ plist also provides the ability to generate plists from Ruby objects. The follo There are two ways to generate complete plists. Given an object: obj = [1, :two, {'c' => 0xd}] - + If you've mixed in <tt>Plist::Emit</tt> (which is already done for +Array+ and +Hash+), you can simply call +to_plist+: - + obj.to_plist - + This is equivalent to calling <tt>Plist::Emit.dump(obj)</tt>. Either one will yield: <?xml version="1.0" encoding="UTF-8"?> @@ -79,7 +79,7 @@ This is equivalent to calling <tt>Plist::Emit.dump(obj)</tt>. Either one will y </dict> </array> </plist> - + You can also dump plist fragments by passing +false+ as the second parameter: Plist::Emit.dump('holy cow!', false) @@ -93,12 +93,12 @@ An example: class MyFancyString ... - + def to_plist_node return "<string>#{self.defancify}</string>" end end - + 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. -If for whatever reason you can't add this method, your object will be serialized with <tt>Marshal.dump</tt> instead.
\ No newline at end of file +If for whatever reason you can't add this method, your object will be serialized with <tt>Marshal.dump</tt> instead. diff --git a/lib/plist/generator.rb b/lib/plist/generator.rb index 223edcc..9a0a057 100644 --- a/lib/plist/generator.rb +++ b/lib/plist/generator.rb @@ -9,11 +9,11 @@ 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). @@ -26,7 +26,7 @@ module Plist 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) @@ -47,7 +47,7 @@ module Plist 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| @@ -58,7 +58,7 @@ module Plist private def self.plist_node(element) output = '' - + if element.respond_to? :to_plist_node output << element.to_plist_node else @@ -115,7 +115,7 @@ module Plist return output end - + def self.comment(content) return "<!-- #{content} -->\n" end @@ -135,7 +135,7 @@ module Plist else out = "<#{type}>#{contents.to_s}</#{type}>\n" end - + return out.to_s end @@ -163,11 +163,11 @@ module Plist end end end - + private class IndentedString attr_accessor :indent_string - + @@indent_level = 0 def initialize(str = "\t") @@ -178,11 +178,11 @@ module Plist def to_s return @contents end - + def raise_indent @@indent_level += 1 end - + def lower_indent @@indent_level -= 1 if @@indent_level > 0 end @@ -196,12 +196,12 @@ module Plist # 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 diff --git a/lib/plist/parser.rb b/lib/plist/parser.rb index f28cb14..7d1de9f 100644 --- a/lib/plist/parser.rb +++ b/lib/plist/parser.rb @@ -69,7 +69,7 @@ module Plist DOCTYPE_PATTERN = /\s*<!DOCTYPE\s+(.*?)(\[|>)/um COMMENT_START = /\A<!--/u COMMENT_END = /.*?-->/um - + def parse plist_tags = PTag::mappings.keys.join('|') @@ -77,7 +77,7 @@ module Plist end_tag = /<\/(#{plist_tags})[^>]*>/i require 'strscan' - + contents = ( if (File.exists? @filename_or_xml) File.open(@filename_or_xml) {|f| f.read} @@ -85,7 +85,7 @@ module Plist @filename_or_xml end ) - + @scanner = StringScanner.new( contents ) until @scanner.eos? if @scanner.scan(COMMENT_START) diff --git a/test/assets/test_data_elements.plist b/test/assets/test_data_elements.plist index fd548c0..78a9be7 100644 --- a/test/assets/test_data_elements.plist +++ b/test/assets/test_data_elements.plist @@ -21,4 +21,4 @@ cyBtYXJzaGFsZWQ= </data> </dict> -</plist>
\ No newline at end of file +</plist> diff --git a/test/assets/test_empty_key.plist b/test/assets/test_empty_key.plist index 5b37513..4527f56 100644 --- a/test/assets/test_empty_key.plist +++ b/test/assets/test_empty_key.plist @@ -10,4 +10,4 @@ <string>2</string> </dict> </dict> -</plist>
\ No newline at end of file +</plist> diff --git a/test/test_data_elements.rb b/test/test_data_elements.rb index 097a28e..0b0ea71 100644 --- a/test/test_data_elements.rb +++ b/test/test_data_elements.rb @@ -28,16 +28,16 @@ BAhvOhZNYXJzaGFsYWJsZU9iamVjdAY6CUBmb28iHnRoaXMgb2JqZWN0IHdhcyBtYXJz aGFsZWQ= </data> END - + mo = MarshalableObject.new('this object was marshaled') assert_equal expected.chomp, Plist::Emit.dump(mo, false).chomp - + assert_instance_of MarshalableObject, @@result['marshal'] - + assert_equal mo.foo, @@result['marshal'].foo end - + def test_generator_io_and_file expected = <<END <data> @@ -50,13 +50,13 @@ END fd = IO.sysopen('test/assets/example_data.bin') io = IO.open(fd, 'r') - + # File is a subclass of IO, so catching IO in the dispatcher should work for File as well... f = File.open('test/assets/example_data.bin') - + assert_equal expected, Plist::Emit.dump(io, false).chomp assert_equal expected, Plist::Emit.dump(f, false).chomp - + assert_instance_of StringIO, @@result['io'] assert_instance_of StringIO, @@result['file'] @@ -78,11 +78,11 @@ dGhpcyBpcyBhIHN0cmluZ2lvIG9iamVjdA== END sio = StringIO.new('this is a stringio object') - + assert_equal expected.chomp, Plist::Emit.dump(sio, false).chomp - + assert_instance_of StringIO, @@result['stringio'] - + sio.rewind assert_equal sio.read, @@result['stringio'].read end @@ -107,9 +107,9 @@ END # However, the interface promise is to return an IO, not a particular class. # plist used to return Tempfiles, which was changed solely for performance reasons. data['image'] = StringIO.new( File.read("test/assets/example_data.jpg")) - + assert_equal(expected, data.to_plist ) end - + end diff --git a/test/test_generator.rb b/test/test_generator.rb index 540afa3..bef2c63 100644 --- a/test/test_generator.rb +++ b/test/test_generator.rb @@ -10,11 +10,11 @@ require 'plist' class SerializableObject attr_accessor :foo - + def initialize(str) @foo = str end - + def to_plist_node return "<string>#{CGI::escapeHTML @foo}</string>" end @@ -38,22 +38,22 @@ class TestGenerator < Test::Unit::TestCase assert_equal to_plist, plist_emit_dump end - + def test_dumping_serializable_object str = 'this object implements #to_plist_node' so = SerializableObject.new(str) - + assert_equal "<string>#{str}</string>", Plist::Emit.dump(so, false) end - + def test_write_plist data = [1, :two, {:c => 'dee'}] - + data.save_plist('test.plist') file = File.open('test.plist') {|f| f.read} - + assert_equal file, data.to_plist - + File.unlink('test.plist') end end diff --git a/test/test_generator_basic_types.rb b/test/test_generator_basic_types.rb index 322dc9b..d3f627c 100644 --- a/test/test_generator_basic_types.rb +++ b/test/test_generator_basic_types.rb @@ -19,10 +19,10 @@ class TestGeneratorBasicTypes < Test::Unit::TestCase assert_equal expected, Plist::Emit.dump('testdata', false).chomp assert_equal expected, Plist::Emit.dump(:testdata, false).chomp end - + def test_strings_with_escaping expected = wrap('string', "<Fish & Chips>") - + assert_equal expected, Plist::Emit.dump('<Fish & Chips>', false).chomp end @@ -55,4 +55,4 @@ class TestGeneratorBasicTypes < Test::Unit::TestCase assert_equal wrap('date', test_date.strftime('%Y-%m-%dT%H:%M:%SZ')), Plist::Emit.dump(test_date, false).chomp assert_equal wrap('date', test_datetime.strftime('%Y-%m-%dT%H:%M:%SZ')), Plist::Emit.dump(test_datetime, false).chomp end -end
\ No newline at end of file +end diff --git a/test/test_generator_collections.rb b/test/test_generator_collections.rb index bad7a5d..e6a21d0 100644 --- a/test/test_generator_collections.rb +++ b/test/test_generator_collections.rb @@ -20,12 +20,12 @@ END assert_equal expected, [1,2,3].to_plist(false) end - + def test_empty_array expected = <<END <array/> END - + assert_equal expected, [].to_plist(false) end @@ -42,7 +42,7 @@ END # so multi-element hash tests should be reliable. We're testing that here too. assert_equal expected, {:foo => :bar, :abc => 123}.to_plist(false) end - + def test_empty_hash expected = <<END <dict/> diff --git a/test/test_parser.rb b/test/test_parser.rb index 26738ff..e3f8cdb 100644 --- a/test/test_parser.rb +++ b/test/test_parser.rb @@ -79,7 +79,7 @@ class TestParser < Test::Unit::TestCase data = Plist::parse_xml('<string>Fish & Chips</string>') assert_equal('Fish & Chips', data) end - + def test_comment_handling_and_empty_plist assert_nothing_raised do assert_nil( Plist::parse_xml( File.read('test/assets/commented.plist') ) ) |