Class: Orca::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/orca/template.rb

Instance Method Summary collapse

Constructor Details

#initialize(node, path) ⇒ Template

Returns a new instance of Template.



5
6
7
8
9
# File 'lib/orca/template.rb', line 5

def initialize(node, path)
  @node = node
  @path = resolve(path)
  @template = Tilt.new(@path)
end

Instance Method Details

#render(locals = {}) ⇒ Object



11
12
13
# File 'lib/orca/template.rb', line 11

def render(locals={})
  @template.render(@node, locals)
end

#render_to_tempfile(locals = {}) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/orca/template.rb', line 15

def render_to_tempfile(locals={})
  basename = File.basename(@path).gsub('.', '-')
  file = Tempfile.new(basename)
  file.write render(locals)
  file.close
  file.path
end