1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-30 06:08:57 +01:00

Add concat filter

This commit is contained in:
Daniil Gentili 2021-12-20 17:16:39 +01:00
parent 5cbe290051
commit 87434b73b6
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 4 additions and 0 deletions

View File

@ -42,6 +42,9 @@ func AddStandardFilters(fd FilterDictionary) { // nolint: gocyclo
}
return
})
fd.AddFilter("concat", func(a, b []interface{}) (result []interface{}) {
return append(append(result, a...), b...)
})
fd.AddFilter("join", joinFilter)
fd.AddFilter("map", func(a []map[string]interface{}, key string) (result []interface{}) {
for _, obj := range a {

View File

@ -32,6 +32,7 @@ var filterTests = []struct {
// array filters
{`pages | map: 'category' | join`, "business celebrities lifestyle sports technology"},
{`pages | map: 'category' | compact | join`, "business celebrities lifestyle sports technology"},
{`"mangos bananas persimmons" | split: " " | concat: fruits | join: ", "`, "mangos, bananas, persimmons, apples, oranges, peaches, plums"},
{`"John, Paul, George, Ringo" | split: ", " | join: " and "`, "John and Paul and George and Ringo"},
{`",John, Paul, George, Ringo" | split: ", " | join: " and "`, ",John and Paul and George and Ringo"},
{`"John, Paul, George, Ringo," | split: ", " | join: " and "`, "John and Paul and George and Ringo,"},