2017-05-01 03:06:42 -04:00
|
|
|
// Copyright 2017-present The Hugo Authors. All rights reserved.
|
2015-04-05 15:03:16 -04:00
|
|
|
//
|
2016-03-10 14:59:41 -05:00
|
|
|
// Portions Copyright The Go Authors.
|
|
|
|
|
2015-11-23 22:16:36 -05:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
2015-04-05 15:03:16 -04:00
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
2015-11-23 22:16:36 -05:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2015-04-05 15:03:16 -04:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2017-02-17 07:30:50 -05:00
|
|
|
package tplimpl
|
2015-04-05 15:03:16 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"html/template"
|
2015-05-26 06:33:32 -04:00
|
|
|
|
2017-04-30 05:34:45 -04:00
|
|
|
"github.com/spf13/hugo/tpl/internal"
|
|
|
|
|
|
|
|
// Init the namespaces
|
2017-05-01 03:06:42 -04:00
|
|
|
_ "github.com/spf13/hugo/tpl/cast"
|
2017-04-30 15:52:56 -04:00
|
|
|
_ "github.com/spf13/hugo/tpl/collections"
|
2017-04-30 13:33:19 -04:00
|
|
|
_ "github.com/spf13/hugo/tpl/compare"
|
2017-04-30 16:19:49 -04:00
|
|
|
_ "github.com/spf13/hugo/tpl/crypto"
|
2017-04-30 13:11:18 -04:00
|
|
|
_ "github.com/spf13/hugo/tpl/data"
|
2017-04-30 16:32:40 -04:00
|
|
|
_ "github.com/spf13/hugo/tpl/encoding"
|
2017-05-01 03:06:42 -04:00
|
|
|
_ "github.com/spf13/hugo/tpl/fmt"
|
2017-04-30 16:36:26 -04:00
|
|
|
_ "github.com/spf13/hugo/tpl/images"
|
2017-04-30 16:43:26 -04:00
|
|
|
_ "github.com/spf13/hugo/tpl/inflect"
|
2017-04-30 05:34:45 -04:00
|
|
|
_ "github.com/spf13/hugo/tpl/lang"
|
2017-04-30 11:45:56 -04:00
|
|
|
_ "github.com/spf13/hugo/tpl/math"
|
2017-04-30 16:52:47 -04:00
|
|
|
_ "github.com/spf13/hugo/tpl/os"
|
2017-05-01 03:06:42 -04:00
|
|
|
_ "github.com/spf13/hugo/tpl/partials"
|
2017-04-30 17:06:28 -04:00
|
|
|
_ "github.com/spf13/hugo/tpl/safe"
|
2017-04-30 12:41:13 -04:00
|
|
|
_ "github.com/spf13/hugo/tpl/strings"
|
2017-04-30 17:10:46 -04:00
|
|
|
_ "github.com/spf13/hugo/tpl/time"
|
2017-04-30 17:16:54 -04:00
|
|
|
_ "github.com/spf13/hugo/tpl/transform"
|
2017-04-30 17:33:14 -04:00
|
|
|
_ "github.com/spf13/hugo/tpl/urls"
|
2017-03-13 18:55:02 -04:00
|
|
|
)
|
2016-10-10 18:03:30 -04:00
|
|
|
|
2017-01-10 04:55:03 -05:00
|
|
|
func (t *templateFuncster) initFuncMap() {
|
2017-05-01 03:06:42 -04:00
|
|
|
funcMap := template.FuncMap{}
|
2017-04-30 05:34:45 -04:00
|
|
|
|
|
|
|
// Merge the namespace funcs
|
|
|
|
for _, nsf := range internal.TemplateFuncsNamespaceRegistry {
|
|
|
|
ns := nsf(t.Deps)
|
2017-05-01 03:06:42 -04:00
|
|
|
if _, exists := funcMap[ns.Name]; exists {
|
|
|
|
panic(ns.Name + " is a duplicate template func")
|
|
|
|
}
|
2017-04-30 05:34:45 -04:00
|
|
|
funcMap[ns.Name] = ns.Context
|
|
|
|
for k, v := range ns.Aliases {
|
|
|
|
funcMap[k] = v
|
|
|
|
}
|
2015-04-05 15:03:16 -04:00
|
|
|
}
|
2017-01-09 19:36:59 -05:00
|
|
|
|
2017-01-10 04:55:03 -05:00
|
|
|
t.funcMap = funcMap
|
2017-04-15 05:33:53 -04:00
|
|
|
t.Tmpl.(*templateHandler).setFuncs(funcMap)
|
2015-04-05 15:03:16 -04:00
|
|
|
}
|