Class: Kerb::Template

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

Instance Method Summary collapse

Constructor Details

#initialize(erb, vars) ⇒ Template

Returns a new instance of Template.



3
4
5
6
# File 'lib/kerb/template.rb', line 3

def initialize(erb, vars)
  @erb = erb
  vars.each { |k, v| instance_variable_set("@#{k}", v) }
end

Instance Method Details

#renderObject



8
9
10
# File 'lib/kerb/template.rb', line 8

def render
  ERB.new(@erb).result(binding)
end

#render_to_file(file) ⇒ Object



12
13
14
# File 'lib/kerb/template.rb', line 12

def render_to_file(file)
  File.open(file, 'w') { |f| f.write(render) }
end