Skip to content

Commit

Permalink
Fix handling generating text from image_links
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Nov 18, 2015
1 parent c0ca09c commit beeefb4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/model/text.rb
Expand Up @@ -219,8 +219,13 @@ def strip
def text
text = ''
@contents.map do |content|
text << content.text if content.is_a? Paragraph
text << content if content.is_a? String
if content.is_a? Paragraph
text << content.text
elsif content.is_a? String
text << content
else
text << content.to_s
end
end
text
end
Expand All @@ -230,7 +235,7 @@ def to_s
if content.is_a? Paragraph
text << content.text
else
text << content if content and content.to_s.length > 0
text << content.to_s
end
end
text.gsub("\n", ' ')
Expand Down
19 changes: 19 additions & 0 deletions test/test_model/fachinfo.rb
Expand Up @@ -219,6 +219,25 @@ def setup
line 5
'
end
def test_image_link
new_doc = ODDB::FachinfoDocument2001.new
new_doc.composition = ODDB::Text::Chapter.new
new_doc.composition.heading = 'Zusammensetzung'
para_1 = new_doc.composition.next_section
para_2 = para_1.next_paragraph
para_2 << 'a'
table = para_1.next_table
table << 'b'
multi = table.next_multi_cell!
multi << 'm'
image = multi.next_image
expected = "Zusammensetzung
a
b m(image)
"
assert_equal(expected, new_doc.text)
end
def test_first_chapter
ue = flexmock 'unwanted_effects'
@doc.unwanted_effects = ue
Expand Down
11 changes: 11 additions & 0 deletions test/test_model/text.rb
Expand Up @@ -666,5 +666,16 @@ def test_width
@table << 'cell4'
assert_equal 2, @table.width
end
def test_multi_cell
@table.next_row!
cell1 = @table.next_cell!
@table << 'cell1'
cell2 = @table.next_multi_cell!
cell2 << 'cell2'
image = @table.next_image!
cell3 = @table.next_cell!
@table << 'cell3'
assert_equal "cell1 cell2 (image) cell3\n", @table.to_s
end
end
end

0 comments on commit beeefb4

Please sign in to comment.