Implement `template' task keyword

This commit is contained in:
Thibault Jouan
2014-09-28 14:32:01 +00:00
parent ff0287b545
commit 6cd294a0b8
3 changed files with 47 additions and 0 deletions

View File

@@ -57,6 +57,25 @@ module Producer
def get(key)
@env[key]
end
def template(path, variables = {})
path = "#{path}.erb"
tpl = ERB.new(File.read(path), nil, '-')
tpl.filename = path
tpl.result build_erb_binding variables
end
private
def build_erb_binding(variables)
Object.new.instance_eval do |o|
variables.each do |k, v|
o.instance_variable_set "@#{k}", v
end
binding
end
end
end
end
end