Class: Kitabu::Exporter::HTML

Inherits:
Base
  • Object
show all
Defined in:
lib/kitabu/exporter/html.rb

Class Attribute Summary collapse

Attributes inherited from Base

#root_dir, #source

Instance Method Summary collapse

Methods inherited from Base

#config, #copy_directory, export, #handle_error, #initialize, #name, #render_template, #source_list, #spawn_command, #ui

Constructor Details

This class inherits a constructor from Kitabu::Exporter::Base

Class Attribute Details

.footnote_indexObject

The footnote index control. We have to manipulate footnotes because each chapter starts from 1, so we have duplicated references.



10
11
12
# File 'lib/kitabu/exporter/html.rb', line 10

def footnote_index
  @footnote_index
end

Instance Method Details

#contentObject

Return all chapters wrapped in a div.chapter tag.



38
39
40
41
42
43
44
45
46
# File 'lib/kitabu/exporter/html.rb', line 38

def content
  buffer = [].tap do |content|
    source_list.each_chapter do |files|
      content << %[<div class="chapter">#{render_chapter(files)}</div>]
    end
  end

  buffer.join
end

#exportObject

Parse all files and save the parsed content to output/book_name.html.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/kitabu/exporter/html.rb', line 16

def export
  super
  copy_images!
  copy_fonts!
  export_stylesheets!

  File.open(root_dir.join("output/#{name}.html"), "w") do |file|
    file << parse_layout(content)
  end

  true
rescue StandardError => error
  handle_error(error)
  false
end

#reset_footnote_index!Object



32
33
34
# File 'lib/kitabu/exporter/html.rb', line 32

def reset_footnote_index!
  self.class.footnote_index = 1
end