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-06-13 12:42:45 -04:00
|
|
|
"github.com/gohugoio/hugo/tpl/internal"
|
2017-04-30 05:34:45 -04:00
|
|
|
|
|
|
|
// Init the namespaces
|
2017-06-13 12:42:45 -04: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 14:54:22 -04:00
|
|
|
_ "github.com/gohugoio/hugo/tpl/path"
|
2017-06-13 12:42:45 -04: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 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
|
2017-05-01 12:40:34 -04: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 05:34:45 -04:00
|
|
|
}
|
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
|
|
|
}
|