aboutsummaryrefslogtreecommitdiffhomepage
path: root/tpl/os
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/os
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/os')
-rw-r--r--tpl/os/init.go34
1 files changed, 22 insertions, 12 deletions
diff --git a/tpl/os/init.go b/tpl/os/init.go
index d03ad5f03..264afd43a 100644
--- a/tpl/os/init.go
+++ b/tpl/os/init.go
@@ -24,22 +24,32 @@ func init() {
f := func(d *deps.Deps) *internal.TemplateFuncsNamespace {
ctx := New(d)
- examples := [][2]string{
- {`{{ range (readDir ".") }}{{ .Name }}{{ end }}`, "README.txt"},
- {`{{ readFile "README.txt" }}`, `Hugo Rocks!`},
- }
-
- return &internal.TemplateFuncsNamespace{
+ ns := &internal.TemplateFuncsNamespace{
Name: name,
Context: func() interface{} { return ctx },
- Aliases: map[string]interface{}{
- "getenv": ctx.Getenv,
- "readDir": ctx.ReadDir,
- "readFile": ctx.ReadFile,
- },
- Examples: examples,
}
+ ns.AddMethodMapping(ctx.Getenv,
+ []string{"getenv"},
+ [][2]string{},
+ )
+
+ ns.AddMethodMapping(ctx.ReadDir,
+ []string{"readDir"},
+ [][2]string{
+ {`{{ range (readDir ".") }}{{ .Name }}{{ end }}`, "README.txt"},
+ },
+ )
+
+ ns.AddMethodMapping(ctx.ReadFile,
+ []string{"readFile"},
+ [][2]string{
+ {`{{ readFile "README.txt" }}`, `Hugo Rocks!`},
+ },
+ )
+
+ return ns
+
}
internal.AddTemplateFuncsNamespace(f)