Skip to content

Commit

Permalink
(Partial) fix to handle line breaks in table cells
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Nov 18, 2013
1 parent 9905cfc commit 62e66e0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/view/chapter.rb
Expand Up @@ -23,7 +23,8 @@ module ChapterMethods
def formats(context, paragraph)
res = ''
if paragraph.is_a? String
return context.span({ 'style' => self.class::PAR_STYLE }) { paragraph }
return '' if paragraph.empty? or paragraph.eql?(' ')
return context.span({ 'style' => self.class::PAR_STYLE }) { paragraph + "<br>" }
end
txt = paragraph.text.encode("UTF-8")
paragraph.formats.each { |format|
Expand Down
36 changes: 36 additions & 0 deletions test/test_view/chapter.rb
Expand Up @@ -394,6 +394,42 @@ def test_table_to_html
assert(result.index('cell2</SPAN>'))
assert(result.index('Zwerge &gt; 1.5 m'))
end
def test_table_with_paragraphs_in_cell_to_html
@lookandfeel = FlexMock.new 'lookandfeel'
@lookandfeel.should_receive(:section_style).and_return { 'section_style' }
@lookandfeel.should_receive(:subheading).and_return { 'subheading' }
session = FlexMock.new 'session'
session.should_receive(:lookandfeel).and_return { @lookandfeel }
session.should_receive(:user_input)
assert(session.respond_to?(:lookandfeel))

@view = View::Chapter.new(:name, @model, session)
chapter = Text::Chapter.new
chapter.heading = "TestTable"
section = chapter.next_section
section.next_paragraph
section.subheading = "Tabelle"
table = Text::Table.new
table.next_row!
cell1 = table.next_multi_cell!
cell1.next_paragraph
cell1 << 'first'
cell1.next_paragraph
cell1 << ''
cell1.next_paragraph
cell1 << ''
cell1.next_paragraph
cell1 << 'second'
section.paragraphs << table
@view.value = chapter
result = @view.to_html(CGI.new)
assert(result.index(/<h3>TestTable<\/H3>/i), 'must contain TestTable as H3')
refute_nil(result.index('>Tabelle<'), 'must contain Tabelle as element')
refute_nil(result.index(/second<br>/i), 'second must be followed by line break')
refute_nil(result.index(/first<br>/i), 'first must be followed by line break')
assert_nil(result.index(/<span [^>]*><\/span>/i), 'it may not contain an empty span')
assert_nil(result.index(/<p [^>]*><\/p>/i), 'it may not contain an empty paragraph')
end
end

end
Expand Down

0 comments on commit 62e66e0

Please sign in to comment.