class Documentum::Generator

Attributes

options[R]
output_dir[R]
stylesheet_filenames[R]
template_filename[R]

Public Class Methods

new(template_filename, output_dir, stylesheet_filenames: [], options: {}) click to toggle source
# File lib/documentum/generator.rb, line 6
def initialize(template_filename, output_dir, stylesheet_filenames: [], options: {})
  @template_filename = template_filename
  @stylesheet_filenames = stylesheet_filenames
  @output_dir = output_dir
end

Public Instance Methods

generate_pdf(markdown_filename) click to toggle source
# File lib/documentum/generator.rb, line 12
def generate_pdf(markdown_filename)
  html = generate_html(markdown_filename)
  engine = PDFKit.new(html, page_size: "Letter")
  engine.stylesheets += @stylesheet_filenames
  engine.to_file(output_path(markdown_filename))
end

Private Instance Methods

generate_html(markdown_filename) click to toggle source
# File lib/documentum/generator.rb, line 31
def generate_html(markdown_filename)
  markdown = File.read(markdown_filename)
  engine = Haml::Engine.new(template)
  engine.render(Object.new, { content: markdown })
end
output_path(markdown_filename) click to toggle source
# File lib/documentum/generator.rb, line 21
def output_path(markdown_filename)
  path = Pathname.new(markdown_filename)
  filename = path.basename.to_s.sub(path.extname, ".pdf")
  "#{@output_dir}/#{filename}"
end
template() click to toggle source
# File lib/documentum/generator.rb, line 27
def template
  @template ||= File.read(@template_filename)
end