Class: Rpub::Epub::HtmlToc

Inherits:
XmlFile
  • Object
show all
Defined in:
lib/rpub/epub/html_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) ⇒ HtmlToc

Returns a new instance of HtmlToc.



6
7
8
9
# File 'lib/rpub/epub/html_toc.rb', line 6

def initialize(book)
  @book = book
  super()
end

Instance Attribute Details

#bookObject (readonly)

Returns the value of attribute book.



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

def book
  @book
end

Instance Method Details

#renderObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rpub/epub/html_toc.rb', line 11

def render
  xml.div :id => 'toc' do
    xml.h1 'Table of Contents'
    xml.div :class => 'toc' do
      book.outline.each do |(filename, headings)|
        headings.each do |heading|
          xml.div :class => "level-#{heading.level}" do
            xml.a heading.text, :href => [filename, heading.html_id].join('#')
          end
        end
      end
    end
  end
end