Class: Rpub::Epub::Toc

Inherits:
XmlFile show all
Defined in:
lib/rpub/epub/toc.rb

Instance Attribute Summary collapse

Attributes inherited from XmlFile

#xml

Instance Method Summary collapse

Methods inherited from XmlFile

#to_s

Constructor Details

#initialize(book) ⇒ Toc

Returns a new instance of Toc.



6
7
8
9
10
11
# File 'lib/rpub/epub/toc.rb', line 6

def initialize(book)
  @book       = book
  @play_order = -1
  @max_level  = book.config.fetch(:max_level) { 2 }
  super()
end

Instance Attribute Details

#bookObject (readonly)

Returns the value of attribute book.



4
5
6
# File 'lib/rpub/epub/toc.rb', line 4

def book
  @book
end

Instance Method Details

#renderObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rpub/epub/toc.rb', line 13

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:totalPageCount', :content => '0'
      xml.meta :name => 'dtb:maxPageNumber',  :content => '0'
    end
    xml.docTitle { xml.text book.title }
    xml.navMap do
      book.chapters.each do |chapter|
        nav_points_nested_by_level chapter.toc, chapter.filename
      end
    end
  end
end