From 681dc84becb4c9bbf37ad4ae9de01057ffac90ef Mon Sep 17 00:00:00 2001 From: Sebastian Celis Date: Mon, 6 Feb 2012 14:38:50 -0600 Subject: [PATCH] Cleanup section headers in generated string files. --- lib/twine/formatters/android.rb | 20 +++++++++++--------- lib/twine/formatters/apple.rb | 10 +++++++++- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/twine/formatters/android.rb b/lib/twine/formatters/android.rb index 01e3062..264abe2 100644 --- a/lib/twine/formatters/android.rb +++ b/lib/twine/formatters/android.rb @@ -53,18 +53,20 @@ module Twine default_lang = strings.language_codes[0] File.open(path, 'w:UTF-8') do |f| f.puts "\n\n\n" - f.puts '' - section_num = -1 + f.write '' strings.sections.each do |section| - section_num += 1 - if section_num > 0 - f.puts '' - end - - section_name = section.name.gsub('--', '—') - f.puts "\t" + printed_section = false section.rows.each do |row| if row_matches_tags?(row, tags) + unless printed_section + f.puts '' + if section.name && section.name.length > 0 + section_name = section.name.gsub('--', '—') + f.puts "\t" + end + printed_section = true + end + key = row.key key = CGI.escapeHTML(key) diff --git a/lib/twine/formatters/apple.rb b/lib/twine/formatters/apple.rb index 8784fdf..dfda663 100644 --- a/lib/twine/formatters/apple.rb +++ b/lib/twine/formatters/apple.rb @@ -49,9 +49,17 @@ module Twine File.open(path, 'w:UTF-8') do |f| f.puts "/**\n * iOS Strings File\n * Generated by Twine\n * Language: #{lang}\n */" strings.sections.each do |section| - f.puts "\n/* #{section.name} */" + printed_section = false section.rows.each do |row| if row_matches_tags?(row, tags) + unless printed_section + f.puts '' + if section.name && section.name.length > 0 + f.puts "/* #{section.name} */" + end + printed_section = true + end + key = row.key key = key.gsub('"', '\\\\"')