Module: PleaseRun::MustacheMethods
- Included in:
- Platform::Base, User::Base
- Defined in:
- lib/pleaserun/mustache_methods.rb
Overview
Methods for use within mustache render() calls.
Instance Method Summary collapse
-
#escaped(str) ⇒ Object
def escaped_args.
- #escaped_args ⇒ Object
-
#quoted(str) ⇒ Object
def shell_continuation.
-
#shell_args ⇒ Object
def escaped.
-
#shell_continuation(str) ⇒ Object
def shell_quote.
-
#shell_quote(str) ⇒ Object
def shell_args.
Instance Method Details
#escaped(str) ⇒ Object
def escaped_args
12 13 14 |
# File 'lib/pleaserun/mustache_methods.rb', line 12 def escaped(str) return Shellwords.shellescape(Mustache.render(str, self)) end |
#escaped_args ⇒ Object
7 8 9 10 |
# File 'lib/pleaserun/mustache_methods.rb', line 7 def escaped_args return if args.nil? return Shellwords.shellescape(Shellwords.shelljoin(args)) end |
#quoted(str) ⇒ Object
def shell_continuation
39 40 41 |
# File 'lib/pleaserun/mustache_methods.rb', line 39 def quoted(str) return shell_quote(render(str)) end |
#shell_args ⇒ Object
def escaped
16 17 18 19 |
# 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) ⇒ Object
def shell_quote
35 36 37 |
# 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) ⇒ Object
def shell_args
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# 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 |