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 ea3fac2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ jobs:
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7
with:
go-version: 'stable'
- run: go test ./...
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7
with:
go-version: 'stable'
- uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64
with:
version: v1.58.1
Expand Down
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 ea3fac2

Please sign in to comment.