summaryrefslogtreecommitdiffstats
path: root/lib/puppet/module.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-09-27 21:30:49 +0200
committerLuke Kanies <luke@madstop.com>2008-09-27 21:30:49 +0200
commitb96bdc6a63f7be6b724c2aa7ad0ea007cba81718 (patch)
tree6d334ea12e1468b34160fa36da29dd7d78ac31ea /lib/puppet/module.rb
parente20f02af4a93478c5b08b7681caa12cd72b4a3a6 (diff)
parent3749267093923692d6e7bc0c9ce83b43a487b19e (diff)
downloadpuppet-b96bdc6a63f7be6b724c2aa7ad0ea007cba81718.tar.gz
puppet-b96bdc6a63f7be6b724c2aa7ad0ea007cba81718.tar.xz
puppet-b96bdc6a63f7be6b724c2aa7ad0ea007cba81718.zip
Merge branch '0.24.x' of git://github.com/jamtur01/puppet into 0.24.x
Diffstat (limited to 'lib/puppet/module.rb')
-rw-r--r--lib/puppet/module.rb40
1 files changed, 29 insertions, 11 deletions
diff --git a/lib/puppet/module.rb b/lib/puppet/module.rb
index 544d94ea9..b34f2f8b0 100644
--- a/lib/puppet/module.rb
+++ b/lib/puppet/module.rb
@@ -19,6 +19,15 @@ class Puppet::Module
end
end
+ # Return an array of paths by splitting the +templatedir+ config
+ # parameter.
+ def self.templatepath(environment = nil)
+ dirs = Puppet.settings.value(:templatedir, environment).split(":")
+ dirs.select do |p|
+ p =~ /^#{File::SEPARATOR}/ && File::directory?(p)
+ end
+ end
+
# Find and return the +module+ that +path+ belongs to. If +path+ is
# absolute, or if there is no module whose name is the first component
# of +path+, return +nil+
@@ -63,25 +72,33 @@ class Puppet::Module
return template
end
+ template_paths = templatepath(environment)
+ default_template_path = File::join(template_paths.first, template)
+
# If we can find the template in :templatedir, we return that.
- td_file = File.join(Puppet.settings.value(:templatedir, environment), template)
- return td_file if File.exists?(td_file)
-
+ td_file = template_paths.collect { |path|
+ File::join(path, template)
+ }.find { |f| File.exists?(f) }
+
+ return td_file unless td_file == nil
+
+ td_file = find_template_for_module(template, environment)
+ td_file ||= default_template_path
+ end
+
+ def self.find_template_for_module(template, environment = nil)
path, file = split_path(template)
# Because templates don't have an assumed template name, like manifests do,
# we treat templates with no name as being templates in the main template
# directory.
- if file.nil?
- mod = nil
- else
+ if not file.nil?
mod = find(path, environment)
+ if mod
+ return mod.template(file)
+ end
end
- if mod
- return mod.template(file)
- else
- return td_file # Return this anyway, since we're going to fail.
- end
+ nil
end
# Return a list of manifests (as absolute filenames) that match +pat+
@@ -144,4 +161,5 @@ class Puppet::Module
end
private :initialize
+ private_class_method :find_template_for_module
end