Class: TP::Publisher::PDF

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/tp/publisher/pdf.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_filename, output_filename) ⇒ PDF

Returns a new instance of PDF.



22
23
24
25
# File 'lib/tp/publisher/pdf.rb', line 22

def initialize(input_filename, output_filename)
  @input_filename = input_filename
  @output_filename = output_filename
end

Instance Attribute Details

#input_filenameObject (readonly)

Returns the value of attribute input_filename.



20
21
22
# File 'lib/tp/publisher/pdf.rb', line 20

def input_filename
  @input_filename
end

Instance Method Details

#document_optionsObject



61
62
63
64
65
66
67
# File 'lib/tp/publisher/pdf.rb', line 61

def document_options
  {
    page_layout: :landscape,
    optimize_objects: true,
    skip_page_creation: true
  }
end

#markdownObject



41
42
43
# File 'lib/tp/publisher/pdf.rb', line 41

def markdown
  @markdown ||= File.read(input_filename)
end

#new_pageObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/tp/publisher/pdf.rb', line 69

def new_page
  start_new_page

  fill_color '111111'

  canvas do
    fill_rectangle [bounds.left, bounds.top], bounds.width, bounds.height
  end

  fill_color 'EEEEEE'

  font "Helvetica"
  font_size 1.in
end

#output_filenameObject



53
54
55
# File 'lib/tp/publisher/pdf.rb', line 53

def output_filename
  @output_filename || "#{input_filename.split('.').first}.pdf"
end

#pdfObject



57
58
59
# File 'lib/tp/publisher/pdf.rb', line 57

def pdf
  @pdf ||= Prawn::Document.new(document_options)
end

#presenterObject



45
46
47
# File 'lib/tp/publisher/pdf.rb', line 45

def presenter
  @presenter ||= Presenter.new(markdown)
end

#publishObject



27
28
29
30
31
32
33
# File 'lib/tp/publisher/pdf.rb', line 27

def publish
  slides.each do |slide|
    render_slide(slide)
  end

  render_file output_filename
end

#render_slide(slide) ⇒ Object



35
36
37
38
39
# File 'lib/tp/publisher/pdf.rb', line 35

def render_slide(slide)
  new_page

  slide.render_pdf(pdf)
end

#slidesObject



49
50
51
# File 'lib/tp/publisher/pdf.rb', line 49

def slides
  presenter.slides
end