Class: Kitabu::TOC::Epub

Inherits:
Object
  • Object
show all
Defined in:
lib/kitabu/toc/epub.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(navigation) ⇒ Epub

Returns a new instance of Epub.



8
9
10
# File 'lib/kitabu/toc/epub.rb', line 8

def initialize(navigation)
  @navigation = navigation
end

Instance Attribute Details

Returns the value of attribute navigation.



6
7
8
# File 'lib/kitabu/toc/epub.rb', line 6

def navigation
  @navigation
end

Instance Method Details

#templateObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/kitabu/toc/epub.rb', line 17

def template
  (+<<-HTML).strip_heredoc.force_encoding("utf-8")
    <?xml version="1.0" encoding="utf-8" ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" type="text/css" href="epub.css"/>
        <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
        <title>Table of Contents</title>
      </head>
      <body>
        <div id="toc">
          <ul>
            <% navigation.each do |nav| %>
              <li>
                <a href="<%= nav[:content] %>"><%= nav[:label] %></a>
              </li>
            <% end %>
          </ul>
        </div>
      </body>
    </html>
  HTML
end

#to_htmlObject



12
13
14
15
# File 'lib/kitabu/toc/epub.rb', line 12

def to_html
  data = OpenStruct.new(navigation:).instance_eval { binding }
  ERB.new(template).result(data)
end