summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorNigel Gibbs <ngibbs@ucas.ac.uk>2015-08-14 09:33:46 +0100
committerNigel Gibbs <ngibbs@ucas.ac.uk>2015-08-14 13:30:01 +0100
commit4cbe846750c40dec57c55dbe6382dfa57c4d79af (patch)
tree2b1977336b137b436c540acd53380ba6244fd5d8 /lib
parente84090df1d081679e0c687614efb982354cf3cbe (diff)
downloadpuppet-stdlib-4cbe846750c40dec57c55dbe6382dfa57c4d79af.tar.gz
puppet-stdlib-4cbe846750c40dec57c55dbe6382dfa57c4d79af.tar.bz2
(MODULES-2410) Add new functions dos2unix and unix2dos
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/parser/functions/dos2unix.rb15
-rw-r--r--lib/puppet/parser/functions/unix2dos.rb15
2 files changed, 30 insertions, 0 deletions
diff --git a/lib/puppet/parser/functions/dos2unix.rb b/lib/puppet/parser/functions/dos2unix.rb
new file mode 100644
index 0000000..ccac899
--- /dev/null
+++ b/lib/puppet/parser/functions/dos2unix.rb
@@ -0,0 +1,15 @@
+# Custom Puppet function to convert dos to unix format
+module Puppet::Parser::Functions
+ newfunction(:dos2unix, :type => :rvalue, :arity => 1, :doc => <<-EOS
+ Returns the Unix version of the given string.
+ Takes a single string argument.
+ EOS
+ ) do |arguments|
+
+ unless arguments[0].is_a?(String)
+ raise(Puppet::ParseError, 'dos2unix(): Requires string as argument')
+ end
+
+ arguments[0].gsub(/\r\n/, "\n")
+ end
+end
diff --git a/lib/puppet/parser/functions/unix2dos.rb b/lib/puppet/parser/functions/unix2dos.rb
new file mode 100644
index 0000000..0bd9cd1
--- /dev/null
+++ b/lib/puppet/parser/functions/unix2dos.rb
@@ -0,0 +1,15 @@
+# Custom Puppet function to convert unix to dos format
+module Puppet::Parser::Functions
+ newfunction(:unix2dos, :type => :rvalue, :arity => 1, :doc => <<-EOS
+ Returns the DOS version of the given string.
+ Takes a single string argument.
+ EOS
+ ) do |arguments|
+
+ unless arguments[0].is_a?(String)
+ raise(Puppet::ParseError, 'unix2dos(): Requires string as argument')
+ end
+
+ arguments[0].gsub(/\r*\n/, "\r\n")
+ end
+end