Class: Kerb::Template
- Inherits:
-
Object
- Object
- Kerb::Template
- Defined in:
- lib/kerb/template.rb
Instance Method Summary collapse
-
#initialize(erb, vars) ⇒ Template
constructor
A new instance of Template.
- #render ⇒ Object
- #render_to_file(file) ⇒ Object
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
#render ⇒ Object
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 |