shithub: hugo

Download patch

ref: 656155736721547fef45466a28295f6a563cdd1f
parent: 0ab23eb5a87efd7db96e11fb3665f0d30336217c
author: Bjørn Erik Pedersen <[email protected]>
date: Sun Apr 30 15:11:18 EDT 2017

tpl/data: Make it a package that stands on its own

See #3042

--- /dev/null
+++ b/tpl/data/init.go
@@ -1,0 +1,43 @@
+// Copyright 2017 The Hugo Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package data
+
+import (
+	"github.com/spf13/hugo/deps"
+	"github.com/spf13/hugo/tpl/internal"
+)
+
+const name = "data"
+
+func init() {
+	f := func(d *deps.Deps) *internal.TemplateFuncsNamespace {
+		ctx := New(d)
+
+		examples := [][2]string{
+			{},
+		}
+
+		return &internal.TemplateFuncsNamespace{
+			Name:    name,
+			Context: func() interface{} { return ctx },
+			Aliases: map[string]interface{}{
+				"getCSV":  ctx.GetCSV,
+				"getJSON": ctx.GetJSON,
+			},
+			Examples: examples,
+		}
+	}
+
+	internal.AddTemplateFuncsNamespace(f)
+}
--- a/tpl/tplimpl/templateFuncster.go
+++ b/tpl/tplimpl/templateFuncster.go
@@ -23,7 +23,6 @@
 	"github.com/spf13/hugo/deps"
 	"github.com/spf13/hugo/tpl/collections"
 	"github.com/spf13/hugo/tpl/crypto"
-	"github.com/spf13/hugo/tpl/data"
 	"github.com/spf13/hugo/tpl/encoding"
 	"github.com/spf13/hugo/tpl/images"
 	"github.com/spf13/hugo/tpl/inflect"
@@ -42,7 +41,6 @@
 	// Namespaces
 	collections *collections.Namespace
 	crypto      *crypto.Namespace
-	data        *data.Namespace
 	encoding    *encoding.Namespace
 	images      *images.Namespace
 	inflect     *inflect.Namespace
@@ -63,7 +61,6 @@
 		// Namespaces
 		collections: collections.New(deps),
 		crypto:      crypto.New(),
-		data:        data.New(deps),
 		encoding:    encoding.New(),
 		images:      images.New(deps),
 		inflect:     inflect.New(),
--- a/tpl/tplimpl/template_funcs.go
+++ b/tpl/tplimpl/template_funcs.go
@@ -25,6 +25,7 @@
 	"github.com/spf13/hugo/tpl/internal"
 
 	// Init the namespaces
+	_ "github.com/spf13/hugo/tpl/data"
 	_ "github.com/spf13/hugo/tpl/lang"
 	_ "github.com/spf13/hugo/tpl/math"
 	_ "github.com/spf13/hugo/tpl/strings"
@@ -107,8 +108,6 @@
 		"eq":            compare.Eq,
 		"first":         t.collections.First,
 		"ge":            compare.Ge,
-		"getCSV":        t.data.GetCSV,
-		"getJSON":       t.data.GetJSON,
 		"getenv":        t.os.Getenv,
 		"gt":            compare.Gt,
 		"highlight":     t.transform.Highlight,