Class: Kitabu::Exporter::PDF

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

Instance Attribute Summary

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

Instance Method Details

#apply_footnotes!Object



13
14
15
16
17
# File 'lib/kitabu/exporter/pdf.rb', line 13

def apply_footnotes!
  html = Footnotes::PDF.process(html_file.read).html
  create_html_file(html_for_print, html, "print")
  create_html_file(html_for_pdf, html, "pdf")
end

#create_html_file(target, html, class_name) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/kitabu/exporter/pdf.rb', line 19

def create_html_file(target, html, class_name)
  html.css("html").first.set_attribute "class", class_name
  html
    .css("link[name=stylesheet]")
    .first
    .set_attribute "href", "styles/#{class_name}.css"

  File.open(target, "w") {|f| f << html.to_html }
end

#exportObject



6
7
8
9
10
11
# File 'lib/kitabu/exporter/pdf.rb', line 6

def export
  super
  apply_footnotes!
  spawn_command ["prince", html_for_pdf.to_s, "-o", pdf_file.to_s]
  spawn_command ["prince", html_for_print.to_s, "-o", print_file.to_s]
end

#html_fileObject



37
38
39
# File 'lib/kitabu/exporter/pdf.rb', line 37

def html_file
  root_dir.join("output/#{name}.html")
end

#html_for_pdfObject



29
30
31
# File 'lib/kitabu/exporter/pdf.rb', line 29

def html_for_pdf
  root_dir.join("output/#{name}.pdf.html")
end

#html_for_printObject



33
34
35
# File 'lib/kitabu/exporter/pdf.rb', line 33

def html_for_print
  root_dir.join("output/#{name}.print.html")
end

#pdf_fileObject



41
42
43
# File 'lib/kitabu/exporter/pdf.rb', line 41

def pdf_file
  root_dir.join("output/#{name}.pdf")
end


45
46
47
# File 'lib/kitabu/exporter/pdf.rb', line 45

def print_file
  root_dir.join("output/#{name}.print.pdf")
end