diff options
-rw-r--r-- | lib/puppet/parser/functions.rb | 24 | ||||
-rw-r--r-- | lib/puppet/parser/scope.rb | 14 |
2 files changed, 37 insertions, 1 deletions
diff --git a/lib/puppet/parser/functions.rb b/lib/puppet/parser/functions.rb index 31053596f..3a9f0cd35 100644 --- a/lib/puppet/parser/functions.rb +++ b/lib/puppet/parser/functions.rb @@ -120,6 +120,30 @@ module Functions vals = vals.collect { |s| s.to_s }.join(" ") if vals.is_a? Array raise Puppet::ParseError, vals.to_s end + + newfunction(:template, :rvalue) do |vals| + require 'erb' + + vals.collect do |file| + unless file =~ /^#{File::SEPARATOR}/ + file = File.join(Puppet[:templatedir], file) + end + + unless File.exists?(file) + raise Puppet::ParseError, + "Could not find template %s" % file + end + + template = ERB.new(File.read(file)) + + begin + template.result(binding) + rescue => detail + raise Puppet::ParseError, "Could not interpret template %s: %s" % + [file, detail] + end + end.join("\n") + end end end diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index b607bb081..9165cdb7e 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -12,7 +12,11 @@ module Puppet::Parser # This doesn't actually work right now. Puppet.config.setdefaults(:puppet, - :lexical => [false, "Whether to use lexical scoping (vs. dynamic)."]) + :lexical => [false, "Whether to use lexical scoping (vs. dynamic)."], + :templatedir => ["$vardir/templates", + "Where Puppet looks for template files." + ] + ) Puppet::Util.logmethods(self) @@ -39,6 +43,14 @@ module Puppet::Parser @@declarative = val end + def method_missing(name, *args) + if value = lookupvar(name.to_s) and value != :undefined and value != "" + return value + else + super + end + end + # Add all of the defaults for a given object to that object. def adddefaults(obj) defaults = lookupdefaults(obj.type) |