Class: Rpub::Epub::HtmlToc

Inherits:
XmlFile
  • Object
show all
Defined in:
lib/rpub/epub/html_toc.rb

Instance Attribute Summary

Attributes inherited from XmlFile

#book, #xml

Instance Method Summary (collapse)

Methods inherited from XmlFile

#initialize, #to_s

Constructor Details

This class inherits a constructor from Rpub::XmlFile

Instance Method Details

- (Object) render



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rpub/epub/html_toc.rb', line 4

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|
          if heading.level <= (book.config.max_level || 2)
            xml.div :class => "level-#{heading.level}" do
              xml.a heading.text, :href => [filename, heading.html_id].join('#')
            end
          end
        end
      end
    end
  end
end