Class: Tilt::PrawnTemplate

Inherits:
Template show all
Defined in:
lib/tilt/prawn.rb

Overview

Prawn template implementation. See: prawnpdf.org

Instance Attribute Summary

Attributes inherited from Template

#data, #file, #line, #options

Instance Method Summary collapse

Methods inherited from Template

#basename, default_mime_type, default_mime_type=, #eval_file, #initialize, metadata, #metadata, #name, #render

Constructor Details

This class inherits a constructor from Tilt::Template

Instance Method Details

#allows_script?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/tilt/prawn.rb', line 25

def allows_script?
  false
end

#evaluate(scope, locals, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/tilt/prawn.rb', line 14

def evaluate(scope, locals, &block)
  pdf = @engine
  if data.respond_to?(:to_str)
    locals[:pdf] = pdf
    super(scope, locals, &block)
  elsif data.kind_of?(Proc)
    data.call(pdf)
  end
  @output ||= pdf.render
end

#precompiled_template(locals) ⇒ Object



29
30
31
# File 'lib/tilt/prawn.rb', line 29

def precompiled_template(locals)
  data.to_str
end

#prepareObject



10
11
12
# File 'lib/tilt/prawn.rb', line 10

def prepare
  @engine = ::Prawn::Document.new(prawn_options)
end