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
This commit is contained in:
lutter 2007-03-09 00:48:28 +00:00
Родитель ba6257c02e
Коммит ebcb6b6df7
3 изменённых файлов: 48 добавлений и 5 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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,

Просмотреть файл

@ -38,4 +38,21 @@ class TestModules < Test::Unit::TestCase
assert_equal("testmod", mod.name)
assert_equal(path, mod.path)
end
def test_find_template
templ = "testmod/templ.erb"
assert_equal(File::join(Puppet[:templatedir], templ),
Puppet::Module::find_template(templ))
templ_path = File::join(@varmods, "testmod",
Puppet::Module::TEMPLATES, "templ.erb")
FileUtils::mkdir_p(File::dirname(templ_path))
File::open(templ_path, "w") { |f| f.puts "Howdy" }
assert_equal(templ_path, Puppet::Module::find_template(templ))
mod = Puppet::Module::find(templ)
assert_not_nil(mod)
assert_equal(templ_path, mod.template(templ))
end
end