ref: 1f9e8dcc6010abeea8abc7ba1a092c4dab9852f6
parent: ebd636e4d5f475d4b5d9047580e61ff7c2bf2fb5
author: Bjørn Erik Pedersen <[email protected]>
date: Sat May 20 07:28:33 EDT 2017
tpl: Make the Namespace func signature explicit This makes it cleaner and avoids breaking client code, such as the docs helper JSON generator.
--- a/tpl/cast/init.go
+++ b/tpl/cast/init.go
@@ -26,7 +26,7 @@
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.ToInt,
--- a/tpl/cast/init_test.go
+++ b/tpl/cast/init_test.go
@@ -34,5 +34,5 @@
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
--- a/tpl/collections/init.go
+++ b/tpl/collections/init.go
@@ -26,7 +26,7 @@
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.After,
--- a/tpl/collections/init_test.go
+++ b/tpl/collections/init_test.go
@@ -34,5 +34,5 @@
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
--- a/tpl/compare/init.go
+++ b/tpl/compare/init.go
@@ -26,7 +26,7 @@
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.Default,
--- a/tpl/compare/init_test.go
+++ b/tpl/compare/init_test.go
@@ -34,5 +34,5 @@
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
--- a/tpl/crypto/init.go
+++ b/tpl/crypto/init.go
@@ -26,7 +26,7 @@
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.MD5,
--- a/tpl/crypto/init_test.go
+++ b/tpl/crypto/init_test.go
@@ -34,5 +34,5 @@
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
--- a/tpl/data/init.go
+++ b/tpl/data/init.go
@@ -26,7 +26,7 @@
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.GetCSV,
--- a/tpl/data/init_test.go
+++ b/tpl/data/init_test.go
@@ -34,5 +34,5 @@
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
--- a/tpl/encoding/init.go
+++ b/tpl/encoding/init.go
@@ -26,7 +26,7 @@
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.Base64Decode,
--- a/tpl/encoding/init_test.go
+++ b/tpl/encoding/init_test.go
@@ -34,5 +34,5 @@
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
--- a/tpl/fmt/init.go
+++ b/tpl/fmt/init.go
@@ -26,7 +26,7 @@
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.Print,
--- a/tpl/fmt/init_test.go
+++ b/tpl/fmt/init_test.go
@@ -34,5 +34,5 @@
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
--- a/tpl/images/init.go
+++ b/tpl/images/init.go
@@ -26,7 +26,7 @@
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.Config,
--- a/tpl/images/init_test.go
+++ b/tpl/images/init_test.go
@@ -34,5 +34,5 @@
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
--- a/tpl/inflect/init.go
+++ b/tpl/inflect/init.go
@@ -26,7 +26,7 @@
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.Humanize,
--- a/tpl/inflect/init_test.go
+++ b/tpl/inflect/init_test.go
@@ -34,5 +34,5 @@
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
--- a/tpl/internal/templatefuncsRegistry.go
+++ b/tpl/internal/templatefuncsRegistry.go
@@ -45,7 +45,7 @@
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 @@
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)
--- a/tpl/lang/init.go
+++ b/tpl/lang/init.go
@@ -26,7 +26,7 @@
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.Translate,
--- a/tpl/lang/init_test.go
+++ b/tpl/lang/init_test.go
@@ -34,5 +34,5 @@
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
--- a/tpl/math/init.go
+++ b/tpl/math/init.go
@@ -26,7 +26,7 @@
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.Add,
--- a/tpl/math/init_test.go
+++ b/tpl/math/init_test.go
@@ -34,5 +34,5 @@
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
--- a/tpl/os/init.go
+++ b/tpl/os/init.go
@@ -26,7 +26,7 @@
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.Getenv,
--- a/tpl/os/init_test.go
+++ b/tpl/os/init_test.go
@@ -34,5 +34,5 @@
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
--- a/tpl/partials/init.go
+++ b/tpl/partials/init.go
@@ -26,7 +26,7 @@
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.Include,
--- a/tpl/partials/init_test.go
+++ b/tpl/partials/init_test.go
@@ -34,5 +34,5 @@
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
--- a/tpl/safe/init.go
+++ b/tpl/safe/init.go
@@ -26,7 +26,7 @@
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.CSS,
--- a/tpl/safe/init_test.go
+++ b/tpl/safe/init_test.go
@@ -34,5 +34,5 @@
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
--- a/tpl/strings/init.go
+++ b/tpl/strings/init.go
@@ -26,7 +26,7 @@
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.Chomp,
--- a/tpl/strings/init_test.go
+++ b/tpl/strings/init_test.go
@@ -34,5 +34,5 @@
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
--- a/tpl/time/init.go
+++ b/tpl/time/init.go
@@ -26,7 +26,7 @@
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 @@
//
// 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
}
--- a/tpl/time/init_test.go
+++ b/tpl/time/init_test.go
@@ -34,5 +34,5 @@
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func(v ...interface{}) interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
--- a/tpl/transform/init.go
+++ b/tpl/transform/init.go
@@ -26,7 +26,7 @@
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.Emojify,
--- a/tpl/transform/init_test.go
+++ b/tpl/transform/init_test.go
@@ -34,5 +34,5 @@
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
--- a/tpl/urls/init.go
+++ b/tpl/urls/init.go
@@ -26,7 +26,7 @@
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.AbsURL,
--- a/tpl/urls/init_test.go
+++ b/tpl/urls/init_test.go
@@ -34,5 +34,5 @@
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}