[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. debian/0.24.6-1-356-g5718585

Brice Figureau brice-puppet at daysofwonder.com
Fri Jan 23 14:21:48 UTC 2009


The following commit has been merged in the master branch:
commit 607958cb7fe178596930b1506b69807dc78d111b
Author: Brice Figureau <brice-puppet at daysofwonder.com>
Date:   Sun Nov 23 00:01:23 2008 +0100

    Fix #1741 - Add inline_template function

diff --git a/lib/puppet/parser/functions/inline_template.rb b/lib/puppet/parser/functions/inline_template.rb
new file mode 100644
index 0000000..2897408
--- /dev/null
+++ b/lib/puppet/parser/functions/inline_template.rb
@@ -0,0 +1,21 @@
+Puppet::Parser::Functions::newfunction(:inline_template, :type => :rvalue, :doc => 
+    "Evaluate a template string and return its value.  See `the templating docs 
+    </trac/puppet/wiki/PuppetTemplating>`_ for more information.  Note that 
+    if multiple template strings are specified, their output is all concatenated 
+    and returned as the output of the function.") do |vals|
+        require 'erb'
+
+        vals.collect do |string|
+            # Use a wrapper, so the template can't get access to the full
+            # Scope object.
+
+            wrapper = Puppet::Parser::TemplateWrapper.new(self)
+            begin
+                wrapper.result(string)
+            rescue => detail
+                raise Puppet::ParseError,
+                    "Failed to parse inline template: %s" %
+                        [detail]
+            end
+        end.join("")
+end
diff --git a/spec/unit/parser/functions/template.rb b/spec/unit/parser/functions/inline_template.rb
similarity index 66%
copy from spec/unit/parser/functions/template.rb
copy to spec/unit/parser/functions/inline_template.rb
index 8fc64d0..19e1a3b 100644
--- a/spec/unit/parser/functions/template.rb
+++ b/spec/unit/parser/functions/inline_template.rb
@@ -2,14 +2,14 @@
 
 require File.dirname(__FILE__) + '/../../../spec_helper'
 
-describe "the template function" do
+describe "the inline_template function" do
 
     before :each do
         @scope = Puppet::Parser::Scope.new()
     end
 
     it "should exist" do
-        Puppet::Parser::Functions.function("template").should == "function_template"
+        Puppet::Parser::Functions.function("inline_template").should == "function_inline_template"
     end
 
     it "should create a TemplateWrapper when called" do
@@ -17,38 +17,35 @@ describe "the template function" do
 
         Puppet::Parser::TemplateWrapper.expects(:new).returns(tw)
 
-        @scope.function_template("test")
+        @scope.function_inline_template("test")
     end
 
-    it "should give the template filename to the TemplateWrapper" do
+    it "should pass the template string to TemplateWrapper.result" do
         tw = stub_everything 'template_wrapper'
         Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw)
 
-        tw.expects(:file=).with("test")
+        tw.expects(:result).with("test")
 
-        @scope.function_template("test")
+        @scope.function_inline_template("test")
     end
 
     it "should return what TemplateWrapper.result returns" do
         tw = stub_everything 'template_wrapper'
         Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw)
-        tw.stubs(:file=).with("test")
 
         tw.expects(:result).returns("template contents evaluated")
 
-        @scope.function_template("test").should == "template contents evaluated"
+        @scope.function_inline_template("test").should == "template contents evaluated"
     end
 
     it "should concatenate template wrapper outputs for multiple templates" do
         tw1 = stub_everything "template_wrapper1"
         tw2 = stub_everything "template_wrapper2"
         Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw1,tw2)
-        tw1.stubs(:file=).with("1")
-        tw2.stubs(:file=).with("2")
         tw1.stubs(:result).returns("result1")
         tw2.stubs(:result).returns("result2")
 
-        @scope.function_template(["1","2"]).should == "result1result2"
+        @scope.function_inline_template(["1","2"]).should == "result1result2"
     end
 
     it "should raise an error if the template raises an error" do
@@ -56,7 +53,7 @@ describe "the template function" do
         Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw)
         tw.stubs(:result).raises
 
-        lambda { @scope.function_template("1") }.should raise_error(Puppet::ParseError)
+        lambda { @scope.function_inline_template("1") }.should raise_error(Puppet::ParseError)
     end
 
 end
\ No newline at end of file

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list