tpl: Improve template funcs GoDoc

This commit is contained in:
Bjørn Erik Pedersen
2022-12-21 13:11:08 +01:00
parent aa2c724195
commit cd1ed563a8
17 changed files with 170 additions and 163 deletions

View File

@@ -24,9 +24,9 @@ import (
"github.com/gohugoio/hugo/tpl"
)
// Apply takes a map, array, or slice and returns a new slice with the function fname applied over it.
func (ns *Namespace) Apply(ctx context.Context, seq any, fname string, args ...any) (any, error) {
if seq == nil {
// Apply takes a map, array, or slice c and returns a new slice with the function fname applied over it.
func (ns *Namespace) Apply(ctx context.Context, c any, fname string, args ...any) (any, error) {
if c == nil {
return make([]any, 0), nil
}
@@ -34,7 +34,7 @@ func (ns *Namespace) Apply(ctx context.Context, seq any, fname string, args ...a
return nil, errors.New("can't apply myself (no turtles allowed)")
}
seqv := reflect.ValueOf(seq)
seqv := reflect.ValueOf(c)
seqv, isNil := indirect(seqv)
if isNil {
return nil, errors.New("can't iterate over a nil value")
@@ -61,7 +61,7 @@ func (ns *Namespace) Apply(ctx context.Context, seq any, fname string, args ...a
return r, nil
default:
return nil, fmt.Errorf("can't apply over %v", seq)
return nil, fmt.Errorf("can't apply over %v", c)
}
}