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:
Bjørn Erik Pedersen 2017-05-20 11:28:33 +03:00
parent ebd636e4d5
commit 1f9e8dcc60
37 changed files with 40 additions and 40 deletions

View file

@ -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,

View file

@ -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())
}

View file

@ -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,

View file

@ -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())
}

View file

@ -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,

View file

@ -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())
}

View file

@ -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,

View file

@ -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())
}

View file

@ -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,

View file

@ -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())
}

View file

@ -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,

View file

@ -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())
}

View file

@ -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,

View file

@ -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())
}

View file

@ -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,

View file

@ -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())
}

View file

@ -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,

View file

@ -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())
}

View file

@ -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)

View file

@ -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,

View file

@ -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())
}

View file

@ -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,

View file

@ -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())
}

View file

@ -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,

View file

@ -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())
}

View file

@ -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,

View file

@ -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())
}

View file

@ -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,

View file

@ -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())
}

View file

@ -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,

View file

@ -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())
}

View file

@ -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
}

View file

@ -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())
}

View file

@ -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,

View file

@ -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())
}

View file

@ -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,

View file

@ -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())
}