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.



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/chef/mixin/template.rb', line 78

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