This makes it cleaner and avoids breaking client code, such as the docs helper JSON generator.
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.ToInt,
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.After,
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.Default,
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.MD5,
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.GetCSV,
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.Base64Decode,
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.Print,
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.Config,
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.Humanize,
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
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
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)
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.Translate,
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.Add,
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.Getenv,
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.Include,
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.CSS,
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.Chomp,
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
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
//
// 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
}
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func(v ...interface{}) interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.Emojify,
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}
ns := &internal.TemplateFuncsNamespace{
Name: name,
- Context: func() interface{} { return ctx },
+ Context: func(args ...interface{}) interface{} { return ctx },
}
ns.AddMethodMapping(ctx.AbsURL,
}
require.True(t, found)
- require.IsType(t, &Namespace{}, ns.Context.(func() interface{})())
+ require.IsType(t, &Namespace{}, ns.Context())
}