Sha256: 322a1da0d969e4a721311038c2ff19080636a8543dc44c492b218af654faeeb1

Contents?: true

Size: 1.28 KB

Versions: 16

Compression:

Stored size: 1.28 KB

Contents

module Kitabu
  module TOC
    class Epub
      attr_accessor :navigation

      def initialize(navigation)
        @navigation = navigation
      end

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

      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
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
kitabu-2.1.0 lib/kitabu/toc/epub.rb
kitabu-2.0.4 lib/kitabu/toc/epub.rb
kitabu-2.0.3 lib/kitabu/toc/epub.rb
kitabu-2.0.2 lib/kitabu/toc/epub.rb
kitabu-2.0.1 lib/kitabu/toc/epub.rb
kitabu-2.0.0 lib/kitabu/toc/epub.rb
kitabu-1.0.6 lib/kitabu/toc/epub.rb
kitabu-1.0.5 lib/kitabu/toc/epub.rb
kitabu-1.0.4 lib/kitabu/toc/epub.rb
kitabu-1.0.3 lib/kitabu/toc/epub.rb
kitabu-1.0.2 lib/kitabu/toc/epub.rb
kitabu-1.0.1 lib/kitabu/toc/epub.rb
kitabu-1.0.0 lib/kitabu/toc/epub.rb
kitabu-1.0.0.rc4 lib/kitabu/toc/epub.rb
kitabu-1.0.0.rc3 lib/kitabu/toc/epub.rb
kitabu-1.0.0.rc2 lib/kitabu/toc/epub.rb