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