mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
parent
0ab23eb5a8
commit
6561557367
3 changed files with 44 additions and 5 deletions
43
tpl/data/init.go
Normal file
43
tpl/data/init.go
Normal file
|
@ -0,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)
|
||||||
|
}
|
|
@ -23,7 +23,6 @@ import (
|
||||||
"github.com/spf13/hugo/deps"
|
"github.com/spf13/hugo/deps"
|
||||||
"github.com/spf13/hugo/tpl/collections"
|
"github.com/spf13/hugo/tpl/collections"
|
||||||
"github.com/spf13/hugo/tpl/crypto"
|
"github.com/spf13/hugo/tpl/crypto"
|
||||||
"github.com/spf13/hugo/tpl/data"
|
|
||||||
"github.com/spf13/hugo/tpl/encoding"
|
"github.com/spf13/hugo/tpl/encoding"
|
||||||
"github.com/spf13/hugo/tpl/images"
|
"github.com/spf13/hugo/tpl/images"
|
||||||
"github.com/spf13/hugo/tpl/inflect"
|
"github.com/spf13/hugo/tpl/inflect"
|
||||||
|
@ -42,7 +41,6 @@ type templateFuncster struct {
|
||||||
// Namespaces
|
// Namespaces
|
||||||
collections *collections.Namespace
|
collections *collections.Namespace
|
||||||
crypto *crypto.Namespace
|
crypto *crypto.Namespace
|
||||||
data *data.Namespace
|
|
||||||
encoding *encoding.Namespace
|
encoding *encoding.Namespace
|
||||||
images *images.Namespace
|
images *images.Namespace
|
||||||
inflect *inflect.Namespace
|
inflect *inflect.Namespace
|
||||||
|
@ -63,7 +61,6 @@ func newTemplateFuncster(deps *deps.Deps) *templateFuncster {
|
||||||
// Namespaces
|
// Namespaces
|
||||||
collections: collections.New(deps),
|
collections: collections.New(deps),
|
||||||
crypto: crypto.New(),
|
crypto: crypto.New(),
|
||||||
data: data.New(deps),
|
|
||||||
encoding: encoding.New(),
|
encoding: encoding.New(),
|
||||||
images: images.New(deps),
|
images: images.New(deps),
|
||||||
inflect: inflect.New(),
|
inflect: inflect.New(),
|
||||||
|
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"github.com/spf13/hugo/tpl/internal"
|
"github.com/spf13/hugo/tpl/internal"
|
||||||
|
|
||||||
// Init the namespaces
|
// Init the namespaces
|
||||||
|
_ "github.com/spf13/hugo/tpl/data"
|
||||||
_ "github.com/spf13/hugo/tpl/lang"
|
_ "github.com/spf13/hugo/tpl/lang"
|
||||||
_ "github.com/spf13/hugo/tpl/math"
|
_ "github.com/spf13/hugo/tpl/math"
|
||||||
_ "github.com/spf13/hugo/tpl/strings"
|
_ "github.com/spf13/hugo/tpl/strings"
|
||||||
|
@ -107,8 +108,6 @@ func (t *templateFuncster) initFuncMap() {
|
||||||
"eq": compare.Eq,
|
"eq": compare.Eq,
|
||||||
"first": t.collections.First,
|
"first": t.collections.First,
|
||||||
"ge": compare.Ge,
|
"ge": compare.Ge,
|
||||||
"getCSV": t.data.GetCSV,
|
|
||||||
"getJSON": t.data.GetJSON,
|
|
||||||
"getenv": t.os.Getenv,
|
"getenv": t.os.Getenv,
|
||||||
"gt": compare.Gt,
|
"gt": compare.Gt,
|
||||||
"highlight": t.transform.Highlight,
|
"highlight": t.transform.Highlight,
|
||||||
|
|
Loading…
Reference in a new issue