From aa03932b0130c110102c27e215d87d230f994877 Mon Sep 17 00:00:00 2001 From: Ben Bleything Date: Fri, 15 Sep 2006 17:39:35 +0000 Subject: add tests and fixes for empty collection elements (more pedantic adherence to What Apple Does) --- lib/plist/generator.rb | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'lib') 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 << "\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 << "\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 -- cgit v1.2.1