Skip to content

Commit

Permalink
tpl/data: Make it a package that stands on its own
Browse files Browse the repository at this point in the history
See #3042
  • Loading branch information
bep committed May 1, 2017
1 parent 0ab23eb commit 6561557
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
43 changes: 43 additions & 0 deletions tpl/data/init.go
Original file line number Diff line number Diff line change
@@ -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)
}
3 changes: 0 additions & 3 deletions tpl/tplimpl/templateFuncster.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"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"
Expand All @@ -42,7 +41,6 @@ type templateFuncster struct {
// Namespaces
collections *collections.Namespace
crypto *crypto.Namespace
data *data.Namespace
encoding *encoding.Namespace
images *images.Namespace
inflect *inflect.Namespace
Expand All @@ -63,7 +61,6 @@ func newTemplateFuncster(deps *deps.Deps) *templateFuncster {
// Namespaces
collections: collections.New(deps),
crypto: crypto.New(),
data: data.New(deps),
encoding: encoding.New(),
images: images.New(deps),
inflect: inflect.New(),
Expand Down
3 changes: 1 addition & 2 deletions tpl/tplimpl/template_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"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"
Expand Down Expand Up @@ -107,8 +108,6 @@ func (t *templateFuncster) initFuncMap() {
"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,
Expand Down

0 comments on commit 6561557

Please sign in to comment.