Class: Rtprov::Template
- Inherits:
-
Object
show all
- Defined in:
- lib/rtprov/template.rb
Defined Under Namespace
Classes: RenderingContext
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(source) ⇒ Template
49
50
51
|
# File 'lib/rtprov/template.rb', line 49
def initialize(source)
@erb = ERB.new(source, trim_mode: "-")
end
|
Class Method Details
.find(router, name) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/rtprov/template.rb', line 36
def self.find(router, name)
candidates = [
"templates/#{router}/#{name}.erb",
"templates/#{name}.erb",
]
candidates.find do |candidate|
return new(File.read(candidate)) if File.exist?(candidate)
end
raise "Template `#{name}` not found in #{candidates.inspect}"
end
|
Instance Method Details
#render(variables) ⇒ Object
53
54
55
56
|
# File 'lib/rtprov/template.rb', line 53
def render(variables)
context = RenderingContext.new(variables)
@erb.result(context.binding)
end
|