diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-10-28 11:10:27 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-10-28 11:54:23 +0200 |
commit | e54139c85b75b171076138eb971d17c7c2264e37 (patch) | |
tree | c1d9f9b2e34ed50567c9d915fcb8f93811396563 /tpl | |
parent | 705e3cd5f558fb506f25c4255968bfdc907adb29 (diff) |
tpl/collections: Make delimit return a string
Closes #10876
Closes #11502
Diffstat (limited to 'tpl')
-rw-r--r-- | tpl/collections/collections.go | 8 | ||||
-rw-r--r-- | tpl/collections/collections_test.go | 10 |
2 files changed, 7 insertions, 11 deletions
diff --git a/tpl/collections/collections.go b/tpl/collections/collections.go index 279dbb169..e34753f17 100644 --- a/tpl/collections/collections.go +++ b/tpl/collections/collections.go @@ -17,16 +17,14 @@ package collections import ( "context" + "errors" "fmt" - "html/template" "math/rand" "net/url" "reflect" "strings" "time" - "errors" - "github.com/gohugoio/hugo/common/collections" "github.com/gohugoio/hugo/common/hugo" "github.com/gohugoio/hugo/common/maps" @@ -101,7 +99,7 @@ func (ns *Namespace) After(n any, l any) (any, error) { // Delimit takes a given list l and returns a string delimited by sep. // If last is passed to the function, it will be used as the final delimiter. -func (ns *Namespace) Delimit(ctx context.Context, l, sep any, last ...any) (template.HTML, error) { +func (ns *Namespace) Delimit(ctx context.Context, l, sep any, last ...any) (string, error) { d, err := cast.ToStringE(sep) if err != nil { return "", err @@ -154,7 +152,7 @@ func (ns *Namespace) Delimit(ctx context.Context, l, sep any, last ...any) (temp return "", fmt.Errorf("can't iterate over %v", l) } - return template.HTML(str), nil + return str, nil } // Dictionary creates a new map from the given parameters by diff --git a/tpl/collections/collections_test.go b/tpl/collections/collections_test.go index 43f8377f3..dcdd3bd5c 100644 --- a/tpl/collections/collections_test.go +++ b/tpl/collections/collections_test.go @@ -71,8 +71,7 @@ func TestAfter(t *testing.T) { } } -type tstGrouper struct { -} +type tstGrouper struct{} type tstGroupers []*tstGrouper @@ -81,8 +80,7 @@ func (g tstGrouper) Group(key any, items any) (any, error) { return fmt.Sprintf("%v(%d)", key, ilen), nil } -type tstGrouper2 struct { -} +type tstGrouper2 struct{} func (g *tstGrouper2) Group(key any, items any) (any, error) { ilen := reflect.ValueOf(items).Len() @@ -134,7 +132,7 @@ func TestDelimit(t *testing.T) { seq any delimiter any last any - expect template.HTML + expect string }{ {[]string{"class1", "class2", "class3"}, " ", nil, "class1 class2 class3"}, {[]int{1, 2, 3, 4, 5}, ",", nil, "1,2,3,4,5"}, @@ -163,7 +161,7 @@ func TestDelimit(t *testing.T) { } { errMsg := qt.Commentf("[%d] %v", i, test) - var result template.HTML + var result string var err error if test.last == nil { |