Class: Bookify::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/bookify/renderer.rb

Constant Summary collapse

MARKDOWN_CONVERTER =
Redcarpet::Markdown.new(Redcarpet::Render::HTML)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Renderer

Returns a new instance of Renderer.



6
7
8
# File 'lib/bookify/renderer.rb', line 6

def initialize(filename)
  self.filename = filename
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



4
5
6
# File 'lib/bookify/renderer.rb', line 4

def filename
  @filename
end

Instance Method Details

#renderObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bookify/renderer.rb', line 10

def render
  Prawn::Document.generate(pdf_path) do |pdf|
    font_path = "#{File.dirname(__FILE__)}/../../fonts"

    pdf.font_families["Book Antiqua"] = {
      normal:      { file: "#{font_path}/BookAntiqua.ttf" },
      bold:        { file: "#{font_path}/BookAntiqua-Bold.ttf" },
      italic:      { file: "#{font_path}/BookAntiqua-Italic.ttf" },
      bold_italic: { file: "#{font_path}/BookAntiqua-BoldItalic.ttf" }
    }

    pdf.fill_color "000000"
    pdf.stroke_color "333333"
    pdf.line_width(0.5)
    pdf.default_leading 0.5

    pdf.column_box [0, pdf.cursor], columns: 2, width: pdf.bounds.width do
      doc.children.each { |c| Bookify::Node.render(c, pdf) }
    end
  end
end