Skip to content

Commit

Permalink
fix #127 : create valid nav.html when @toc is empty.
Browse files Browse the repository at this point in the history
  • Loading branch information
skoji committed May 17, 2015
1 parent 59cff6e commit 3943efc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/gepub/book.rb
Expand Up @@ -307,8 +307,10 @@ def write_toc xml_doc, tocs
tocs.each {
|x|
id = x[:id].nil? ? "" : "##{x[:id]}"
toc_text = x[:text]
toc_text = x[:item].href if toc_text.nil? or toc_text == ''
xml_doc.li {
xml_doc.a({'href' => x[:item].href + id} ,x[:text])
xml_doc.a({'href' => x[:item].href + id} ,toc_text)
if x[:child_stack] && x[:child_stack][:tocs].size > 0
write_toc(xml_doc, x[:child_stack][:tocs])
end
Expand Down
21 changes: 21 additions & 0 deletions spec/gepub_spec.rb
Expand Up @@ -205,4 +205,25 @@
@book.generate_epub(epubname)
epubcheck(epubname)
end

it 'should generate valid EPUB when @toc is empty' do
epubname = File.join(File.dirname(__FILE__), 'testepub4.epub')
@book = GEPUB::Book.new('OEPBS/package.opf', { 'version' => '3.0'} )
@book.title = 'thetitle'
@book.creator = "theauthor"
@book.contributor = "contributors contributors!"
@book.publisher = "thepublisher"
@book.date = "2015-05-05"
@book.identifier = "http://example.jp/foobar/"
@book.language = 'ja'
item1 = @book.add_item('text/foobar.xhtml',nil, 'c1')
item1.add_content(StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c1</title></head><body><p>the first page</p></body></html>'))
@book.spine.push(item1)
item2 = @book.add_ordered_item('text/barbar.xhtml',
StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c2</title></head><body><p>second page, whith is test chapter.</p></body></html>'),
'c2')
@book.generate_epub(epubname)
epubcheck(epubname)

end
end

0 comments on commit 3943efc

Please sign in to comment.