summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
authorAndrea Campi <andrea.campi@zephirworks.com>2012-11-18 22:43:55 +0100
committerBryan McLellan <btm@opscode.com>2012-12-14 11:10:28 -0800
commit5509897b9f0a536f6b3768f28f569d450ff53232 (patch)
treebffca25f527cb77c67c367c3146f031e87d25ef6 /lib/chef
parentd4b4bd7b658d36d1363879e269963bbbe8089663 (diff)
downloadchef-5509897b9f0a536f6b3768f28f569d450ff53232.tar.gz
[CHEF-3249] Basic implementation of partials in templates.
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/mixin/template.rb16
-rw-r--r--lib/chef/provider/template.rb4
2 files changed, 20 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)
diff --git a/lib/chef/provider/template.rb b/lib/chef/provider/template.rb
index c937b9d980..cce3418f91 100644
--- a/lib/chef/provider/template.rb
+++ b/lib/chef/provider/template.rb
@@ -109,6 +109,10 @@ class Chef
context = {}
context.merge!(@new_resource.variables)
context[:node] = node
+ context[:partial_resolver] = lambda do
+ cookbook = _run_context.cookbook_collection[resource_cookbook]
+ partial_location = cookbook.preferred_filename_on_disk_location(node, :templates, partial_name)
+ end
render_template(IO.read(template_location), context, &block)
end