Class: EPUB::ContentDocument::Navigation

Inherits:
Object
  • Object
show all
Defined in:
lib/epub/maker/content_document.rb

Instance Method Summary collapse

Instance Method Details

#to_xml(options = {:encoding => 'UTF-8'}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/epub/maker/content_document.rb', line 7

def to_xml(options={:encoding => 'UTF-8'})
  Nokogiri::XML::Builder.new(options) {|xml|
    xml.html('xmlns' => EPUB::NAMESPACES['xhtml'], 'xmlns:epub' => EPUB::NAMESPACES['epub']) {
      xml.head {
        xml.title_ 'Table of Contents'
      }
      xml.body {
        navigations.each do |navigation|
          xml.nav_('epub:type' => navigation.type) {
            unless navigation.items.empty?
              xml.ol {
                navigation.items.each do |item|
                  xml.li {
                    if item.href
                      xml.a item.text, 'href' => item.href
                    else
                      xml.span_ item.text
                    end
                  }
                end
              }
            end
          }
        end
      }
    }
  }.to_xml
end