diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-06-29 23:35:57 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-06-29 23:35:57 +0000 |
commit | a6dc7f2e22bf548240064a68ae2ee04309f7de24 (patch) | |
tree | 8635502ba90bd8071966c9f4e59a03903e050eb6 /lib/puppet/parser/functions.rb | |
parent | e47a98769380b37ec1ee65cf922ce2cc7aa7b88a (diff) | |
download | puppet-a6dc7f2e22bf548240064a68ae2ee04309f7de24.tar.gz puppet-a6dc7f2e22bf548240064a68ae2ee04309f7de24.tar.xz puppet-a6dc7f2e22bf548240064a68ae2ee04309f7de24.zip |
Adding initial template support. It is just a function, and a method_missing method on Scope.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1340 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/parser/functions.rb')
-rw-r--r-- | lib/puppet/parser/functions.rb | 24 |
1 files changed, 24 insertions, 0 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 |