Skip to content

Commit

Permalink
tpl/collections: Make delimit return a string
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Oct 28, 2023
1 parent 705e3cd commit cfb6b6d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
7 changes: 2 additions & 5 deletions hugolib/page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ func normalizeExpected(ext, str string) string {
}

func testAllMarkdownEnginesForPages(t *testing.T,
assertFunc func(t *testing.T, ext string, pages page.Pages), settings map[string]any, pageSources ...string) {

assertFunc func(t *testing.T, ext string, pages page.Pages), settings map[string]any, pageSources ...string,
) {
engines := []struct {
ext string
shouldExecute func() bool
Expand Down Expand Up @@ -643,7 +643,6 @@ Simple Page With Some Date`
}

func TestPageRawContent(t *testing.T) {

files := `
-- hugo.toml --
-- content/basic.md --
Expand All @@ -668,7 +667,6 @@ title: "empty"

b.AssertFileContent("public/basic/index.html", "|**basic**|")
b.AssertFileContent("public/empty/index.html", "! title")

}

func TestPageWithShortCodeInSummary(t *testing.T) {
Expand Down Expand Up @@ -1954,5 +1952,4 @@ func TestRenderWithoutArgument(t *testing.T) {
).BuildE()

b.Assert(err, qt.IsNotNil)

}
8 changes: 3 additions & 5 deletions tpl/collections/collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions tpl/collections/collections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ func TestAfter(t *testing.T) {
}
}

type tstGrouper struct {
}
type tstGrouper struct{}

type tstGroupers []*tstGrouper

Expand All @@ -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()
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit cfb6b6d

Please sign in to comment.