mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-20 21:31:32 +02:00
tpl: Add docshelper for template funcs
And fix some other minor related issues. Updates #3418
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user