mirror of
https://github.com/gohugoio/hugo.git
synced 2025-03-23 12:33:27 +00:00
tpl: Make the Namespace func signature explicit
This makes it cleaner and avoids breaking client code, such as the docs helper JSON generator.
This commit is contained in:
parent
ebd636e4d5
commit
1f9e8dcc60
37 changed files with 40 additions and 40 deletions
tpl
cast
collections
compare
crypto
data
encoding
fmt
images
inflect
internal
lang
math
os
partials
safe
strings
time
transform
urls
|
@ -26,7 +26,7 @@ func init() {
|
|||
|
||||
ns := &internal.TemplateFuncsNamespace{
|
||||
Name: name,
|
||||
Context: func() interface{} { return ctx },
|
||||
Context: func(args ...interface{}) interface{} { return ctx },
|
||||
}
|
||||
|
||||
ns.AddMethodMapping(ctx.ToInt,
|
||||
|
|
|
@ -34,5 +34,5 @@ func TestInit(t *testing.T) {
|
|||
}
|
||||
|
||||
require.True(t, found)
|
||||
require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
|
||||
require.IsType(t, &Namespace{}, ns.Context())
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func init() {
|
|||
|
||||
ns := &internal.TemplateFuncsNamespace{
|
||||
Name: name,
|
||||
Context: func() interface{} { return ctx },
|
||||
Context: func(args ...interface{}) interface{} { return ctx },
|
||||
}
|
||||
|
||||
ns.AddMethodMapping(ctx.After,
|
||||
|
|
|
@ -34,5 +34,5 @@ func TestInit(t *testing.T) {
|
|||
}
|
||||
|
||||
require.True(t, found)
|
||||
require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
|
||||
require.IsType(t, &Namespace{}, ns.Context())
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func init() {
|
|||
|
||||
ns := &internal.TemplateFuncsNamespace{
|
||||
Name: name,
|
||||
Context: func() interface{} { return ctx },
|
||||
Context: func(args ...interface{}) interface{} { return ctx },
|
||||
}
|
||||
|
||||
ns.AddMethodMapping(ctx.Default,
|
||||
|
|
|
@ -34,5 +34,5 @@ func TestInit(t *testing.T) {
|
|||
}
|
||||
|
||||
require.True(t, found)
|
||||
require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
|
||||
require.IsType(t, &Namespace{}, ns.Context())
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func init() {
|
|||
|
||||
ns := &internal.TemplateFuncsNamespace{
|
||||
Name: name,
|
||||
Context: func() interface{} { return ctx },
|
||||
Context: func(args ...interface{}) interface{} { return ctx },
|
||||
}
|
||||
|
||||
ns.AddMethodMapping(ctx.MD5,
|
||||
|
|
|
@ -34,5 +34,5 @@ func TestInit(t *testing.T) {
|
|||
}
|
||||
|
||||
require.True(t, found)
|
||||
require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
|
||||
require.IsType(t, &Namespace{}, ns.Context())
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func init() {
|
|||
|
||||
ns := &internal.TemplateFuncsNamespace{
|
||||
Name: name,
|
||||
Context: func() interface{} { return ctx },
|
||||
Context: func(args ...interface{}) interface{} { return ctx },
|
||||
}
|
||||
|
||||
ns.AddMethodMapping(ctx.GetCSV,
|
||||
|
|
|
@ -34,5 +34,5 @@ func TestInit(t *testing.T) {
|
|||
}
|
||||
|
||||
require.True(t, found)
|
||||
require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
|
||||
require.IsType(t, &Namespace{}, ns.Context())
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func init() {
|
|||
|
||||
ns := &internal.TemplateFuncsNamespace{
|
||||
Name: name,
|
||||
Context: func() interface{} { return ctx },
|
||||
Context: func(args ...interface{}) interface{} { return ctx },
|
||||
}
|
||||
|
||||
ns.AddMethodMapping(ctx.Base64Decode,
|
||||
|
|
|
@ -34,5 +34,5 @@ func TestInit(t *testing.T) {
|
|||
}
|
||||
|
||||
require.True(t, found)
|
||||
require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
|
||||
require.IsType(t, &Namespace{}, ns.Context())
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func init() {
|
|||
|
||||
ns := &internal.TemplateFuncsNamespace{
|
||||
Name: name,
|
||||
Context: func() interface{} { return ctx },
|
||||
Context: func(args ...interface{}) interface{} { return ctx },
|
||||
}
|
||||
|
||||
ns.AddMethodMapping(ctx.Print,
|
||||
|
|
|
@ -34,5 +34,5 @@ func TestInit(t *testing.T) {
|
|||
}
|
||||
|
||||
require.True(t, found)
|
||||
require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
|
||||
require.IsType(t, &Namespace{}, ns.Context())
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func init() {
|
|||
|
||||
ns := &internal.TemplateFuncsNamespace{
|
||||
Name: name,
|
||||
Context: func() interface{} { return ctx },
|
||||
Context: func(args ...interface{}) interface{} { return ctx },
|
||||
}
|
||||
|
||||
ns.AddMethodMapping(ctx.Config,
|
||||
|
|
|
@ -34,5 +34,5 @@ func TestInit(t *testing.T) {
|
|||
}
|
||||
|
||||
require.True(t, found)
|
||||
require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
|
||||
require.IsType(t, &Namespace{}, ns.Context())
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func init() {
|
|||
|
||||
ns := &internal.TemplateFuncsNamespace{
|
||||
Name: name,
|
||||
Context: func() interface{} { return ctx },
|
||||
Context: func(args ...interface{}) interface{} { return ctx },
|
||||
}
|
||||
|
||||
ns.AddMethodMapping(ctx.Humanize,
|
||||
|
|
|
@ -34,5 +34,5 @@ func TestInit(t *testing.T) {
|
|||
}
|
||||
|
||||
require.True(t, found)
|
||||
require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
|
||||
require.IsType(t, &Namespace{}, ns.Context())
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ type TemplateFuncsNamespace struct {
|
|||
Name string
|
||||
|
||||
// This is the method receiver.
|
||||
Context interface{}
|
||||
Context func(v ...interface{}) interface{}
|
||||
|
||||
// Additional info, aliases and examples, per method name.
|
||||
MethodMappings map[string]TemplateFuncMethodMapping
|
||||
|
@ -165,7 +165,7 @@ func (t *TemplateFuncsNamespace) toJSON() ([]byte, error) {
|
|||
|
||||
buf.WriteString(fmt.Sprintf(`%q: {`, t.Name))
|
||||
|
||||
ctx := t.Context.(func() interface{})()
|
||||
ctx := t.Context()
|
||||
ctxType := reflect.TypeOf(ctx)
|
||||
for i := 0; i < ctxType.NumMethod(); i++ {
|
||||
method := ctxType.Method(i)
|
||||
|
|
|
@ -26,7 +26,7 @@ func init() {
|
|||
|
||||
ns := &internal.TemplateFuncsNamespace{
|
||||
Name: name,
|
||||
Context: func() interface{} { return ctx },
|
||||
Context: func(args ...interface{}) interface{} { return ctx },
|
||||
}
|
||||
|
||||
ns.AddMethodMapping(ctx.Translate,
|
||||
|
|
|
@ -34,5 +34,5 @@ func TestInit(t *testing.T) {
|
|||
}
|
||||
|
||||
require.True(t, found)
|
||||
require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
|
||||
require.IsType(t, &Namespace{}, ns.Context())
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func init() {
|
|||
|
||||
ns := &internal.TemplateFuncsNamespace{
|
||||
Name: name,
|
||||
Context: func() interface{} { return ctx },
|
||||
Context: func(args ...interface{}) interface{} { return ctx },
|
||||
}
|
||||
|
||||
ns.AddMethodMapping(ctx.Add,
|
||||
|
|
|
@ -34,5 +34,5 @@ func TestInit(t *testing.T) {
|
|||
}
|
||||
|
||||
require.True(t, found)
|
||||
require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
|
||||
require.IsType(t, &Namespace{}, ns.Context())
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func init() {
|
|||
|
||||
ns := &internal.TemplateFuncsNamespace{
|
||||
Name: name,
|
||||
Context: func() interface{} { return ctx },
|
||||
Context: func(args ...interface{}) interface{} { return ctx },
|
||||
}
|
||||
|
||||
ns.AddMethodMapping(ctx.Getenv,
|
||||
|
|
|
@ -34,5 +34,5 @@ func TestInit(t *testing.T) {
|
|||
}
|
||||
|
||||
require.True(t, found)
|
||||
require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
|
||||
require.IsType(t, &Namespace{}, ns.Context())
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func init() {
|
|||
|
||||
ns := &internal.TemplateFuncsNamespace{
|
||||
Name: name,
|
||||
Context: func() interface{} { return ctx },
|
||||
Context: func(args ...interface{}) interface{} { return ctx },
|
||||
}
|
||||
|
||||
ns.AddMethodMapping(ctx.Include,
|
||||
|
|
|
@ -34,5 +34,5 @@ func TestInit(t *testing.T) {
|
|||
}
|
||||
|
||||
require.True(t, found)
|
||||
require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
|
||||
require.IsType(t, &Namespace{}, ns.Context())
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func init() {
|
|||
|
||||
ns := &internal.TemplateFuncsNamespace{
|
||||
Name: name,
|
||||
Context: func() interface{} { return ctx },
|
||||
Context: func(args ...interface{}) interface{} { return ctx },
|
||||
}
|
||||
|
||||
ns.AddMethodMapping(ctx.CSS,
|
||||
|
|
|
@ -34,5 +34,5 @@ func TestInit(t *testing.T) {
|
|||
}
|
||||
|
||||
require.True(t, found)
|
||||
require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
|
||||
require.IsType(t, &Namespace{}, ns.Context())
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func init() {
|
|||
|
||||
ns := &internal.TemplateFuncsNamespace{
|
||||
Name: name,
|
||||
Context: func() interface{} { return ctx },
|
||||
Context: func(args ...interface{}) interface{} { return ctx },
|
||||
}
|
||||
|
||||
ns.AddMethodMapping(ctx.Chomp,
|
||||
|
|
|
@ -34,5 +34,5 @@ func TestInit(t *testing.T) {
|
|||
}
|
||||
|
||||
require.True(t, found)
|
||||
require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
|
||||
require.IsType(t, &Namespace{}, ns.Context())
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func init() {
|
|||
|
||||
ns := &internal.TemplateFuncsNamespace{
|
||||
Name: name,
|
||||
Context: func(v ...interface{}) interface{} {
|
||||
Context: func(args ...interface{}) interface{} {
|
||||
// Handle overlapping "time" namespace and func.
|
||||
//
|
||||
// If no args are passed to `time`, assume namespace usage and
|
||||
|
@ -34,11 +34,11 @@ func init() {
|
|||
//
|
||||
// If args are passed, call AsTime().
|
||||
|
||||
if len(v) == 0 {
|
||||
if len(args) == 0 {
|
||||
return ctx
|
||||
}
|
||||
|
||||
t, err := ctx.AsTime(v[0])
|
||||
t, err := ctx.AsTime(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -34,5 +34,5 @@ func TestInit(t *testing.T) {
|
|||
}
|
||||
|
||||
require.True(t, found)
|
||||
require.IsType(t, &Namespace{}, ns.Context.(func(v ...interface{}) interface{})())
|
||||
require.IsType(t, &Namespace{}, ns.Context())
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func init() {
|
|||
|
||||
ns := &internal.TemplateFuncsNamespace{
|
||||
Name: name,
|
||||
Context: func() interface{} { return ctx },
|
||||
Context: func(args ...interface{}) interface{} { return ctx },
|
||||
}
|
||||
|
||||
ns.AddMethodMapping(ctx.Emojify,
|
||||
|
|
|
@ -34,5 +34,5 @@ func TestInit(t *testing.T) {
|
|||
}
|
||||
|
||||
require.True(t, found)
|
||||
require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
|
||||
require.IsType(t, &Namespace{}, ns.Context())
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func init() {
|
|||
|
||||
ns := &internal.TemplateFuncsNamespace{
|
||||
Name: name,
|
||||
Context: func() interface{} { return ctx },
|
||||
Context: func(args ...interface{}) interface{} { return ctx },
|
||||
}
|
||||
|
||||
ns.AddMethodMapping(ctx.AbsURL,
|
||||
|
|
|
@ -34,5 +34,5 @@ func TestInit(t *testing.T) {
|
|||
}
|
||||
|
||||
require.True(t, found)
|
||||
require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
|
||||
require.IsType(t, &Namespace{}, ns.Context())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue