From 8a45646d4edf0171afecb654a9cd5b5822147be1 Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Fri, 19 May 2017 14:29:26 -0400 Subject: Documenting `join`, and adding an integration test for it Signed-off-by: Dave Henderson --- README.md | 18 ++++++++++++++++++ test/integration/typeconv_funcs.bats | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/README.md b/README.md index f395e564..33511bc9 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ Gomplate is an alternative that will let you process templates which also includ - [`trim`](#trim) - [`urlParse`](#urlparse) - [`has`](#has) + - [`join`](#join) - [`indent`](#indent) - [`json`](#json) - [`jsonArray`](#jsonarray) @@ -489,6 +490,23 @@ $ gomplate -d vault:///secret/foo < input.tmpl The secret is 'foo: bar' ``` +#### `join` + +Concatenates the elements of an array to create a string. The separator string sep is placed between elements in the resulting string. + +##### Example + +_`input.tmpl`_ +``` +{{ $a := `[1, 2, 3]` | jsonArray }} +{{ join $a "-" }} +``` + +```console +$ gomplate -f input.tmpl +1-2-3 +``` + #### `indent` Indents a given string with the given indentation pattern. If the input string has multiple lines, each line will be indented. diff --git a/test/integration/typeconv_funcs.bats b/test/integration/typeconv_funcs.bats index 14921117..dbb83c15 100644 --- a/test/integration/typeconv_funcs.bats +++ b/test/integration/typeconv_funcs.bats @@ -37,3 +37,9 @@ function teardown () { multiline world" ]] } + +@test "join" { + gomplate -i '{{ $a := `[1, 2, 3]` | jsonArray }}{{ join $a "-" }}' + [ "$status" -eq 0 ] + [[ "${output}" == "1-2-3" ]] +} -- cgit v1.2.3