diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-04-30 11:34:45 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-05-01 15:13:41 +0200 |
commit | c5373efcf07aeb161324b3ce844d41a172da42bc (patch) | |
tree | 71e2616ea98ebd84f07dbb97ebaf87dc37bc62f1 /tpl/tplimpl/template_funcs.go | |
parent | 8f95172c7af334f61d75faad74cc75016804eca6 (diff) |
tpl: Add TemplateFuncsNamespaceRegistry
As a first step to remove the hard ties between `tplimpl` and the different namespace packages.
The `lang` package is used as the first example use case.
See #3042
Diffstat (limited to 'tpl/tplimpl/template_funcs.go')
-rw-r--r-- | tpl/tplimpl/template_funcs.go | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/tpl/tplimpl/template_funcs.go b/tpl/tplimpl/template_funcs.go index 8d86dfa54..b1d7d71f9 100644 --- a/tpl/tplimpl/template_funcs.go +++ b/tpl/tplimpl/template_funcs.go @@ -22,6 +22,10 @@ import ( "github.com/spf13/cast" "github.com/spf13/hugo/tpl/compare" + "github.com/spf13/hugo/tpl/internal" + + // Init the namespaces + _ "github.com/spf13/hugo/tpl/lang" ) // Get retrieves partial output from the cache based upon the partial name. @@ -181,8 +185,18 @@ func (t *templateFuncster) initFuncMap() { "upper": t.strings.ToUpper, "urlize": t.PathSpec.URLize, "where": t.collections.Where, - "i18n": t.lang.Translate, - "T": t.lang.T, + } + + // Merge the namespace funcs + for _, nsf := range internal.TemplateFuncsNamespaceRegistry { + ns := nsf(t.Deps) + // TODO(bep) namespace ns.Context is a dummy func just to make this work. + // Consider if we can add this context to the rendering context in an easy + // way to make this cleaner. Maybe. + funcMap[ns.Name] = ns.Context + for k, v := range ns.Aliases { + funcMap[k] = v + } } t.funcMap = funcMap |