Class: Hippo::Templates::Latex
- Inherits:
-
Base
- Object
- Base
- Hippo::Templates::Latex
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
#id ⇒ Object
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_latex ⇒ Object
46
47
48
|
# File 'lib/hippo/templates/latex.rb', line 46
def as_latex
engine.compile_latex
end
|
#as_pdf ⇒ Object
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
|
#context ⇒ Object
76
77
78
|
# File 'lib/hippo/templates/latex.rb', line 76
def context
Context
end
|
#engine ⇒ Object
96
97
98
|
# File 'lib/hippo/templates/latex.rb', line 96
def engine
ErbLatex::Template.new(pathname, engine_options)
end
|
#engine_options ⇒ Object
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
|
#extension ⇒ Object
62
63
64
|
# File 'lib/hippo/templates/latex.rb', line 62
def extension
'.tex.erb'
end
|
#layout ⇒ Object
92
93
94
|
# File 'lib/hippo/templates/latex.rb', line 92
def layout
root_path.join('layout.tex.erb')
end
|
#record ⇒ Object
58
59
60
|
# File 'lib/hippo/templates/latex.rb', line 58
def record
@record ||= model.find(id)
end
|
#render ⇒ Object
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_path ⇒ Object
50
51
52
|
# File 'lib/hippo/templates/latex.rb', line 50
def root_path
super.join('latex')
end
|
#variables ⇒ Object
54
55
56
|
# File 'lib/hippo/templates/latex.rb', line 54
def variables
{ 'root_path' => root_path, class_as_name => record }
end
|