Merge pull request #162 from sebastianludwig/empty-jquery-sections

Empty jquery sections
This commit is contained in:
Sebastian Celis 2016-05-04 09:50:09 -05:00
commit a45bfba0ba
2 changed files with 15 additions and 0 deletions

View file

@ -50,6 +50,7 @@ module Twine
def format_sections(twine_file, lang)
sections = twine_file.sections.map { |section| format_section(section, lang) }
sections.delete_if &:empty?
sections.join(",\n\n")
end

View file

@ -239,6 +239,20 @@ class TestJQueryFormatter < FormatterTest
assert_equal content('formatter_jquery.json'), formatter.format_file('en')
end
def test_empty_sections_are_removed
@twine_file = build_twine_file 'en' do
add_section 'Section 1' do
end
add_section 'Section 2' do
add_definition key: 'value'
end
end
formatter = Twine::Formatters::JQuery.new
formatter.twine_file = @twine_file
refute_includes formatter.format_file('en'), ','
end
def test_format_value_with_newline
assert_equal "value\nwith\nline\nbreaks", @formatter.format_value("value\nwith\nline\nbreaks")
end