diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-05-01 19:40:34 +0300 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-05-01 22:44:15 +0300 |
commit | 690b0f8ff5795318dfa3834a5a75d6623e7d934a (patch) | |
tree | 1112306f4c6fecc0966d880dec702c3804633deb /tpl/urls | |
parent | e2b067f0504ba41ef45786e2f83d7002bd13a7eb (diff) |
tpl: Add docshelper for template funcs
And fix some other minor related issues.
Updates #3418
Diffstat (limited to 'tpl/urls')
-rw-r--r-- | tpl/urls/init.go | 56 |
1 files changed, 33 insertions, 23 deletions
diff --git a/tpl/urls/init.go b/tpl/urls/init.go index fb9b00a27..e32807f32 100644 --- a/tpl/urls/init.go +++ b/tpl/urls/init.go @@ -24,33 +24,43 @@ func init() { f := func(d *deps.Deps) *internal.TemplateFuncsNamespace { ctx := New(d) - examples := [][2]string{ - {`{{ "index.html" | absLangURL }}`, `http://mysite.com/hugo/en/index.html`}, - {`{{ "http://gohugo.io/" | absURL }}`, `http://gohugo.io/`}, - {`{{ "mystyle.css" | absURL }}`, `http://mysite.com/hugo/mystyle.css`}, - {`{{ 42 | absURL }}`, `http://mysite.com/hugo/42`}, - {`{{ "index.html" | relLangURL }}`, `/hugo/en/index.html`}, - {`{{ "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{ + ns := &internal.TemplateFuncsNamespace{ Name: name, Context: func() interface{} { return ctx }, - Aliases: map[string]interface{}{ - "absURL": ctx.AbsURL, - "absLangURL": ctx.AbsLangURL, - "ref": ctx.Ref, - "relURL": ctx.RelURL, - "relLangURL": ctx.RelLangURL, - "relref": ctx.RelRef, - "urlize": ctx.URLize, - }, - Examples: examples, } + ns.AddMethodMapping(ctx.AbsURL, + []string{"absURL"}, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.AbsLangURL, + []string{"absLangURL"}, + [][2]string{}, + ) + ns.AddMethodMapping(ctx.Ref, + []string{"ref"}, + [][2]string{}, + ) + ns.AddMethodMapping(ctx.RelURL, + []string{"relURL"}, + [][2]string{}, + ) + ns.AddMethodMapping(ctx.RelLangURL, + []string{"relLangURL"}, + [][2]string{}, + ) + ns.AddMethodMapping(ctx.RelRef, + []string{"relref"}, + [][2]string{}, + ) + ns.AddMethodMapping(ctx.URLize, + []string{"urlize"}, + [][2]string{}, + ) + + return ns + } internal.AddTemplateFuncsNamespace(f) |