diff options
author | Andrea Campi <andrea.campi@zephirworks.com> | 2012-11-18 22:43:55 +0100 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2012-12-14 11:10:28 -0800 |
commit | 5509897b9f0a536f6b3768f28f569d450ff53232 (patch) | |
tree | bffca25f527cb77c67c367c3146f031e87d25ef6 /lib/chef/mixin/template.rb | |
parent | d4b4bd7b658d36d1363879e269963bbbe8089663 (diff) | |
download | chef-5509897b9f0a536f6b3768f28f569d450ff53232.tar.gz |
[CHEF-3249] Basic implementation of partials in templates.
Diffstat (limited to 'lib/chef/mixin/template.rb')
-rw-r--r-- | lib/chef/mixin/template.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/chef/mixin/template.rb b/lib/chef/mixin/template.rb index 78148d2577..c25f5f6e1f 100644 --- a/lib/chef/mixin/template.rb +++ b/lib/chef/mixin/template.rb @@ -29,6 +29,22 @@ class Chef raise "Could not find a value for node. If you are explicitly setting variables in a template, " + "include a node variable if you plan to use it." end + + def render(partial_name, variables = nil) + raise "You cannot render partials in this context" unless @partial_resolver + + if variables + context = {} + context.merge!(variables) + context[:node] = node + else + context = self.dup + end + + template_location = @partial_resolver.call(partial_name) + eruby = Erubis::Eruby.new(IO.read(template_location)) + output = eruby.evaluate(context) + end end ::Erubis::Context.send(:include, ChefContext) |