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-04-30 09:34:45 +00:00
|
|
|
"github.com/spf13/hugo/tpl/internal"
|
|
|
|
|
|
|
|
// Init the namespaces
|
2017-05-01 07:06:42 +00:00
|
|
|
_ "github.com/spf13/hugo/tpl/cast"
|
2017-04-30 19:52:56 +00:00
|
|
|
_ "github.com/spf13/hugo/tpl/collections"
|
2017-04-30 17:33:19 +00:00
|
|
|
_ "github.com/spf13/hugo/tpl/compare"
|
2017-04-30 20:19:49 +00:00
|
|
|
_ "github.com/spf13/hugo/tpl/crypto"
|
2017-04-30 17:11:18 +00:00
|
|
|
_ "github.com/spf13/hugo/tpl/data"
|
2017-04-30 20:32:40 +00:00
|
|
|
_ "github.com/spf13/hugo/tpl/encoding"
|
2017-05-01 07:06:42 +00:00
|
|
|
_ "github.com/spf13/hugo/tpl/fmt"
|
2017-04-30 20:36:26 +00:00
|
|
|
_ "github.com/spf13/hugo/tpl/images"
|
2017-04-30 20:43:26 +00:00
|
|
|
_ "github.com/spf13/hugo/tpl/inflect"
|
2017-04-30 09:34:45 +00:00
|
|
|
_ "github.com/spf13/hugo/tpl/lang"
|
2017-04-30 15:45:56 +00:00
|
|
|
_ "github.com/spf13/hugo/tpl/math"
|
2017-04-30 20:52:47 +00:00
|
|
|
_ "github.com/spf13/hugo/tpl/os"
|
2017-05-01 07:06:42 +00:00
|
|
|
_ "github.com/spf13/hugo/tpl/partials"
|
2017-04-30 21:06:28 +00:00
|
|
|
_ "github.com/spf13/hugo/tpl/safe"
|
2017-04-30 16:41:13 +00:00
|
|
|
_ "github.com/spf13/hugo/tpl/strings"
|
2017-04-30 21:10:46 +00:00
|
|
|
_ "github.com/spf13/hugo/tpl/time"
|
2017-04-30 21:16:54 +00:00
|
|
|
_ "github.com/spf13/hugo/tpl/transform"
|
2017-04-30 21:33:14 +00:00
|
|
|
_ "github.com/spf13/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
|
|
|
}
|