summaryrefslogtreecommitdiff
path: root/lib/chef/provider/template.rb
diff options
context:
space:
mode:
authorAndrea Campi <andrea.campi@zephirworks.com>2012-11-18 23:24:49 +0100
committerBryan McLellan <btm@opscode.com>2012-12-14 11:10:28 -0800
commit3dd9365d285bd1bd316be6270e108a229595668a (patch)
tree7de2d64c7f8f30d5fe163af6ca686c569c8202db /lib/chef/provider/template.rb
parent5509897b9f0a536f6b3768f28f569d450ff53232 (diff)
downloadchef-3dd9365d285bd1bd316be6270e108a229595668a.tar.gz
[CHEF-3249] Refactor template name resolution out to a separate class for DRYness and readability. While here let's also extend the API to support local templates, as well as templates from other cookbooks.
Diffstat (limited to 'lib/chef/provider/template.rb')
-rw-r--r--lib/chef/provider/template.rb18
1 files changed, 8 insertions, 10 deletions
diff --git a/lib/chef/provider/template.rb b/lib/chef/provider/template.rb
index cce3418f91..703b596d2b 100644
--- a/lib/chef/provider/template.rb
+++ b/lib/chef/provider/template.rb
@@ -17,6 +17,7 @@
# limitations under the License.
#
+require 'chef/provider/template_finder'
require 'chef/provider/file'
require 'chef/mixin/template'
require 'chef/mixin/checksum'
@@ -77,15 +78,15 @@ class Chef
end
end
+ def template_finder
+ @template_finder ||= begin
+ TemplateFinder.new(run_context, cookbook_name, node)
+ end
+ end
def template_location
@template_file_cache_location ||= begin
- if @new_resource.local
- @new_resource.source
- else
- cookbook = run_context.cookbook_collection[resource_cookbook]
- cookbook.preferred_filename_on_disk_location(node, :templates, @new_resource.source)
- end
+ template_finder.find(@new_resource.source, :local => @new_resource.local, :cookbook => @new_resource.cookbook)
end
end
@@ -109,10 +110,7 @@ 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
+ context[:template_finder] = template_finder
render_template(IO.read(template_location), context, &block)
end