diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-05-01 18:40:34 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-05-01 21:44:15 +0200 |
commit | 690b0f8ff5795318dfa3834a5a75d6623e7d934a (patch) | |
tree | 1112306f4c6fecc0966d880dec702c3804633deb /tpl/safe/init.go | |
parent | e2b067f0504ba41ef45786e2f83d7002bd13a7eb (diff) |
tpl: Add docshelper for template funcs
And fix some other minor related issues.
Updates #3418
Diffstat (limited to 'tpl/safe/init.go')
-rw-r--r-- | tpl/safe/init.go | 67 |
1 files changed, 47 insertions, 20 deletions
diff --git a/tpl/safe/init.go b/tpl/safe/init.go index fc47c66a7..94012a6ca 100644 --- a/tpl/safe/init.go +++ b/tpl/safe/init.go @@ -24,30 +24,57 @@ func init() { f := func(d *deps.Deps) *internal.TemplateFuncsNamespace { ctx := New() - examples := [][2]string{ - {`{{ "Bat&Man" | safeCSS | safeCSS }}`, `Bat&Man`}, - {`{{ "Bat&Man" | safeHTML | safeHTML }}`, `Bat&Man`}, - {`{{ "Bat&Man" | safeHTML }}`, `Bat&Man`}, - {`{{ "(1*2)" | safeJS | safeJS }}`, `(1*2)`}, - {`{{ "http://gohugo.io" | safeURL | safeURL }}`, `http://gohugo.io`}, - } - - return &internal.TemplateFuncsNamespace{ + ns := &internal.TemplateFuncsNamespace{ Name: name, Context: func() interface{} { return ctx }, - Aliases: map[string]interface{}{ - "safeCSS": ctx.CSS, - "safeHTML": ctx.HTML, - "safeHTMLAttr": ctx.HTMLAttr, - "safeJS": ctx.JS, - "safeJSStr": ctx.JSStr, - "safeURL": ctx.URL, - "sanitizeURL": ctx.SanitizeURL, - "sanitizeurl": ctx.SanitizeURL, - }, - Examples: examples, } + ns.AddMethodMapping(ctx.CSS, + []string{"safeCSS"}, + [][2]string{ + {`{{ "Bat&Man" | safeCSS | safeCSS }}`, `Bat&Man`}, + }, + ) + + ns.AddMethodMapping(ctx.HTML, + []string{"safeHTML"}, + [][2]string{ + {`{{ "Bat&Man" | safeHTML | safeHTML }}`, `Bat&Man`}, + {`{{ "Bat&Man" | safeHTML }}`, `Bat&Man`}, + }, + ) + + ns.AddMethodMapping(ctx.HTMLAttr, + []string{"safeHTMLAttr"}, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.JS, + []string{"safeJS"}, + [][2]string{ + {`{{ "(1*2)" | safeJS | safeJS }}`, `(1*2)`}, + }, + ) + + ns.AddMethodMapping(ctx.JSStr, + []string{"safeJSStr"}, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.URL, + []string{"safeURL"}, + [][2]string{ + {`{{ "http://gohugo.io" | safeURL | safeURL }}`, `http://gohugo.io`}, + }, + ) + + ns.AddMethodMapping(ctx.SanitizeURL, + []string{"sanitizeURL", "sanitizeurl"}, + [][2]string{}, + ) + + return ns + } internal.AddTemplateFuncsNamespace(f) |