aboutsummaryrefslogtreecommitdiffhomepage
path: root/tpl/math
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2017-05-01 18:40:34 +0200
committerBjørn Erik Pedersen <[email protected]>2017-05-01 21:44:15 +0200
commit690b0f8ff5795318dfa3834a5a75d6623e7d934a (patch)
tree1112306f4c6fecc0966d880dec702c3804633deb /tpl/math
parente2b067f0504ba41ef45786e2f83d7002bd13a7eb (diff)
downloadhugo-690b0f8ff5795318dfa3834a5a75d6623e7d934a.tar.gz
hugo-690b0f8ff5795318dfa3834a5a75d6623e7d934a.zip
tpl: Add docshelper for template funcs
And fix some other minor related issues. Updates #3418
Diffstat (limited to 'tpl/math')
-rw-r--r--tpl/math/init.go64
1 files changed, 45 insertions, 19 deletions
diff --git a/tpl/math/init.go b/tpl/math/init.go
index 69ba2cc17..65b22c516 100644
--- a/tpl/math/init.go
+++ b/tpl/math/init.go
@@ -24,29 +24,55 @@ func init() {
f := func(d *deps.Deps) *internal.TemplateFuncsNamespace {
ctx := New()
- examples := [][2]string{
- {"{{add 1 2}}", "3"},
- {"{{div 6 3}}", "2"},
- {"{{mod 15 3}}", "0"},
- {"{{modBool 15 3}}", "true"},
- {"{{mul 2 3}}", "6"},
- {"{{sub 3 2}}", "1"},
- }
-
- return &internal.TemplateFuncsNamespace{
+ ns := &internal.TemplateFuncsNamespace{
Name: name,
Context: func() interface{} { return ctx },
- Aliases: map[string]interface{}{
- "add": ctx.Add,
- "div": ctx.Div,
- "mod": ctx.Mod,
- "modBool": ctx.ModBool,
- "mul": ctx.Mul,
- "sub": ctx.Sub,
- },
- Examples: examples,
}
+ ns.AddMethodMapping(ctx.Add,
+ []string{"add"},
+ [][2]string{
+ {"{{add 1 2}}", "3"},
+ },
+ )
+
+ ns.AddMethodMapping(ctx.Div,
+ []string{"div"},
+ [][2]string{
+ {"{{div 6 3}}", "2"},
+ },
+ )
+
+ ns.AddMethodMapping(ctx.Mod,
+ []string{"mod"},
+ [][2]string{
+ {"{{mod 15 3}}", "0"},
+ },
+ )
+
+ ns.AddMethodMapping(ctx.ModBool,
+ []string{"modBool"},
+ [][2]string{
+ {"{{modBool 15 3}}", "true"},
+ },
+ )
+
+ ns.AddMethodMapping(ctx.Mul,
+ []string{"mul"},
+ [][2]string{
+ {"{{mul 2 3}}", "6"},
+ },
+ )
+
+ ns.AddMethodMapping(ctx.Sub,
+ []string{"sub"},
+ [][2]string{
+ {"{{sub 3 2}}", "1"},
+ },
+ )
+
+ return ns
+
}
internal.AddTemplateFuncsNamespace(f)