diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-05-01 10:06:42 +0300 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-05-01 16:13:41 +0300 |
commit | 0e2260421e40c97d9d210724fb44cfdc15ea7855 (patch) | |
tree | 13a73d06a67b42584fcd20c08615418e0ec2fe1f /tpl/urls | |
parent | 4714085a10835b9f4e8d4f699dc94e3120d8067e (diff) |
tpl: Fix the remaining template funcs namespace issues
See #3042
Diffstat (limited to 'tpl/urls')
-rw-r--r-- | tpl/urls/init.go | 2 | ||||
-rw-r--r-- | tpl/urls/urls.go | 13 |
2 files changed, 10 insertions, 5 deletions
diff --git a/tpl/urls/init.go b/tpl/urls/init.go index a687704af..fb9b00a27 100644 --- a/tpl/urls/init.go +++ b/tpl/urls/init.go @@ -33,6 +33,7 @@ func init() { {`{{ "http://gohugo.io/" | relURL }}`, `http://gohugo.io/`}, {`{{ "mystyle.css" | relURL }}`, `/hugo/mystyle.css`}, {`{{ mul 2 21 | relURL }}`, `/hugo/42`}, + {`{{ "Bat Man" | urlize }}`, `bat-man`}, } return &internal.TemplateFuncsNamespace{ @@ -45,6 +46,7 @@ func init() { "relURL": ctx.RelURL, "relLangURL": ctx.RelLangURL, "relref": ctx.RelRef, + "urlize": ctx.URLize, }, Examples: examples, } diff --git a/tpl/urls/urls.go b/tpl/urls/urls.go index 04ad1cb4d..5d1077785 100644 --- a/tpl/urls/urls.go +++ b/tpl/urls/urls.go @@ -33,11 +33,6 @@ type Namespace struct { deps *deps.Deps } -// Namespace returns a pointer to the current namespace instance. -func (ns *Namespace) Namespace() *Namespace { - return ns -} - // AbsURL takes a given string and converts it to an absolute URL. func (ns *Namespace) AbsURL(a interface{}) (template.HTML, error) { s, err := cast.ToStringE(a) @@ -59,6 +54,14 @@ func (ns *Namespace) RelURL(a interface{}) (template.HTML, error) { return template.HTML(ns.deps.PathSpec.RelURL(s, false)), nil } +func (ns *Namespace) URLize(a interface{}) (template.URL, error) { + s, err := cast.ToStringE(a) + if err != nil { + return "", nil + } + return template.URL(ns.deps.PathSpec.URLize(s)), nil +} + type reflinker interface { Ref(refs ...string) (string, error) RelRef(refs ...string) (string, error) |