hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit 1f9e8dcc6010abeea8abc7ba1a092c4dab9852f6
parent ebd636e4d5f475d4b5d9047580e61ff7c2bf2fb5
Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date:   Sat, 20 May 2017 11:28:33 +0300

tpl: Make the Namespace func signature explicit

This makes it cleaner and avoids breaking client code, such as the docs helper JSON generator.

Diffstat:
Mtpl/cast/init.go | 2+-
Mtpl/cast/init_test.go | 2+-
Mtpl/collections/init.go | 2+-
Mtpl/collections/init_test.go | 2+-
Mtpl/compare/init.go | 2+-
Mtpl/compare/init_test.go | 2+-
Mtpl/crypto/init.go | 2+-
Mtpl/crypto/init_test.go | 2+-
Mtpl/data/init.go | 2+-
Mtpl/data/init_test.go | 2+-
Mtpl/encoding/init.go | 2+-
Mtpl/encoding/init_test.go | 2+-
Mtpl/fmt/init.go | 2+-
Mtpl/fmt/init_test.go | 2+-
Mtpl/images/init.go | 2+-
Mtpl/images/init_test.go | 2+-
Mtpl/inflect/init.go | 2+-
Mtpl/inflect/init_test.go | 2+-
Mtpl/internal/templatefuncsRegistry.go | 4++--
Mtpl/lang/init.go | 2+-
Mtpl/lang/init_test.go | 2+-
Mtpl/math/init.go | 2+-
Mtpl/math/init_test.go | 2+-
Mtpl/os/init.go | 2+-
Mtpl/os/init_test.go | 2+-
Mtpl/partials/init.go | 2+-
Mtpl/partials/init_test.go | 2+-
Mtpl/safe/init.go | 2+-
Mtpl/safe/init_test.go | 2+-
Mtpl/strings/init.go | 2+-
Mtpl/strings/init_test.go | 2+-
Mtpl/time/init.go | 6+++---
Mtpl/time/init_test.go | 2+-
Mtpl/transform/init.go | 2+-
Mtpl/transform/init_test.go | 2+-
Mtpl/urls/init.go | 2+-
Mtpl/urls/init_test.go | 2+-
37 files changed, 40 insertions(+), 40 deletions(-)
diff --git a/tpl/cast/init.go b/tpl/cast/init.go
@@ -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,
diff --git a/tpl/cast/init_test.go b/tpl/cast/init_test.go
@@ -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())
 }
diff --git a/tpl/collections/init.go b/tpl/collections/init.go
@@ -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,
diff --git a/tpl/collections/init_test.go b/tpl/collections/init_test.go
@@ -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())
 }
diff --git a/tpl/compare/init.go b/tpl/compare/init.go
@@ -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,
diff --git a/tpl/compare/init_test.go b/tpl/compare/init_test.go
@@ -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())
 }
diff --git a/tpl/crypto/init.go b/tpl/crypto/init.go
@@ -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,
diff --git a/tpl/crypto/init_test.go b/tpl/crypto/init_test.go
@@ -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())
 }
diff --git a/tpl/data/init.go b/tpl/data/init.go
@@ -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,
diff --git a/tpl/data/init_test.go b/tpl/data/init_test.go
@@ -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())
 }
diff --git a/tpl/encoding/init.go b/tpl/encoding/init.go
@@ -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,
diff --git a/tpl/encoding/init_test.go b/tpl/encoding/init_test.go
@@ -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())
 }
diff --git a/tpl/fmt/init.go b/tpl/fmt/init.go
@@ -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,
diff --git a/tpl/fmt/init_test.go b/tpl/fmt/init_test.go
@@ -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())
 }
diff --git a/tpl/images/init.go b/tpl/images/init.go
@@ -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,
diff --git a/tpl/images/init_test.go b/tpl/images/init_test.go
@@ -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())
 }
diff --git a/tpl/inflect/init.go b/tpl/inflect/init.go
@@ -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,
diff --git a/tpl/inflect/init_test.go b/tpl/inflect/init_test.go
@@ -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())
 }
diff --git a/tpl/internal/templatefuncsRegistry.go b/tpl/internal/templatefuncsRegistry.go
@@ -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)
diff --git a/tpl/lang/init.go b/tpl/lang/init.go
@@ -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,
diff --git a/tpl/lang/init_test.go b/tpl/lang/init_test.go
@@ -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())
 }
diff --git a/tpl/math/init.go b/tpl/math/init.go
@@ -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,
diff --git a/tpl/math/init_test.go b/tpl/math/init_test.go
@@ -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())
 }
diff --git a/tpl/os/init.go b/tpl/os/init.go
@@ -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,
diff --git a/tpl/os/init_test.go b/tpl/os/init_test.go
@@ -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())
 }
diff --git a/tpl/partials/init.go b/tpl/partials/init.go
@@ -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,
diff --git a/tpl/partials/init_test.go b/tpl/partials/init_test.go
@@ -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())
 }
diff --git a/tpl/safe/init.go b/tpl/safe/init.go
@@ -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,
diff --git a/tpl/safe/init_test.go b/tpl/safe/init_test.go
@@ -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())
 }
diff --git a/tpl/strings/init.go b/tpl/strings/init.go
@@ -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,
diff --git a/tpl/strings/init_test.go b/tpl/strings/init_test.go
@@ -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())
 }
diff --git a/tpl/time/init.go b/tpl/time/init.go
@@ -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
 				}
diff --git a/tpl/time/init_test.go b/tpl/time/init_test.go
@@ -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())
 }
diff --git a/tpl/transform/init.go b/tpl/transform/init.go
@@ -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,
diff --git a/tpl/transform/init_test.go b/tpl/transform/init_test.go
@@ -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())
 }
diff --git a/tpl/urls/init.go b/tpl/urls/init.go
@@ -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,
diff --git a/tpl/urls/init_test.go b/tpl/urls/init_test.go
@@ -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())
 }