summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBen Bleything <ben@bleything.net>2006-09-15 17:39:35 +0000
committerBen Bleything <ben@bleything.net>2006-09-15 17:39:35 +0000
commitaa03932b0130c110102c27e215d87d230f994877 (patch)
treeff5b017da86b6a2eba4b2b8b18ffa68c68e3a36f /lib
parent9c13f486024574a0ec14f84ddca39a7ef0a0341f (diff)
downloadplist-aa03932b0130c110102c27e215d87d230f994877.tar.gz
add tests and fixes for empty collection elements (more pedantic adherence to What Apple Does)
Diffstat (limited to 'lib')
-rw-r--r--lib/plist/generator.rb34
1 files changed, 21 insertions, 13 deletions
diff --git a/lib/plist/generator.rb b/lib/plist/generator.rb
index 8036575..223edcc 100644
--- a/lib/plist/generator.rb
+++ b/lib/plist/generator.rb
@@ -64,21 +64,29 @@ module Plist
else
case element
when Array
- output << tag('array') {
- element.collect {|e| plist_node(e)}
- }
+ if element.empty?
+ output << "<array/>\n"
+ else
+ output << tag('array') {
+ element.collect {|e| plist_node(e)}
+ }
+ end
when Hash
- 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)
+ 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
-
- output << tag('dict') {
- inner_tags
- }
when true, false
output << "<#{element}/>\n"
when Time