diff options
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/modules.rb | 30 | ||||
-rw-r--r-- | lib/puppet/parser/templatewrapper.rb | 6 |
2 files changed, 31 insertions, 5 deletions
diff --git a/lib/puppet/modules.rb b/lib/puppet/modules.rb index cf611b82c..2d48a6a4e 100644 --- a/lib/puppet/modules.rb +++ b/lib/puppet/modules.rb @@ -1,6 +1,8 @@ # Support for modules class Puppet::Module + TEMPLATES = "templates" + # Return an array of paths by splitting the +modulepath+ config # parameter. Only consider paths that are absolute and existing # directories @@ -32,11 +34,39 @@ class Puppet::Module # Instance methods + # Find the concrete file denoted by +file+. If +file+ is absolute, + # return it directly. Otherwise try to find it as a template in a + # module. If that fails, return it relative to the +templatedir+ config + # param. + # In all cases, an absolute path is returned, which does not + # necessarily refer to an existing file + def self.find_template(file) + if file =~ /^#{File::SEPARATOR}/ + return file + end + + mod = find(file) + if mod + return mod.template(file) + else + return File.join(Puppet[:templatedir], file) + end + end + attr_reader :name, :path def initialize(name, path) @name = name @path = path end + def strip(file) + n, rest = file.split(File::SEPARATOR, 2) + return rest + end + + def template(file) + return File::join(path, TEMPLATES, strip(file)) + end + private :initialize end diff --git a/lib/puppet/parser/templatewrapper.rb b/lib/puppet/parser/templatewrapper.rb index 62b45852b..3b8cc3a3a 100644 --- a/lib/puppet/parser/templatewrapper.rb +++ b/lib/puppet/parser/templatewrapper.rb @@ -7,11 +7,7 @@ class Puppet::Parser::TemplateWrapper def initialize(scope, file) @scope = scope - if file =~ /^#{File::SEPARATOR}/ - @file = file - else - @file = File.join(Puppet[:templatedir], file) - end + @file = Puppet::Module::find_template(file) unless FileTest.exists?(@file) raise Puppet::ParseError, |