Add multi_source_template function
[puppet_common.git] / lib / puppet / parser / functions / multi_source_template.rb
1 module Puppet::Parser::Functions
2     require 'erb'
3
4     newfunction(:multi_source_template, :type => :rvalue) do |args|
5         contents = nil
6         environment = compiler.environment
7         sources = args
8
9         sources.each do |file|
10             Puppet.debug("Looking for #{file} in #{environment}")
11             if filename = Puppet::Parser::Files.find_template(file, environment.to_s)
12                 wrapper = Puppet::Parser::TemplateWrapper.new(self)
13                 wrapper.file = file
14
15                 begin
16                      contents = wrapper.result
17                 rescue => detail
18                      raise Puppet::ParseError, "Failed to parse template %s: %s" % [file, detail]
19                 end
20
21                 break
22             end
23         end
24
25         raise Puppet::ParseError, "multi_source_template: No match found for files: #{sources.join(', ')}" if contents == nil
26
27         contents
28     end
29 end