Skip to content

Commit

Permalink
concat
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenhilton committed May 19, 2024
1 parent 0e91528 commit 7704cc7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docs/templatefuncs.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
[one three]
```

## `concat` *list*...

`concat` concatenates *list*s into a new list.

```text
{{ concat (list 0 1 2) (list "a" "b" "c") }}
[0 1 2 a b c]
```

## `contains` *substring* *string*

`contains` returns whether *substring* is in *string*.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/chezmoi/templatefuncs

go 1.21
go 1.22

require github.com/alecthomas/assert/v2 v2.9.0

Expand Down
1 change: 1 addition & 0 deletions templatefuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var fileModeTypeNames = map[fs.FileMode]string{
func NewFuncMap() template.FuncMap {
return template.FuncMap{
"compact": compactTemplateFunc,
"concat": slices.Concat[[]any],
"contains": reverseArgs2(strings.Contains),
"eqFold": eqFoldTemplateFunc,
"fromJSON": eachByteSliceErr(fromJSONTemplateFunc),
Expand Down
4 changes: 4 additions & 0 deletions templatefuncs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func TestFuncMap(t *testing.T) {
template: `{{ list "one" "" list "three" | compact }}`,
expected: `[one three]`,
},
{
template: `{{ concat (list 0 1 2) (list "a" "b" "c") }}`,
expected: "[0 1 2 a b c]",
},
{
template: `{{ "abc" | contains "bc" }}`,
expected: "true",
Expand Down

0 comments on commit 7704cc7

Please sign in to comment.