Skip to content
Browse files

initial commit

  • Loading branch information...
0 parents commit a794a7f96254e773333e7854507fcbf3ab7b6fc9 spox committed Jun 12, 2009
85 CHANGELOG
@@ -0,0 +1,85 @@
+= plist - All-purpose Property List manipulation library
+
+2007-02-22 (r81):
+ * 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.
+
+2006-09-20 (r80):
+ * tweak a comment in generator.rb to make it clear that we're not using Base64.b64encode because it's broken.
+
+=== Release version 3.0.0!
+
+2006-09-20 (r77 - r79):
+ * move IndentedString inside Plist::Emit and :nodoc: it
+ * Tag 3.0.0! (from rev 78)
+
+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 ;)
+ * Fix Rakefile
+ * gem install -t now works correctly
+ * Remove super-sekr1t rdoc staging area from rdoc publishing task
+
+2006-09-15 (r64 - r69):
+* Change behavior of empty collection elements to match What Apple Does
+* Fix some gem packaging infrastructure
+
+2006-09-13 (r61 - r63):
+* Merge generator injection removal branch into trunk!
+
+2006-09-13 (r52 - r60):
+* Fix indentation/newlines in generator (finally!)
+* Refix indentation to be more faithful to the way Apple emits their plists
+* Remove horrific regex and replace it with proper comment parsing
+* Empty plists return nil when parsed
+* Sort hash keys before emitting (now we can test multi-element hashes!)
+* Inject #<=> into Symbol so that sorting Symbol-keyed hashes won't freak out
+
+2006-09-12 (r47 - r51):
+* More test rejiggering
+* New tests to expose some bugs
+
+2006-09-10 (r33 - r46):
+* Update tests for new generator code
+* Rejigger some tests
+* 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
+* Marshal.dump unrecognized objects into <data> elements
+* Make the parser strip out comments and Marshal.load <data> elements if possible
+* Update some rdoc
+
+=== Release version 2.1.1!
+
+2006-09-10 (r31 - r32):
+* Added encoding / decoding for entities (&amp; etc)
+* Changed parsing of <data> elements to return StringIO objects
+* Fixed bug with empty <key> tags
+
+2006-08-24 (r25 - r30):
+* Invert ownership of methods in the generator, allowing us to remove the self.extend(self)
+* New branch to remove method inject from parser
+
+2006-08-23 (r22 - r24):
+* Add rcov task to Rakefile
+* Add some tests
+
+2006-08-20 (r9 - r21):
+* Add a bunch of rdoc and rdoc infrastructure
+* Add rake task to clean up errant whitespace
+* Spin off a branch to remove a bunch of method injection in the generator code
+* Rename some tests for clarity's sake
+* Replace NARF generation code with Ben's generation code
+ * Update tests
+ * This broke indentation (will be fixed later)
+* Add Plist::Emit.dump, so you can dump objects which don't include Plist::Emit, update tests to match
+* Fix a bug with the method that wraps output in the plist header/footer
+
+2006-08-19 (r1 - r8):
+* The beginnings of merging the plist project into the NARF plist library (under the plist project's name)
+ * fancier project infrastructure (more tests, Rakefile, the like)
+ * Add/update copyright notices in the source files
+ * Move a bunch of documentation out to README
+ * Split library into chunks
+* Properly delete files when cleaning up from tests
21 MIT-LICENSE
@@ -0,0 +1,21 @@
+Copyright (c) 2006, Ben Bleything <ben@bleything.net>
+and Patrick May <patrick@hexane.org>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 README
@@ -0,0 +1,36 @@
+= All-purpose Property List manipulation library
+
+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.
+
+== Usage
+
+See USAGE[link:files/docs/USAGE.html].
+
+== Links
+
+[<b>Project Page</b>] http://plist.rubyforge.org
+[<b>Subversion repository</b>] svn://rubyforge.org//var/svn/plist
+[<b>RDoc (on RubyForge)</b>] http://plist.rubyforge.org
+
+== Credits
+
+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.
+
+Other folks who have helped along the way:
+
+[<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>
+[<b>Chuck Remes</b>] who pushed Patrick towards implementing <tt>#to_plist</tt>
+[<b>Mat Schaffer</b>] who supplied code and test cases for <tt><data></tt> elements
+[<b>Michael Granger</b>] for encouragement and help
+
+== License and Copyright
+
+plist is released under the MIT License.
+
+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.
+
+=== MIT License
+
+:include: MIT-LICENSE
+
+
144 Rakefile
@@ -0,0 +1,144 @@
+##############################################################
+# Copyright 2006, Ben Bleything <ben@bleything.net> and #
+# Patrick May <patrick@hexane.org> #
+# #
+# Based heavily on Geoffrey Grosenbach's Rakefile for gruff. #
+# Includes whitespace-fixing task based on code from Typo. #
+# #
+# Distributed under the MIT license. #
+##############################################################
+
+require 'fileutils'
+require 'rubygems'
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+require 'rake/packagetask'
+require 'rake/gempackagetask'
+require 'rake/contrib/rubyforgepublisher'
+
+$:.unshift(File.dirname(__FILE__) + "/lib")
+require 'plist'
+
+PKG_NAME = 'plist'
+PKG_VERSION = Plist::VERSION
+PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
+
+RELEASE_NAME = "REL #{PKG_VERSION}"
+
+RUBYFORGE_PROJECT = "plist"
+RUBYFORGE_USER = ENV['RUBYFORGE_USER']
+
+TEST_FILES = Dir.glob('test/test_*').delete_if { |item| item.include?( "\.svn" ) }
+TEST_ASSETS = Dir.glob('test/assets/*').delete_if { |item| item.include?( "\.svn" ) }
+LIB_FILES = Dir.glob('lib/**/*').delete_if { |item| item.include?( "\.svn" ) }
+RELEASE_FILES = [ "Rakefile", "README", "MIT-LICENSE", "docs/USAGE" ] + LIB_FILES + TEST_FILES + TEST_ASSETS
+
+task :default => [ :test ]
+# Run the unit tests
+Rake::TestTask.new { |t|
+ t.libs << "test"
+ t.pattern = 'test/test_*.rb'
+ t.verbose = true
+}
+
+desc "Clean pkg, coverage, and rdoc; remove .bak files"
+task :clean => [ :clobber_rdoc, :clobber_package, :clobber_coverage ] do
+ puts cmd = "find . -type f -name *.bak -delete"
+ `#{cmd}`
+end
+
+task :clobber_coverage do
+ puts cmd = "rm -rf coverage"
+ `#{cmd}`
+end
+
+desc "Generate coverage analysis with rcov (requires rcov to be installed)"
+task :rcov => [ :clobber_coverage ] do
+ puts cmd = "rcov -Ilib --xrefs -T test/*.rb"
+ puts `#{cmd}`
+end
+
+desc "Strip trailing whitespace and fix newlines for all release files"
+task :fix_whitespace => [ :clean ] do
+ RELEASE_FILES.reject {|i| i =~ /assets/}.each do |filename|
+ next if File.directory? filename
+
+ File.open(filename) do |file|
+ newfile = ''
+ needs_love = false
+
+ file.readlines.each_with_index do |line, lineno|
+ if line =~ /[ \t]+$/
+ needs_love = true
+ puts "#{filename}: trailing whitespace on line #{lineno}"
+ line.gsub!(/[ \t]*$/, '')
+ end
+
+ if line.chomp == line
+ needs_love = true
+ puts "#{filename}: no newline on line #{lineno}"
+ line << "\n"
+ end
+
+ newfile << line
+ end
+
+ if needs_love
+ tempname = "#{filename}.new"
+
+ File.open(tempname, 'w').write(newfile)
+ File.chmod(File.stat(filename).mode, tempname)
+
+ FileUtils.ln filename, "#{filename}.bak"
+ FileUtils.ln tempname, filename, :force => true
+ File.unlink(tempname)
+ end
+ end
+ end
+end
+
+desc "Copy documentation to rubyforge"
+task :update_rdoc => [ :rdoc ] do
+ Rake::SshDirPublisher.new("#{RUBYFORGE_USER}@rubyforge.org", "/var/www/gforge-projects/#{RUBYFORGE_PROJECT}", "rdoc").upload
+end
+
+# Genereate the RDoc documentation
+Rake::RDocTask.new { |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = "All-purpose Property List manipulation library"
+ rdoc.options << '-SNmREADME'
+ rdoc.template = "docs/jamis-template.rb"
+ rdoc.rdoc_files.include('README', 'MIT-LICENSE', 'CHANGELOG')
+ rdoc.rdoc_files.include Dir.glob('docs/**').delete_if {|f| f.include? 'jamis' }
+ rdoc.rdoc_files.include('lib/**')
+}
+
+# Create compressed packages
+spec = Gem::Specification.new do |s|
+ s.name = PKG_NAME
+ s.version = PKG_VERSION
+
+ s.summary = "All-purpose Property List manipulation library."
+ s.description = <<-EOD
+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.
+EOD
+
+ s.authors = "Ben Bleything and Patrick May"
+ s.homepage = "http://plist.rubyforge.org"
+
+ s.rubyforge_project = RUBYFORGE_PROJECT
+
+ s.has_rdoc = true
+
+ s.files = RELEASE_FILES
+ s.test_files = TEST_FILES
+
+ s.autorequire = 'plist'
+end
+
+Rake::GemPackageTask.new(spec) do |p|
+ p.gem_spec = spec
+ p.need_tar = true
+ p.need_zip = true
+end
104 docs/USAGE
@@ -0,0 +1,104 @@
+== Parsing
+
+ result = Plist::parse_xml('path/to/example.plist')
+
+ result.class
+ => Hash
+
+ "#{result['FirstName']} #{result['LastName']}"
+ => "John Public"
+
+ result['ZipPostal']
+ => "12345"
+
+==== Example Property List
+
+ <?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+ <plist version="1.0">
+ <dict>
+ <key>FirstName</key>
+ <string>John</string>
+
+ <key>LastName</key>
+ <string>Public</string>
+
+ <key>StreetAddr1</key>
+ <string>123 Anywhere St.</string>
+
+ <key>StateProv</key>
+ <string>CA</string>
+
+ <key>City</key>
+ <string>Some Town</string>
+
+ <key>CountryName</key>
+ <string>United States</string>
+
+ <key>AreaCode</key>
+ <string>555</string>
+
+ <key>LocalPhoneNumber</key>
+ <string>5551212</string>
+
+ <key>ZipPostal</key>
+ <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.
+
+==== Creating a plist
+
+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"?>
+ <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+ <plist version="1.0">
+ <array>
+ <integer>1</integer>
+ <string>two</string>
+ <dict>
+ <key>c</key>
+ <integer>13</integer>
+ </dict>
+ </array>
+ </plist>
+
+You can also dump plist fragments by passing +false+ as the second parameter:
+
+ Plist::Emit.dump('holy cow!', false)
+ => "<string>holy cow!</string>"
+
+==== Custom serialization
+
+If your class can be safely coerced into a native plist datatype, you can implement +to_plist_node+. Upon encountering an object of a class it doesn't recognize, the plist library will check to see if it responds to +to_plist_node+, and if so, insert the result of that call into the plist output.
+
+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.
591 docs/jamis-template.rb
@@ -0,0 +1,591 @@
+module RDoc
+module Page
+
+FONTS = "\"Bitstream Vera Sans\", Verdana, Arial, Helvetica, sans-serif"
+
+STYLE = <<CSS
+a {
+ color: #00F;
+ text-decoration: none;
+}
+
+a:hover {
+ color: #77F;
+ text-decoration: underline;
+}
+
+body, td, p {
+ font-family: %fonts%;
+ background: #FFF;
+ color: #000;
+ margin: 0px;
+ font-size: small;
+}
+
+#content {
+ margin: 2em;
+}
+
+#description p {
+ margin-bottom: 0.5em;
+}
+
+.sectiontitle {
+ margin-top: 1em;
+ margin-bottom: 1em;
+ padding: 0.5em;
+ padding-left: 2em;
+ background: #005;
+ color: #FFF;
+ font-weight: bold;
+ border: 1px dotted black;
+}
+
+.attr-rw {
+ padding-left: 1em;
+ padding-right: 1em;
+ text-align: center;
+ color: #055;
+}
+
+.attr-name {
+ font-weight: bold;
+}
+
+.attr-desc {
+}
+
+.attr-value {
+ font-family: monospace;
+}
+
+.file-title-prefix {
+ font-size: large;
+}
+
+.file-title {
+ font-size: large;
+ font-weight: bold;
+ background: #005;
+ color: #FFF;
+}
+
+.banner {
+ background: #005;
+ color: #FFF;
+ border: 1px solid black;
+ padding: 1em;
+}
+
+.banner td {
+ background: transparent;
+ color: #FFF;
+}
+
+h1 a, h2 a, .sectiontitle a, .banner a {
+ color: #FF0;
+}
+
+h1 a:hover, h2 a:hover, .sectiontitle a:hover, .banner a:hover {
+ color: #FF7;
+}
+
+.dyn-source {
+ display: none;
+ background: #FFE;
+ color: #000;
+ border: 1px dotted black;
+ margin: 0.5em 2em 0.5em 2em;
+ padding: 0.5em;
+}
+
+.dyn-source .cmt {
+ color: #00F;
+ font-style: italic;
+}
+
+.dyn-source .kw {
+ color: #070;
+ font-weight: bold;
+}
+
+.method {
+ margin-left: 1em;
+ margin-right: 1em;
+ margin-bottom: 1em;
+}
+
+.description pre {
+ padding: 0.5em;
+ border: 1px dotted black;
+ background: #FFE;
+}
+
+.method .title {
+ font-family: monospace;
+ font-size: large;
+ border-bottom: 1px dashed black;
+ margin-bottom: 0.3em;
+ padding-bottom: 0.1em;
+}
+
+.method .description, .method .sourcecode {
+ margin-left: 1em;
+}
+
+.description p, .sourcecode p {
+ margin-bottom: 0.5em;
+}
+
+.method .sourcecode p.source-link {
+ text-indent: 0em;
+ margin-top: 0.5em;
+}
+
+.method .aka {
+ margin-top: 0.3em;
+ margin-left: 1em;
+ font-style: italic;
+ text-indent: 2em;
+}
+
+h1 {
+ padding: 1em;
+ border: 1px solid black;
+ font-size: x-large;
+ font-weight: bold;
+ color: #FFF;
+ background: #007;
+}
+
+h2 {
+ padding: 0.5em 1em 0.5em 1em;
+ border: 1px solid black;
+ font-size: large;
+ font-weight: bold;
+ color: #FFF;
+ background: #009;
+}
+
+h3, h4, h5, h6 {
+ padding: 0.2em 1em 0.2em 1em;
+ border: 1px dashed black;
+ color: #000;
+ background: #AAF;
+}
+
+.sourcecode > pre {
+ padding: 0.5em;
+ border: 1px dotted black;
+ background: #FFE;
+}
+
+CSS
+
+XHTML_PREAMBLE = %{<?xml version="1.0" encoding="%charset%"?>
+<!DOCTYPE html
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+}
+
+HEADER = XHTML_PREAMBLE + <<ENDHEADER
+<html>
+ <head>
+ <title>%title%</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=%charset%" />
+ <link rel="stylesheet" href="%style_url%" type="text/css" media="screen" />
+
+ <script language="JavaScript" type="text/javascript">
+ // <![CDATA[
+
+ function toggleSource( id )
+ {
+ var elem
+ var link
+
+ if( document.getElementById )
+ {
+ elem = document.getElementById( id )
+ link = document.getElementById( "l_" + id )
+ }
+ else if ( document.all )
+ {
+ elem = eval( "document.all." + id )
+ link = eval( "document.all.l_" + id )
+ }
+ else
+ return false;
+
+ if( elem.style.display == "block" )
+ {
+ elem.style.display = "none"
+ link.innerHTML = "show source"
+ }
+ else
+ {
+ elem.style.display = "block"
+ link.innerHTML = "hide source"
+ }
+ }
+
+ function openCode( url )
+ {
+ window.open( url, "SOURCE_CODE", "width=400,height=400,scrollbars=yes" )
+ }
+ // ]]>
+ </script>
+ </head>
+
+ <body>
+ENDHEADER
+
+FILE_PAGE = <<HTML
+<table border='0' cellpadding='0' cellspacing='0' width="100%" class='banner'>
+ <tr><td>
+ <table width="100%" border='0' cellpadding='0' cellspacing='0'><tr>
+ <td class="file-title" colspan="2"><span class="file-title-prefix">File</span><br />%short_name%</td>
+ <td align="right">
+ <table border='0' cellspacing="0" cellpadding="2">
+ <tr>
+ <td>Path:</td>
+ <td>%full_path%
+IF:cvsurl
+ &nbsp;(<a href="%cvsurl%">CVS</a>)
+ENDIF:cvsurl
+ </td>
+ </tr>
+ <tr>
+ <td>Modified:</td>
+ <td>%dtm_modified%</td>
+ </tr>
+ </table>
+ </td></tr>
+ </table>
+ </td></tr>
+</table><br>
+HTML
+
+###################################################################
+
+CLASS_PAGE = <<HTML
+<table width="100%" border='0' cellpadding='0' cellspacing='0' class='banner'><tr>
+ <td class="file-title"><span class="file-title-prefix">%classmod%</span><br />%full_name%</td>
+ <td align="right">
+ <table cellspacing=0 cellpadding=2>
+ <tr valign="top">
+ <td>In:</td>
+ <td>
+START:infiles
+HREF:full_path_url:full_path:
+IF:cvsurl
+&nbsp;(<a href="%cvsurl%">CVS</a>)
+ENDIF:cvsurl
+END:infiles
+ </td>
+ </tr>
+IF:parent
+ <tr>
+ <td>Parent:</td>
+ <td>
+IF:par_url
+ <a href="%par_url%">
+ENDIF:par_url
+%parent%
+IF:par_url
+ </a>
+ENDIF:par_url
+ </td>
+ </tr>
+ENDIF:parent
+ </table>
+ </td>
+ </tr>
+ </table>
+HTML
+
+###################################################################
+
+METHOD_LIST = <<HTML
+ <div id="content">
+IF:diagram
+ <table cellpadding='0' cellspacing='0' border='0' width="100%"><tr><td align="center">
+ %diagram%
+ </td></tr></table>
+ENDIF:diagram
+
+IF:description
+ <div class="description">%description%</div>
+ENDIF:description
+
+IF:requires
+ <div class="sectiontitle">Required Files</div>
+ <ul>
+START:requires
+ <li>HREF:aref:name:</li>
+END:requires
+ </ul>
+ENDIF:requires
+
+IF:toc
+ <div class="sectiontitle">Contents</div>
+ <ul>
+START:toc
+ <li><a href="#%href%">%secname%</a></li>
+END:toc
+ </ul>
+ENDIF:toc
+
+IF:methods
+ <div class="sectiontitle">Methods</div>
+ <ul>
+START:methods
+ <li>HREF:aref:name:</li>
+END:methods
+ </ul>
+ENDIF:methods
+
+IF:includes
+<div class="sectiontitle">Included Modules</div>
+<ul>
+START:includes
+ <li>HREF:aref:name:</li>
+END:includes
+</ul>
+ENDIF:includes
+
+START:sections
+IF:sectitle
+<div class="sectiontitle"><a nem="%secsequence%">%sectitle%</a></div>
+IF:seccomment
+<div class="description">
+%seccomment%
+</div>
+ENDIF:seccomment
+ENDIF:sectitle
+
+IF:classlist
+ <div class="sectiontitle">Classes and Modules</div>
+ %classlist%
+ENDIF:classlist
+
+IF:constants
+ <div class="sectiontitle">Constants</div>
+ <table border='0' cellpadding='5'>
+START:constants
+ <tr valign='top'>
+ <td class="attr-name">%name%</td>
+ <td>=</td>
+ <td class="attr-value">%value%</td>
+ </tr>
+IF:desc
+ <tr valign='top'>
+ <td>&nbsp;</td>
+ <td colspan="2" class="attr-desc">%desc%</td>
+ </tr>
+ENDIF:desc
+END:constants
+ </table>
+ENDIF:constants
+
+IF:attributes
+ <div class="sectiontitle">Attributes</div>
+ <table border='0' cellpadding='5'>
+START:attributes
+ <tr valign='top'>
+ <td class='attr-rw'>
+IF:rw
+[%rw%]
+ENDIF:rw
+ </td>
+ <td class='attr-name'>%name%</td>
+ <td class='attr-desc'>%a_desc%</td>
+ </tr>
+END:attributes
+ </table>
+ENDIF:attributes
+
+IF:method_list
+START:method_list
+IF:methods
+<div class="sectiontitle">%type% %category% methods</div>
+START:methods
+<div class="method">
+ <div class="title">
+IF:callseq
+ <a name="%aref%"></a><b>%callseq%</b>
+ENDIF:callseq
+IFNOT:callseq
+ <a name="%aref%"></a><b>%name%</b>%params%
+ENDIF:callseq
+IF:codeurl
+[ <a href="javascript:openCode('%codeurl%')">source</a> ]
+ENDIF:codeurl
+ </div>
+IF:m_desc
+ <div class="description">
+ %m_desc%
+ </div>
+ENDIF:m_desc
+IF:aka
+<div class="aka">
+ This method is also aliased as
+START:aka
+ <a href="%aref%">%name%</a>
+END:aka
+</div>
+ENDIF:aka
+IF:sourcecode
+<div class="sourcecode">
+ <p class="source-link">[ <a href="javascript:toggleSource('%aref%_source')" id="l_%aref%_source">show source</a> ]</p>
+ <div id="%aref%_source" class="dyn-source">
+<pre>
+%sourcecode%
+</pre>
+ </div>
+</div>
+ENDIF:sourcecode
+</div>
+END:methods
+ENDIF:methods
+END:method_list
+ENDIF:method_list
+END:sections
+</div>
+HTML
+
+FOOTER = <<ENDFOOTER
+ </body>
+</html>
+ENDFOOTER
+
+BODY = HEADER + <<ENDBODY
+ !INCLUDE! <!-- banner header -->
+
+ <div id="bodyContent">
+ #{METHOD_LIST}
+ </div>
+
+ #{FOOTER}
+ENDBODY
+
+########################## Source code ##########################
+
+SRC_PAGE = XHTML_PREAMBLE + <<HTML
+<html>
+<head><title>%title%</title>
+<meta http-equiv="Content-Type" content="text/html; charset=%charset%">
+<style>
+.ruby-comment { color: green; font-style: italic }
+.ruby-constant { color: #4433aa; font-weight: bold; }
+.ruby-identifier { color: #222222; }
+.ruby-ivar { color: #2233dd; }
+.ruby-keyword { color: #3333FF; font-weight: bold }
+.ruby-node { color: #777777; }
+.ruby-operator { color: #111111; }
+.ruby-regexp { color: #662222; }
+.ruby-value { color: #662222; font-style: italic }
+ .kw { color: #3333FF; font-weight: bold }
+ .cmt { color: green; font-style: italic }
+ .str { color: #662222; font-style: italic }
+ .re { color: #662222; }
+</style>
+</head>
+<body bgcolor="white">
+<pre>%code%</pre>
+</body>
+</html>
+HTML
+
+########################## Index ################################
+
+FR_INDEX_BODY = <<HTML
+!INCLUDE!
+HTML
+
+FILE_INDEX = XHTML_PREAMBLE + <<HTML
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=%charset%">
+<style>
+<!--
+ body {
+ background-color: #EEE;
+ font-family: #{FONTS};
+ color: #000;
+ margin: 0px;
+ }
+ .banner {
+ background: #005;
+ color: #FFF;
+ padding: 0.2em;
+ font-size: small;
+ font-weight: bold;
+ text-align: center;
+ }
+ .entries {
+ margin: 0.25em 1em 0 1em;
+ font-size: x-small;
+ }
+ a {
+ color: #00F;
+ text-decoration: none;
+ white-space: nowrap;
+ }
+ a:hover {
+ color: #77F;
+ text-decoration: underline;
+ }
+-->
+</style>
+<base target="docwin">
+</head>
+<body>
+<div class="banner">%list_title%</div>
+<div class="entries">
+START:entries
+<a href="%href%">%name%</a><br>
+END:entries
+</div>
+</body></html>
+HTML
+
+CLASS_INDEX = FILE_INDEX
+METHOD_INDEX = FILE_INDEX
+
+INDEX = XHTML_PREAMBLE + <<HTML
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <title>%title%</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=%charset%">
+</head>
+
+<frameset cols="20%,*">
+ <frameset rows="15%,35%,50%">
+ <frame src="fr_file_index.html" title="Files" name="Files" />
+ <frame src="fr_class_index.html" name="Classes" />
+ <frame src="fr_method_index.html" name="Methods" />
+ </frameset>
+IF:inline_source
+ <frame src="%initial_page%" name="docwin">
+ENDIF:inline_source
+IFNOT:inline_source
+ <frameset rows="80%,20%">
+ <frame src="%initial_page%" name="docwin">
+ <frame src="blank.html" name="source">
+ </frameset>
+ENDIF:inline_source
+ <noframes>
+ <body bgcolor="white">
+ Click <a href="html/index.html">here</a> for a non-frames
+ version of this page.
+ </body>
+ </noframes>
+</frameset>
+
+</html>
+HTML
+
+end
+end
+
+
22 lib/plist.rb
@@ -0,0 +1,22 @@
+#--
+##############################################################
+# Copyright 2006, Ben Bleything <ben@bleything.net> and #
+# Patrick May <patrick@hexane.org> #
+# #
+# Distributed under the MIT license. #
+##############################################################
+#++
+# = Plist
+#
+# This is the main file for plist. Everything interesting happens in Plist and Plist::Emit.
+
+require 'base64'
+require 'cgi'
+require 'stringio'
+
+require 'plist/generator'
+require 'plist/parser'
+
+module Plist
+ VERSION = '3.0.0'
+end
227 lib/plist/generator.rb
@@ -0,0 +1,227 @@
+#--###########################################################
+# Copyright 2006, Ben Bleything <ben@bleything.net> and #
+# Patrick May <patrick@hexane.org> #
+# #
+# Distributed under the MIT license. #
+##############################################################
+#++
+# See Plist::Emit.
+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
+ # 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.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, Fixnum, Bignum, 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 Computer//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)
+ return case item
+ when String, Symbol
+ 'string'
+ when Fixnum, Bignum, 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
+
+ @@indent_level = 0
+
+ def initialize(str = "\t")
+ @indent_string = str
+ @contents = ''
+ 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
+
+# we need to add this so sorting hash keys works properly
+class Symbol #:nodoc:
+ def <=> (other)
+ self.to_s <=> other.to_s
+ end
+end
+
+class Array #:nodoc:
+ include Plist::Emit
+end
+
+class Hash #:nodoc:
+ include Plist::Emit
+end
224 lib/plist/generator.rb~
@@ -0,0 +1,224 @@
+#--###########################################################
+# Copyright 2006, Ben Bleything <ben@bleything.net> and #
+# Patrick May <patrick@hexane.org> #
+# #
+# Distributed under the MIT license. #
+##############################################################
+#++
+# See Plist::Emit.
+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
+ # 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.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, Fixnum, Bignum, 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 Computer//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)
+ return case item
+ when String, Symbol: 'string'
+ when Fixnum, Bignum, 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
+
+ @@indent_level = 0
+
+ def initialize(str = "\t")
+ @indent_string = str
+ @contents = ''
+ 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
+
+# we need to add this so sorting hash keys works properly
+class Symbol #:nodoc:
+ def <=> (other)
+ self.to_s <=> other.to_s
+ end
+end
+
+class Array #:nodoc:
+ include Plist::Emit
+end
+
+class Hash #:nodoc:
+ include Plist::Emit
+end
224 lib/plist/parser.rb
@@ -0,0 +1,224 @@
+#--###########################################################
+# Copyright 2006, Ben Bleything <ben@bleything.net> and #
+# Patrick May <patrick@hexane.org> #
+# #
+# Distributed under the MIT license. #
+##############################################################
+#++
+# Plist parses Mac OS X xml property list files into ruby data structures.
+#
+# === Load a plist file
+# This is the main point of the library:
+#
+# r = Plist::parse_xml( filename_or_xml )
+module Plist
+# Note that I don't use these two elements much:
+#
+# + Date elements are returned as DateTime objects.
+# + Data elements are implemented as Tempfiles
+#
+# Plist::parse_xml will blow up if it encounters a data element.
+# 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
+# plist@hexane.org so that I can implement the proper support.
+ def Plist::parse_xml( filename_or_xml )
+ listener = Listener.new
+ #parser = REXML::Parsers::StreamParser.new(File.new(filename), listener)
+ parser = StreamParser.new(filename_or_xml, listener)
+ parser.parse
+ listener.result
+ end
+
+ class Listener
+ #include REXML::StreamListener
+
+ attr_accessor :result, :open
+
+ def initialize
+ @result = nil
+ @open = Array.new
+ end
+
+
+ def tag_start(name, attributes)
+ @open.push PTag::mappings[name].new
+ end
+
+ def text( contents )
+ @open.last.text = contents if @open.last
+ end
+
+ def tag_end(name)
+ last = @open.pop
+ if @open.empty?
+ @result = last.to_ruby
+ else
+ @open.last.children.push last
+ end
+ end
+ end
+
+ class StreamParser
+ def initialize( plist_data_or_file, listener )
+ if plist_data_or_file.respond_to? :read
+ @xml = plist_data_or_file.read
+ elsif File.exists? plist_data_or_file
+ @xml = File.read( plist_data_or_file )
+ else
+ @xml = plist_data_or_file
+ end
+
+ @listener = listener
+ end
+
+ TEXT = /([^<]+)/
+ XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>*/um
+ DOCTYPE_PATTERN = /\s*<!DOCTYPE\s+(.*?)(\[|>)/um
+ COMMENT_START = /\A<!--/u
+ COMMENT_END = /.*?-->/um
+
+
+ def parse
+ plist_tags = PTag::mappings.keys.join('|')
+ start_tag = /<(#{plist_tags})([^>]*)>/i
+ end_tag = /<\/(#{plist_tags})[^>]*>/i
+
+ require 'strscan'
+
+ @scanner = StringScanner.new( @xml )
+ until @scanner.eos?
+ if @scanner.scan(COMMENT_START)
+ @scanner.scan(COMMENT_END)
+ elsif @scanner.scan(XMLDECL_PATTERN)
+ elsif @scanner.scan(DOCTYPE_PATTERN)
+ elsif @scanner.scan(start_tag)
+ @listener.tag_start(@scanner[1], nil)
+ if (@scanner[2] =~ /\/$/)
+ @listener.tag_end(@scanner[1])
+ end
+ elsif @scanner.scan(TEXT)
+ @listener.text(@scanner[1])
+ elsif @scanner.scan(end_tag)
+ @listener.tag_end(@scanner[1])
+ else
+ raise "Unimplemented element"
+ end
+ end
+ end
+ end
+
+ class PTag
+ @@mappings = { }
+ def PTag::mappings
+ @@mappings
+ end
+
+ def PTag::inherited( sub_class )
+ key = sub_class.to_s.downcase
+ key.gsub!(/^plist::/, '' )
+ key.gsub!(/^p/, '') unless key == "plist"
+
+ @@mappings[key] = sub_class
+ end
+
+ attr_accessor :text, :children
+ def initialize
+ @children = Array.new
+ end
+
+ def to_ruby
+ raise "Unimplemented: " + self.class.to_s + "#to_ruby on #{self.inspect}"
+ end
+ end
+
+ class PList < PTag
+ def to_ruby
+ children.first.to_ruby if children.first
+ end
+ end
+
+ class PDict < PTag
+ def to_ruby
+ dict = Hash.new
+ key = nil
+
+ children.each do |c|
+ if key.nil?
+ key = c.to_ruby
+ else
+ dict[key] = c.to_ruby
+ key = nil
+ end
+ end
+
+ dict
+ end
+ end
+
+ class PKey < PTag
+ def to_ruby
+ CGI::unescapeHTML(text || '')
+ end
+ end
+
+ class PString < PTag
+ def to_ruby
+ CGI::unescapeHTML(text || '')
+ end
+ end
+
+ class PArray < PTag
+ def to_ruby
+ children.collect do |c|
+ c.to_ruby
+ end
+ end
+ end
+
+ class PInteger < PTag
+ def to_ruby
+ text.to_i
+ end
+ end
+
+ class PTrue < PTag
+ def to_ruby
+ true
+ end
+ end
+
+ class PFalse < PTag
+ def to_ruby
+ false
+ end
+ end
+
+ class PReal < PTag
+ def to_ruby
+ text.to_f
+ end
+ end
+
+ require 'date'
+ class PDate < PTag
+ def to_ruby
+ DateTime.parse(text)
+ end
+ end
+
+ require 'base64'
+ class PData < PTag
+ def to_ruby
+ data = Base64.decode64(text.gsub(/\s+/, ''))
+
+ begin
+ return Marshal.load(data)
+ rescue Exception => e
+ io = StringIO.new
+ io.write data
+ io.rewind
+ return io
+ end
+ end
+ end
+end
BIN pkg/plist-3.0.0.gem
Binary file not shown.
203 test/assets/AlbumData.xml
@@ -0,0 +1,203 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>Application Version</key>
+ <string>5.0.4 (263)</string>
+ <key>Archive Path</key>
+ <string>/Users/username/Pictures/iPhoto Library</string>
+ <key>List of Albums</key>
+ <array>
+ <dict>
+ <key>AlbumId</key>
+ <integer>999000</integer>
+ <key>AlbumName</key>
+ <string>Library</string>
+ <key>KeyList</key>
+ <array>
+ <string>7</string>
+ </array>
+ <key>Master</key>
+ <true/>
+ <key>PhotoCount</key>
+ <integer>1</integer>
+ <key>PlayMusic</key>
+ <string>YES</string>
+ <key>RepeatSlideShow</key>
+ <string>YES</string>
+ <key>SecondsPerSlide</key>
+ <integer>3</integer>
+ <key>SlideShowUseTitles</key>
+ <false/>
+ <key>SongPath</key>
+ <string></string>
+ <key>TransitionDirection</key>
+ <integer>0</integer>
+ <key>TransitionName</key>
+ <string>Dissolve</string>
+ <key>TransitionSpeed</key>
+ <real>1</real>
+ </dict>
+ <dict>
+ <key>Album Type</key>
+ <string>Special Roll</string>
+ <key>AlbumId</key>
+ <integer>999001</integer>
+ <key>AlbumName</key>
+ <string>Last Roll</string>
+ <key>Filter Mode</key>
+ <string>All</string>
+ <key>Filters</key>
+ <array>
+ <dict>
+ <key>Count</key>
+ <integer>1</integer>
+ <key>Operation</key>
+ <string>In Last</string>
+ <key>Type</key>
+ <string>Roll</string>
+ </dict>
+ </array>
+ <key>KeyList</key>
+ <array>
+ <string>7</string>
+ </array>
+ <key>PhotoCount</key>
+ <integer>1</integer>
+ <key>PlayMusic</key>
+ <string>YES</string>
+ <key>RepeatSlideShow</key>
+ <string>YES</string>
+ <key>SecondsPerSlide</key>
+ <integer>3</integer>
+ <key>SlideShowUseTitles</key>
+ <false/>
+ <key>SongPath</key>
+ <string></string>
+ <key>TransitionDirection</key>
+ <integer>0</integer>
+ <key>TransitionName</key>
+ <string>Dissolve</string>
+ <key>TransitionSpeed</key>
+ <real>1</real>
+ </dict>
+ <dict>
+ <key>Album Type</key>
+ <string>Special Month</string>
+ <key>AlbumId</key>
+ <integer>999002</integer>
+ <key>AlbumName</key>
+ <string>Last 12 Months</string>
+ <key>Filter Mode</key>
+ <string>All</string>
+ <key>Filters</key>
+ <array/>
+ <key>KeyList</key>
+ <array>
+ <string>7</string>
+ </array>
+ <key>PhotoCount</key>
+ <integer>1</integer>
+ <key>PlayMusic</key>
+ <string>YES</string>
+ <key>RepeatSlideShow</key>
+ <string>YES</string>
+ <key>SecondsPerSlide</key>
+ <integer>3</integer>
+ <key>SlideShowUseTitles</key>
+ <false/>
+ <key>SongPath</key>
+ <string></string>
+ <key>TransitionDirection</key>
+ <integer>0</integer>
+ <key>TransitionName</key>
+ <string>Dissolve</string>
+ <key>TransitionSpeed</key>
+ <real>1</real>
+ </dict>
+ <dict>
+ <key>Album Type</key>
+ <string>Regular</string>
+ <key>AlbumId</key>
+ <integer>9</integer>
+ <key>AlbumName</key>
+ <string>An Album</string>
+ <key>KeyList</key>
+ <array>
+ <string>7</string>
+ </array>
+ <key>PhotoCount</key>
+ <integer>1</integer>
+ <key>PlayMusic</key>
+ <string>YES</string>
+ <key>RepeatSlideShow</key>
+ <string>YES</string>
+ <key>SecondsPerSlide</key>
+ <integer>3</integer>
+ <key>SlideShowUseTitles</key>
+ <false/>
+ <key>SongPath</key>
+ <string></string>
+ <key>TransitionDirection</key>
+ <integer>0</integer>
+ <key>TransitionName</key>
+ <string>Dissolve</string>
+ <key>TransitionSpeed</key>
+ <real>1</real>
+ </dict>
+ </array>
+ <key>List of Keywords</key>
+ <dict/>
+ <key>List of Rolls</key>
+ <array>
+ <dict>
+ <key>Album Type</key>
+ <string>Regular</string>
+ <key>AlbumId</key>
+ <integer>6</integer>
+ <key>AlbumName</key>
+ <string>Roll 1</string>
+ <key>KeyList</key>
+ <array>
+ <string>7</string>
+ </array>
+ <key>Parent</key>
+ <integer>999000</integer>
+ <key>PhotoCount</key>
+ <integer>1</integer>
+ </dict>
+ </array>
+ <key>Major Version</key>
+ <integer>2</integer>
+ <key>Master Image List</key>
+ <dict>
+ <key>7</key>
+ <dict>
+ <key>Aspect Ratio</key>
+ <real>1</real>
+ <key>Caption</key>
+ <string>fallow_keep.png.450x450.2005-12-04</string>
+ <key>Comment</key>
+ <string>a comment</string>
+ <key>DateAsTimerInterval</key>
+ <real>158341389</real>
+ <key>ImagePath</key>
+ <string>/Users/username/Pictures/iPhoto Library/2006/01/07/fallow_keep.png.450x450.2005-12-04.jpg</string>
+ <key>MediaType</key>
+ <string>Image</string>
+ <key>MetaModDateAsTimerInterval</key>
+ <real>158341439.728129</real>
+ <key>ModDateAsTimerInterval</key>
+ <real>158341389</real>
+ <key>Rating</key>
+ <integer>0</integer>
+ <key>Roll</key>
+ <integer>6</integer>
+ <key>ThumbPath</key>
+ <string>/Users/username/Pictures/iPhoto Library/2006/01/07/Thumbs/7.jpg</string>
+ </dict>
+ </dict>
+ <key>Minor Version</key>
+ <integer>0</integer>
+</dict>
+</plist>
104 test/assets/Cookies.plist
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<array>
+ <dict>
+ <key>Created</key>
+ <real>151936595.697543</real>
+ <key>Domain</key>
+ <string>.cleveland.com</string>
+ <key>Expires</key>
+ <date>2007-10-25T12:36:35Z</date>
+ <key>Name</key>
+ <string>CTC</string>
+ <key>Path</key>
+ <string>/</string>
+ <key>Value</key>
+ <string>:broadband:</string>
+ </dict>
+ <dict>
+ <key>Created</key>
+ <real>151778895.063041</real>
+ <key>Domain</key>
+ <string>.gamefaqs.com</string>
+ <key>Expires</key>
+ <date>2006-04-21T16:47:58Z</date>
+ <key>Name</key>
+ <string>ctk</string>
+ <key>Path</key>
+ <string>/</string>
+ <key>Value</key>
+ <string>NDM1YmJlYmU0NjZiOGYxZjc1NjgxODg0YmRkMA%3D%3D</string>
+ </dict>
+ <dict>
+ <key>Created</key>
+ <real>183530456</real>
+ <key>Domain</key>
+ <string>arstechnica.com</string>
+ <key>Expires</key>
+ <date>2006-10-26T13:56:36Z</date>
+ <key>Name</key>
+ <string>fontFace</string>
+ <key>Path</key>
+ <string>/</string>
+ <key>Value</key>
+ <string>1</string>
+ </dict>
+ <dict>
+ <key>Created</key>
+ <real>183004526</real>
+ <key>Domain</key>
+ <string>.sourceforge.net</string>
+ <key>Expires</key>
+ <date>2006-10-20T02:35:26Z</date>
+ <key>Name</key>
+ <string>FRQSTR</string>
+ <key>Path</key>
+ <string>/</string>
+ <key>Value</key>
+ <string>18829595x86799:1:1440x87033:1:1440x86799:1:1440x87248:1:1440|18829595|18829595|18829595|18829595</string>
+ </dict>
+ <dict>
+ <key>Created</key>
+ <real>151053128.640531</real>
+ <key>Domain</key>
+ <string>.tvguide.com</string>
+ <key>Expires</key>
+ <date>2025-10-10T07:12:17Z</date>
+ <key>Name</key>
+ <string>DMSEG</string>
+ <key>Path</key>
+ <string>/</string>
+ <key>Value</key>
+ <string>1BDF3D1CC07FC70F&amp;D04451&amp;434EC763&amp;4351FD51&amp;0&amp;</string>
+ </dict>
+ <dict>
+ <key>Created</key>
+ <real>151304125.760261</real>
+ <key>Domain</key>
+ <string>.code.blogspot.com</string>
+ <key>Expires</key>
+ <date>2038-01-18T00:00:00Z</date>
+ <key>Name</key>
+ <string>__utma</string>
+ <key>Path</key>
+ <string>/</string>
+ <key>Value</key>
+ <string>11680422.1172819419.1129611326.1129611326.1129611326.1</string>
+ </dict>
+ <dict>
+ <key>Created</key>
+ <real>599529600</real>
+ <key>Domain</key>
+ <string>.tvguide.com</string>
+ <key>Expires</key>
+ <date>2020-01-01T00:00:00Z</date>
+ <key>Name</key>
+ <string>gfm</string>
+ <key>Path</key>
+ <string>/</string>
+ <key>Value</key>
+ <string>0</string>
+ </dict>
+</array>
+</plist>
9 test/assets/commented.plist
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<!-- I am a comment! -->
+<!--
+ I am a multi-line comment!
+ hooray!
+-->
+</plist>
BIN test/assets/example_data.bin
Binary file not shown.
BIN test/assets/example_data.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
259 test/assets/example_data.plist
@@ -0,0 +1,259 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>IMs</key>
+ <array>
+ <string>com.apple.syncservices:9583BE42-EC1A-4B3F-B248-7904BA60634B</string>
+ <string>com.apple.syncservices:2A222E96-4CC6-4320-BE0C-61D5F08C2E64</string>
+ <string>com.apple.syncservices:64DAA772-4558-49F8-9B87-C4A32D5E05C1</string>
+ <string>com.apple.syncservices:AF7C6884-B760-4E55-A4D5-B1B114C8A7DC</string>
+ <string>com.apple.syncservices:ECC7FAED-47D6-4DB9-8120-2F029C7D64C8</string>
+ <string>com.apple.syncservices:D704F079-F869-4613-9CFC-697C1976E8F4</string>
+ </array>
+ <key>URLs</key>
+ <array>
+ <string>com.apple.syncservices:5BA97109-F8E3-46A9-AF0B-5F8C093F49EA</string>
+ </array>
+ <key>com.apple.syncservices.RecordEntityName</key>
+ <string>com.apple.contacts.Contact</string>
+ <key>display as company</key>
+ <string>person</string>
+ <key>email addresses</key>
+ <array>
+ <string>com.apple.syncservices:B97DCC9C-5B00-4D38-AB06-4B7A5D6BC369</string>
+ <string>com.apple.syncservices:E508D679-43E1-49E2-B5D7-F14A8E48C067</string>
+ <string>com.apple.syncservices:C6478063-34A5-4CCB-BD41-1F131D56F7BD</string>
+ <string>com.apple.syncservices:2B3E352C-7831-4349-9A87-0FA4BD290515</string>
+ </array>
+ <key>first name</key>
+ <string>Mat</string>
+ <key>image</key>
+ <data>
+ /9j/4AAQSkZJRgABAQAAAQABAAD/7QAcUGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAAD/
+ 4g9ASUNDX1BST0ZJTEUAAQEAAA8wYXBwbAIAAABtbnRyUkdCIFhZWiAH1gAFABUAFAAg
+ AAZhY3NwQVBQTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9tYAAQAAAADTLWFwcGxx
+ EHyAeZ4fvAacU+DW7cbVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA5yWFla
+ AAABLAAAABRnWFlaAAABQAAAABRiWFlaAAABVAAAABR3dHB0AAABaAAAABRjaGFkAAAB
+ fAAAACxyVFJDAAABqAAAAA5nVFJDAAABuAAAAA5iVFJDAAAByAAAAA52Y2d0AAAB2AAA
+ BhJuZGluAAAH7AAABj5kZXNjAAAOLAAAAGRkc2NtAAAOkAAAAEhtbW9kAAAO2AA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MqEHKcVC
+ liV7Wc5RxOFs4Kov0E/YK+Nn7O3hj4W/G5fih4/+EXg+9u/F2qWVjpfinXdO0/xNdeGr
+ 7wXaRS6h4bttLvb2LxB5eoXF9Z2mn29hdWtypFnblEgkt5/yLjjgzxA/tbJMflOV5zm8
+ aeVU5YrDxqY+GFli3j8VzyTqLDUsFivZeyqVa+InSrxnN1puTkuf08tzfI5YWrRq4vL8
+ NTjiZwp1qjpSxdDDwwlGVCFKbVatXw1OMZU6dCnCpQeHgqdKzp8q8RtvAfhX4lRt4in8
+ O3WiaNqHm33haH7Q0GsabpBkH2JL25SeS4OorbqlxcxrMsaO0sSq6IrH+xvDDhTN8/yS
+ hmedVq1CNOnKjhM1yyvSprEzwlWdNYrERcZKpT9pFxlzRiqqpuUo3nd8mOxOGw8aUKbl
+ OpWp0q9J1VyP2VSCl7NqCXs6sV+8UUrxT5ejRz2kfCRvBXjK68Ry+Ir3xDaXul3OixwX
+ RtUNja3DCQr/AKPAovDMyRI8kpV40QKI2ZpJG+yzPJs3y7E1I5hUji6FTD16Ea2Ei6c0
+ p0pRnKrSTnSbk4x0oezjBqTlTbk3Hy8NTpYidfEKdWWIlFU5RruMoxUJOdqcoRTld2T5
+ 7vlfuvV3/Nv4g/EkeD9N1Pw9Yy7deS51HTbK3QgyWECXEsAvblhnbshANtGx8yaYq+0R
+ qzV5FKWFxeVYGtU5JYhUKUYxg1LkcLc9So+WylLlSVOSbTakvdSPkMyzOpgKlbC0m/a3
+ lFKS1g5ac132jtZJN20sj5h0LWI7CIxXEl/bZMjLe2u2dY5JCQ0zwloyzEFhuLscnIBO
+ APFzHAyxM/aQjhqr91OhWbpOcYq6hGpaSS0TtZbWfn5GXY2GGi4VZ4mi221WpWqRhKVl
+ zSptxk21dX5pWbuo3SS//9k=
+ </data>
+ <key>last name</key>
+ <string>Schaffer</string>
+ <key>phone numbers</key>
+ <array>
+ <string>com.apple.syncservices:64ED42EB-109B-43A9-BEFC-3463D944251A</string>
+ <string>com.apple.syncservices:FB7585EB-A3DE-46D5-920C-DF8028689BC5</string>
+ <string>com.apple.syncservices:020036FD-22B3-41C9-BC3D-CDA6083582C6</string>
+ <string>com.apple.syncservices:C6661518-90CA-45C7-A988-02F73B958951</string>
+ </array>
+ <key>primary URL</key>
+ <array>
+ <string>com.apple.syncservices:5BA97109-F8E3-46A9-AF0B-5F8C093F49EA</string>
+ </array>
+ <key>primary email address</key>
+ <array>
+ <string>com.apple.syncservices:B97DCC9C-5B00-4D38-AB06-4B7A5D6BC369</string>
+ </array>
+ <key>primary phone number</key>
+ <array>
+ <string>com.apple.syncservices:64ED42EB-109B-43A9-BEFC-3463D944251A</string>
+ </array>
+ <key>primary related name</key>
+ <array>
+ <string>com.apple.syncservices:CD0B7021-0228-4770-8FB0-3739479E9788</string>
+ </array>
+ <key>primary street address</key>
+ <array>
+ <string>com.apple.syncservices:377B9105-9D15-4F69-BCD6-B01E587F7760</string>
+ </array>
+ <key>related names</key>
+ <array>
+ <string>com.apple.syncservices:CD0B7021-0228-4770-8FB0-3739479E9788</string>
+ </array>
+ <key>street addresses</key>
+ <array>
+ <string>com.apple.syncservices:377B9105-9D15-4F69-BCD6-B01E587F7760</string>
+ </array>
+</dict>
+</plist>
24 test/assets/test_data_elements.plist
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+ <dict>
+ <key>stringio</key>
+ <data>dGhpcyBpcyBhIHN0cmluZ2lvIG9iamVjdA==
+ </data>
+ <key>file</key>
+ <data>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+ AAAAAAAAAAAAAA==
+ </data>
+ <key>io</key>
+ <data>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+ AAAAAAAAAAAAAA==
+ </data>
+ <key>marshal</key>
+ <!-- The <data> element below contains a Ruby object which has been serialized with Marshal.dump. -->
+ <data>BAhvOhZNYXJzaGFsYWJsZU9iamVjdAY6CUBmb28iHnRoaXMgb2JqZWN0IHdh
+ cyBtYXJzaGFsZWQ=
+ </data>
+ </dict>
+</plist>
13 test/assets/test_empty_key.plist
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+ <dict>
+ <key>key</key>
+ <dict>
+ <key></key>
+ <string>1</string>
+ <key>subkey</key>
+ <string>2</string>
+ </dict>
+ </dict>
+</plist>
115 test/test_data_elements.rb
@@ -0,0 +1,115 @@
+##############################################################
+# Copyright 2006, Ben Bleything <ben@bleything.net> and #
+# Patrick May <patrick@hexane.org> #
+# #
+# Distributed under the MIT license. #
+##############################################################
+
+require 'test/unit'
+require 'plist'
+require 'stringio'
+
+class MarshalableObject
+ attr_accessor :foo
+
+ def initialize(str)
+ @foo = str
+ end
+end
+
+class TestDataElements < Test::Unit::TestCase
+ @@result = Plist::parse_xml('test/assets/test_data_elements.plist')
+
+ def test_marshal
+ expected = <<END
+<!-- The <data> element below contains a Ruby object which has been serialized with Marshal.dump. -->
+<data>
+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>
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
+</data>
+END
+
+ expected.chomp!
+
+ 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']
+
+ io.rewind
+ f.rewind
+
+ assert_equal io.read, @@result['io'].read
+ assert_equal f.read, @@result['file'].read
+
+ io.close
+ f.close
+ end
+
+ def test_generator_string_io
+ expected = <<END
+<data>
+dGhpcyBpcyBhIHN0cmluZ2lvIG9iamVjdA==
+</data>
+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
+
+ # this functionality is credited to Mat Schaffer,
+ # who discovered the plist with the data tag
+ # supplied the test data, and provided the parsing code.
+ def test_data
+ # test reading plist <data> elements
+ data = Plist::parse_xml("test/assets/example_data.plist");
+ assert_equal( File.open("test/assets/example_data.jpg"){|f| f.read }, data['image'].read )
+
+ # test writing data elements
+ expected = File.read("test/assets/example_data.plist")
+ result = data.to_plist
+ #File.open('result.plist', 'w') {|f|f.write(result)} # debug
+ assert_equal( expected, result )
+
+ # Test changing the <data> object in the plist to a StringIO and writing.
+ # This appears extraneous given that plist currently returns a StringIO,
+ # so the above writing test also flexes StringIO#to_plist_node.
+ # 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
59 test/test_generator.rb
@@ -0,0 +1,59 @@
+##############################################################
+# Copyright 2006, Ben Bleything <ben@bleything.net> and #
+# Patrick May <patrick@hexane.org> #
+# #
+# Distributed under the MIT license. #
+##############################################################
+
+require 'test/unit'
+require 'plist'
+
+class SerializableObject
+ attr_accessor :foo
+
+ def initialize(str)
+ @foo = str
+ end
+
+ def to_plist_node
+ return "<string>#{CGI::escapeHTML @foo}</string>"
+ end
+end
+
+class TestGenerator < Test::Unit::TestCase
+ def test_to_plist_vs_plist_emit_dump_no_envelope
+ source = [1, :b, true]
+
+ to_plist = source.to_plist(false)
+ plist_emit_dump = Plist::Emit.dump(source, false)