summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-06-29 23:35:57 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-06-29 23:35:57 +0000
commita6dc7f2e22bf548240064a68ae2ee04309f7de24 (patch)
tree8635502ba90bd8071966c9f4e59a03903e050eb6
parente47a98769380b37ec1ee65cf922ce2cc7aa7b88a (diff)
downloadpuppet-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
-rw-r--r--lib/puppet/parser/functions.rb24
-rw-r--r--lib/puppet/parser/scope.rb14
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)