module PleaseRun::MustacheMethods

Methods for use within mustache render() calls.

Public Instance Methods

escaped(str) click to toggle source
# File lib/pleaserun/mustache_methods.rb, line 12
def escaped(str)
  return Shellwords.shellescape(Mustache.render(str, self))
end
escaped_args() click to toggle source
# File lib/pleaserun/mustache_methods.rb, line 7
def escaped_args
  return if args.nil?
  return Shellwords.shellescape(Shellwords.shelljoin(args))
end
quoted(str) click to toggle source
# File lib/pleaserun/mustache_methods.rb, line 39
def quoted(str)
  return shell_quote(render(str))
end
shell_args() click to toggle source
# File lib/pleaserun/mustache_methods.rb, line 16
def shell_args
  return if args.nil?
  return args.collect { |a| shell_quote(a) }.join(" ")
end
shell_continuation(str) click to toggle source
# File lib/pleaserun/mustache_methods.rb, line 35
def shell_continuation(str)
  return render(str).split("\n").reject { |l| l =~ /^\s*$/ }.join(" \\\n")
end
shell_quote(str) click to toggle source
# File lib/pleaserun/mustache_methods.rb, line 21
def shell_quote(str)
  # interpreted from POSIX 1003.1 2004 section 2.2.3 (Double-Quotes)

  # $ is has meaning, escape it.
  value = str.gsub(/(?<![\\])\$/, "\\$")
  # ` is has meaning, escape it.
  value = value.gsub(/`/) { "\\`" }

  # Backslash means escape a literal unless followed by one of $`"\
  value = value.gsub(/\\[^$`"\\]/) { |v| "\\#{v}" }    

  return "\"" + value + "\""
end