summaryrefslogtreecommitdiffstats
path: root/tpl/transform
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-05-01 18:40:34 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-05-01 21:44:15 +0200
commit690b0f8ff5795318dfa3834a5a75d6623e7d934a (patch)
tree1112306f4c6fecc0966d880dec702c3804633deb /tpl/transform
parente2b067f0504ba41ef45786e2f83d7002bd13a7eb (diff)
tpl: Add docshelper for template funcs
And fix some other minor related issues. Updates #3418
Diffstat (limited to 'tpl/transform')
-rw-r--r--tpl/transform/init.go99
1 files changed, 62 insertions, 37 deletions
diff --git a/tpl/transform/init.go b/tpl/transform/init.go
index 98994c0e6..3483d1306 100644
--- a/tpl/transform/init.go
+++ b/tpl/transform/init.go
@@ -24,47 +24,72 @@ func init() {
f := func(d *deps.Deps) *internal.TemplateFuncsNamespace {
ctx := New(d)
- examples := [][2]string{
- {`{{ "I :heart: Hugo" | emojify }}`, `I ❤️ Hugo`},
- {`{{ .Title | markdownify}}`, `<strong>BatMan</strong>`},
- {`{{ plainify "Hello <strong>world</strong>, gophers!" }}`, `Hello world, gophers!`},
- {
- `htmlEscape 1: {{ htmlEscape "Cathal Garvey & The Sunshine Band <cathal@foo.bar>" | safeHTML}}`,
- `htmlEscape 1: Cathal Garvey &amp; The Sunshine Band &lt;cathal@foo.bar&gt;`},
- {
- `htmlEscape 2: {{ htmlEscape "Cathal Garvey & The Sunshine Band <cathal@foo.bar>"}}`,
- `htmlEscape 2: Cathal Garvey &amp;amp; The Sunshine Band &amp;lt;cathal@foo.bar&amp;gt;`},
- {
- `htmlUnescape 1: {{htmlUnescape "Cathal Garvey &amp; The Sunshine Band &lt;cathal@foo.bar&gt;" | safeHTML}}`,
- `htmlUnescape 1: Cathal Garvey & The Sunshine Band <cathal@foo.bar>`},
- {
- `htmlUnescape 2: {{"Cathal Garvey &amp;amp; The Sunshine Band &amp;lt;cathal@foo.bar&amp;gt;" | htmlUnescape | htmlUnescape | safeHTML}}`,
- `htmlUnescape 2: Cathal Garvey & The Sunshine Band <cathal@foo.bar>`},
- {
- `htmlUnescape 3: {{"Cathal Garvey &amp;amp; The Sunshine Band &amp;lt;cathal@foo.bar&amp;gt;" | htmlUnescape | htmlUnescape }}`,
- `htmlUnescape 3: Cathal Garvey &amp; The Sunshine Band &lt;cathal@foo.bar&gt;`},
- {
- `htmlUnescape 4: {{ htmlEscape "Cathal Garvey & The Sunshine Band <cathal@foo.bar>" | htmlUnescape | safeHTML }}`,
- `htmlUnescape 4: Cathal Garvey & The Sunshine Band <cathal@foo.bar>`},
- {
- `htmlUnescape 5: {{ htmlUnescape "Cathal Garvey &amp; The Sunshine Band &lt;cathal@foo.bar&gt;" | htmlEscape | safeHTML }}`,
- `htmlUnescape 5: Cathal Garvey &amp; The Sunshine Band &lt;cathal@foo.bar&gt;`},
- }
-
- return &internal.TemplateFuncsNamespace{
+ ns := &internal.TemplateFuncsNamespace{
Name: name,
Context: func() interface{} { return ctx },
- Aliases: map[string]interface{}{
- "emojify": ctx.Emojify,
- "highlight": ctx.Highlight,
- "htmlEscape": ctx.HTMLEscape,
- "htmlUnescape": ctx.HTMLUnescape,
- "markdownify": ctx.Markdownify,
- "plainify": ctx.Plainify,
- },
- Examples: examples,
}
+ ns.AddMethodMapping(ctx.Emojify,
+ []string{"emojify"},
+ [][2]string{
+ {`{{ "I :heart: Hugo" | emojify }}`, `I ❤️ Hugo`},
+ },
+ )
+
+ ns.AddMethodMapping(ctx.Highlight,
+ []string{"highlight"},
+ [][2]string{},
+ )
+
+ ns.AddMethodMapping(ctx.HTMLEscape,
+ []string{"htmlEscape"},
+ [][2]string{
+ {
+ `{{ htmlEscape "Cathal Garvey & The Sunshine Band <cathal@foo.bar>" | safeHTML}}`,
+ `Cathal Garvey &amp; The Sunshine Band &lt;cathal@foo.bar&gt;`},
+ {
+ `{{ htmlEscape "Cathal Garvey & The Sunshine Band <cathal@foo.bar>"}}`,
+ `Cathal Garvey &amp;amp; The Sunshine Band &amp;lt;cathal@foo.bar&amp;gt;`},
+ {
+ `{{ htmlEscape "Cathal Garvey & The Sunshine Band <cathal@foo.bar>" | htmlUnescape | safeHTML }}`,
+ `Cathal Garvey & The Sunshine Band <cathal@foo.bar>`},
+ },
+ )
+
+ ns.AddMethodMapping(ctx.HTMLUnescape,
+ []string{"htmlUnescape"},
+ [][2]string{
+ {
+ `{{ htmlUnescape "Cathal Garvey &amp; The Sunshine Band &lt;cathal@foo.bar&gt;" | safeHTML}}`,
+ `Cathal Garvey & The Sunshine Band <cathal@foo.bar>`},
+ {
+ `{{"Cathal Garvey &amp;amp; The Sunshine Band &amp;lt;cathal@foo.bar&amp;gt;" | htmlUnescape | htmlUnescape | safeHTML}}`,
+ `Cathal Garvey & The Sunshine Band <cathal@foo.bar>`},
+ {
+ `{{"Cathal Garvey &amp;amp; The Sunshine Band &amp;lt;cathal@foo.bar&amp;gt;" | htmlUnescape | htmlUnescape }}`,
+ `Cathal Garvey &amp; The Sunshine Band &lt;cathal@foo.bar&gt;`},
+ {
+ `{{ htmlUnescape "Cathal Garvey &amp; The Sunshine Band &lt;cathal@foo.bar&gt;" | htmlEscape | safeHTML }}`,
+ `Cathal Garvey &amp; The Sunshine Band &lt;cathal@foo.bar&gt;`},
+ },
+ )
+
+ ns.AddMethodMapping(ctx.Markdownify,
+ []string{"markdownify"},
+ [][2]string{
+ {`{{ .Title | markdownify}}`, `<strong>BatMan</strong>`},
+ },
+ )
+
+ ns.AddMethodMapping(ctx.Plainify,
+ []string{"plainify"},
+ [][2]string{
+ {`{{ plainify "Hello <strong>world</strong>, gophers!" }}`, `Hello world, gophers!`},
+ },
+ )
+
+ return ns
+
}
internal.AddTemplateFuncsNamespace(f)