From a95a25dac45df2fd04fba321eb66dbb868c1283a Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Sat, 17 Nov 2018 13:01:20 -0500 Subject: Adding quote and squote functions Signed-off-by: Dave Henderson --- docs-src/content/functions/strings.yml | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'docs-src/content/functions/strings.yml') diff --git a/docs-src/content/functions/strings.yml b/docs-src/content/functions/strings.yml index 6e3807c3..172184db 100644 --- a/docs-src/content/functions/strings.yml +++ b/docs-src/content/functions/strings.yml @@ -1,6 +1,29 @@ ns: strings preamble: '' funcs: + - name: strings.Quote + alias: quote + description: | + Surrounds an input string with double-quote characters (`"`). If the input is not a string, converts first. + + `"` characters in the input are first escaped with a `\` character. + + This is a convenience function which is equivalent to: + + ``` + {{ print "%q" "input string" }} + ``` + pipeline: true + arguments: + - name: in + required: true + description: The input to quote + examples: + - | + $ gomplate -i '{{ "in" | quote }}' + "in" + $ gomplate -i '{{ strings.Quote 500 }}' + "500" - name: strings.Sort alias: sort description: | @@ -14,3 +37,20 @@ funcs: - | $ gomplate -i '{{ (slice "foo" "bar" "baz") | sort }}' [bar baz foo] + - name: strings.Squote + alias: squote + description: | + Surrounds an input string with a single-quote (apostrophe) character (`'`). If the input is not a string, converts first. + + `'` characters in the input are first escaped in the YAML-style (by repetition: `''`). + pipeline: true + arguments: + - name: in + required: true + description: The input to quote + examples: + - | + $ gomplate -i '{{ "in" | squote }}' + 'in' + $ gomplate -i "{{ strings.Squote \"it's a banana\" }}" + 'it''s a banana' -- cgit v1.2.3