Class: Skr::Print::Form

Inherits:
Object
  • Object
show all
Defined in:
lib/skr/print/form.rb

Instance Method Summary collapse

Constructor Details

#initialize(form, code) ⇒ Form

Returns a new instance of Form.



6
7
8
9
10
11
12
13
14
# File 'lib/skr/print/form.rb', line 6

def initialize(form, code)
    @template = Template.get(form) || raise("Unable to find template for #{form}")
    @record   = @template.model.where(hash_code: code).first!
    @latex    = @template.path_for_record(@record)
    unless @latex.exist?
        raise("Unable to find template type for record")
    end
    Lanes.logger.debug "Printing #{form} #{code} using #{@latex}"
end

Instance Method Details

#as_latexObject



20
21
22
# File 'lib/skr/print/form.rb', line 20

def as_latex
    template.compile_latex
end

#as_pdfObject



16
17
18
# File 'lib/skr/print/form.rb', line 16

def as_pdf
    template.to_stringio
end

#dataObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/skr/print/form.rb', line 24

def data
    vars = {
        @template.name.underscore => @record,
        'root_path' => ::Skr::Print::ROOT
    }
    if @record.respond_to?(:latex_template_variables)
        vars.merge!(@record.latex_template_variables)
    end
    vars
end

#templateObject



35
36
37
38
39
40
41
42
# File 'lib/skr/print/form.rb', line 35

def template
    ErbLatex::Template.new( @latex,
                            data: data,
                            layout: ROOT.join('layout.tex.erb'),
                            partials_path: ROOT.join('partials'),
                            packages_path: ROOT.join('packages')
                          )
end