mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-31 22:41:53 +02:00
@@ -40,7 +40,7 @@ func (ns *Namespace) Apply(ctx context.Context, c any, fname string, args ...any
|
||||
return nil, errors.New("can't iterate over a nil value")
|
||||
}
|
||||
|
||||
fnv, found := ns.lookupFunc(fname)
|
||||
fnv, found := ns.lookupFunc(ctx, fname)
|
||||
if !found {
|
||||
return nil, errors.New("can't find function " + fname)
|
||||
}
|
||||
@@ -106,7 +106,7 @@ func applyFnToThis(ctx context.Context, fn, this reflect.Value, args ...any) (re
|
||||
return reflect.ValueOf(nil), res[1].Interface().(error)
|
||||
}
|
||||
|
||||
func (ns *Namespace) lookupFunc(fname string) (reflect.Value, bool) {
|
||||
func (ns *Namespace) lookupFunc(ctx context.Context, fname string) (reflect.Value, bool) {
|
||||
namespace, methodName, ok := strings.Cut(fname, ".")
|
||||
if !ok {
|
||||
templ := ns.deps.Tmpl().(tpl.TemplateFuncGetter)
|
||||
@@ -114,16 +114,16 @@ func (ns *Namespace) lookupFunc(fname string) (reflect.Value, bool) {
|
||||
}
|
||||
|
||||
// Namespace
|
||||
nv, found := ns.lookupFunc(namespace)
|
||||
nv, found := ns.lookupFunc(ctx, namespace)
|
||||
if !found {
|
||||
return reflect.Value{}, false
|
||||
}
|
||||
|
||||
fn, ok := nv.Interface().(func(...any) (any, error))
|
||||
fn, ok := nv.Interface().(func(context.Context, ...any) (any, error))
|
||||
if !ok {
|
||||
return reflect.Value{}, false
|
||||
}
|
||||
v, err := fn()
|
||||
v, err := fn(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@@ -14,6 +14,8 @@
|
||||
package collections
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gohugoio/hugo/deps"
|
||||
"github.com/gohugoio/hugo/tpl/internal"
|
||||
)
|
||||
@@ -26,7 +28,7 @@ func init() {
|
||||
|
||||
ns := &internal.TemplateFuncsNamespace{
|
||||
Name: name,
|
||||
Context: func(args ...any) (any, error) { return ctx, nil },
|
||||
Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil },
|
||||
}
|
||||
|
||||
ns.AddMethodMapping(ctx.After,
|
||||
|
Reference in New Issue
Block a user