Module: Chef::Mixin::Template

Included in:
Provider::Template
Defined in:
lib/chef/mixin/template.rb

Defined Under Namespace

Modules: ChefContext Classes: TemplateError

Instance Method Summary collapse

Instance Method Details

#render_template(template, context) ⇒ Object

Render a template with Erubis. Takes a template as a string, and a context hash.


38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/chef/mixin/template.rb', line 38

def render_template(template, context)
  begin
    eruby = Erubis::Eruby.new(template)
    output = eruby.evaluate(context)
  rescue Object => e
    raise TemplateError.new(e, template, context)
  end
  Tempfile.open("chef-rendered-template") do |tempfile|
    tempfile.print(output)
    tempfile.close
    yield tempfile
  end
end