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/content/functions/strings.md | 70 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'docs') diff --git a/docs/content/functions/strings.md b/docs/content/functions/strings.md index 1f1dae42..460212ad 100644 --- a/docs/content/functions/strings.md +++ b/docs/content/functions/strings.md @@ -224,6 +224,44 @@ foo bar:baz ``` +## `strings.Quote` + +**Alias:** `quote` + +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" }} +``` + +### Usage +```go +strings.Quote in +``` + +```go +in | strings.Quote +``` + +### Arguments + +| name | description | +|------|-------------| +| `in` | _(required)_ The input to quote | + +### Examples + +```console +$ gomplate -i '{{ "in" | quote }}' +"in" +$ gomplate -i '{{ strings.Quote 500 }}' +"500" +``` + ## `strings.Repeat` Returns a new string consisting of `count` copies of the input string. @@ -291,6 +329,38 @@ $ echo 'Rock & Roll @ Cafe Wha?' | gomplate -d in=stdin: -i '{{ strings.Slug (in rock-and-roll-at-cafe-wha ``` +## `strings.Squote` + +**Alias:** `squote` + +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: `''`). + +### Usage +```go +strings.Squote in +``` + +```go +in | strings.Squote +``` + +### Arguments + +| name | description | +|------|-------------| +| `in` | _(required)_ The input to quote | + +### Examples + +```console +$ gomplate -i '{{ "in" | squote }}' +'in' +$ gomplate -i "{{ strings.Squote \"it's a banana\" }}" +'it''s a banana' +``` + ## `strings.Title` **Alias:** `title` -- cgit v1.2.3