Class: Hippo::Templates::Latex

Inherits:
Base
  • Object
show all
Defined in:
lib/hippo/templates/latex.rb

Defined Under Namespace

Classes: Context

Constant Summary collapse

ALL =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#class_as_name, #filename, format, #pathname, #source

Constructor Details

#initialize(id) ⇒ Latex

Returns a new instance of Latex.


32
33
34
# File 'lib/hippo/templates/latex.rb', line 32

def initialize(id)
    @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id


30
31
32
# File 'lib/hippo/templates/latex.rb', line 30

def id
  @id
end

Class Method Details

.for_identifier(id) ⇒ Object


11
12
13
# File 'lib/hippo/templates/latex.rb', line 11

def self.for_identifier(id)
    ALL.find{|tmpl| tmpl.identifier == id}
end

.inherited(klass) ⇒ Object


26
27
28
# File 'lib/hippo/templates/latex.rb', line 26

def self.inherited(klass)
    ALL << klass
end

Instance Method Details

#as_latexObject


46
47
48
# File 'lib/hippo/templates/latex.rb', line 46

def as_latex
    engine.compile_latex
end

#as_pdfObject


36
37
38
39
40
41
42
43
44
# File 'lib/hippo/templates/latex.rb', line 36

def as_pdf
    engine.to_stringio
rescue ErbLatex::LatexError => e
    Hippo.logger.warn e.log
    raise
rescue => e
    Hippo.logger.warn e
    raise
end

#contextObject


76
77
78
# File 'lib/hippo/templates/latex.rb', line 76

def context
    Context
end

#engineObject


96
97
98
# File 'lib/hippo/templates/latex.rb', line 96

def engine
    ErbLatex::Template.new(pathname, engine_options)
end

#engine_optionsObject


80
81
82
83
84
85
86
87
88
89
90
# File 'lib/hippo/templates/latex.rb', line 80

def engine_options
    options = {
        data: variables,
        context: context,
        partials_path: root_path.join('partials'),
        packages_path: root_path.join('packages')

    }
    options[:layout] = layout unless layout.blank?
    options
end

#extensionObject


62
63
64
# File 'lib/hippo/templates/latex.rb', line 62

def extension
    '.tex.erb'
end

#layoutObject


92
93
94
# File 'lib/hippo/templates/latex.rb', line 92

def layout
    root_path.join('layout.tex.erb')
end

#recordObject


58
59
60
# File 'lib/hippo/templates/latex.rb', line 58

def record
    @record ||= model.find(id)
end

#renderObject


66
67
68
69
70
71
72
73
74
# File 'lib/hippo/templates/latex.rb', line 66

def render
    engine.to_stringio
rescue ErbLatex::LatexError => e
    Hippo.logger.warn e.log
    raise
rescue => e
    Hippo.logger.warn e
    raise
end

#root_pathObject


50
51
52
# File 'lib/hippo/templates/latex.rb', line 50

def root_path
    super.join('latex')
end

#variablesObject


54
55
56
# File 'lib/hippo/templates/latex.rb', line 54

def variables
    { 'root_path' => root_path, class_as_name => record }
end