Implement `template' task keyword
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user