lib/rpub/epub/toc.rb in rpub-0.4.0 vs lib/rpub/epub/toc.rb in rpub-0.5.0
- old
+ new
@@ -1,46 +1,49 @@
module Rpub
class Epub
class Toc < XmlFile
- attr_reader :book
-
- def initialize(book)
- @book = book
- @play_order = -1
- @max_level = book.config.fetch(:max_level) { 2 }
- super()
- end
-
def render
xml.instruct!
xml.declare! :DOCTYPE, :ncx, :PUBLIC, "-//W3C//DTD XHTML 1.1//EN", 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'
xml.ncx :xmlns => 'http://www.daisy.org/z3986/2005/ncx/', :version => '2005-1' do
xml.head do
xml.meta :name => 'dtb:uid', :content => book.uid
- xml.meta :name => 'dtb:depth', :content => @max_level
+ xml.meta :name => 'dtb:depth', :content => max_level
xml.meta :name => 'dtb:totalPageCount', :content => '0'
xml.meta :name => 'dtb:maxPageNumber', :content => '0'
end
- xml.docTitle { xml.text book.title }
+ xml.docTitle { xml.text book.config.title }
xml.navMap do
book.chapters.each do |chapter|
nav_points_nested_by_level chapter.toc, chapter.filename
end
end
end
end
private
+ def max_level
+ book.config.max_level || 2
+ end
+
+ def play_order
+ @play_order ||= 0
+ end
+
+ def play_order=(v)
+ @play_order = v
+ end
+
def next_play_order
- @play_order += 1
+ self.play_order = play_order + 1
end
def nav_points_nested_by_level(heading, filename, level = 1)
heading.children.each do |heading|
html_id = heading.attr[:id]
source = filename+'#'+html_id
- if heading.value.options[:level] <= @max_level
+ if heading.value.options[:level] <= max_level
nav_point html_id, next_play_order, heading.value.options[:raw_text], source do
nav_points_nested_by_level heading, filename, level + 1
end
end
end