Class: MakeBook::Formats::PDF

Inherits:
Object
  • Object
show all
Defined in:
lib/makebook/formats/pdf.rb

Overview

PDF output format

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(book, build, options = {}) ⇒ PDF

Returns a new instance of PDF.



7
8
9
10
11
# File 'lib/makebook/formats/pdf.rb', line 7

def initialize(book, build, options = {})
  @book = book
  @build = build
  @options = kit_options_from(options)
end

Instance Attribute Details

#bookObject (readonly)

Returns the value of attribute book.



5
6
7
# File 'lib/makebook/formats/pdf.rb', line 5

def book
  @book
end

#buildObject (readonly)

Returns the value of attribute build.



5
6
7
# File 'lib/makebook/formats/pdf.rb', line 5

def build
  @build
end

Instance Method Details

#build_fileObject



52
53
54
# File 'lib/makebook/formats/pdf.rb', line 52

def build_file
  Pathname("#{build_name}.pdf")
end

#build_nameObject



48
49
50
# File 'lib/makebook/formats/pdf.rb', line 48

def build_name
  build.root + book.root + book.name
end

#makeObject



13
14
15
16
17
18
19
# File 'lib/makebook/formats/pdf.rb', line 13

def make
  html = MakeBook::Formats::HTML.new(book, build)
  html.make if html.stale?

  kit = PDFKit.new(File.new(html.build_file), options)
  kit.to_file(build_file)
end

#stale?Boolean

Returns:

  • (Boolean)


56
57
58
59
60
# File 'lib/makebook/formats/pdf.rb', line 56

def stale?
  book.source.mtime > build_file.mtime
rescue Errno::ENOENT
  true
end