1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
# frozen_string_literal: true
# = Prawn
#
# Prawn template implementation.
#
# === See also
#
# * http://prawnpdf.org
#
# === Related module
#
# * Tilt::PrawnTemplate
require_relative 'template'
require 'prawn'
module Tilt
class PrawnTemplate < Template
self.default_mime_type = 'application/pdf'
def prepare
@options[:page_size] = 'A4' unless @options.has_key?(:page_size)
@options[:page_layout] = :portrait unless @options.has_key?(:page_layout)
end
def evaluate(scope, locals, &block)
pdf = ::Prawn::Document.new(@options)
locals = locals.dup
locals[:pdf] = pdf
super
pdf.render
end
def precompiled_template(locals)
@data.to_str
end
end
end
|