From ebcb6b6df7af42632a6c1beaa1b60171ff32b61e Mon Sep 17 00:00:00 2001 From: lutter Date: Fri, 9 Mar 2007 00:48:28 +0000 Subject: The template function now tries to first find a template within a module (if the template path looks like it belongs to a module) and only when that fails looks for it in templatedir git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2277 980ebf18-57e1-0310-9a29-db15c13687c0 --- lib/puppet/modules.rb | 30 ++++++++++++++++++++++++++++++ lib/puppet/parser/templatewrapper.rb | 6 +----- 2 files changed, 31 insertions(+), 5 deletions(-) (limited to 'lib/puppet') 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, -- cgit