mirror of
https://github.com/gohugoio/hugo.git
synced 2025-09-01 22:42:45 +02:00
tpl: Add docshelper for template funcs
And fix some other minor related issues. Updates #3418
This commit is contained in:
@@ -26,14 +26,15 @@ func New() *Namespace {
|
||||
type Namespace struct {
|
||||
}
|
||||
|
||||
func (ns *Namespace) Print(a ...interface{}) (n int, err error) {
|
||||
return _fmt.Print(a...)
|
||||
func (ns *Namespace) Print(a ...interface{}) string {
|
||||
return _fmt.Sprint(a...)
|
||||
}
|
||||
|
||||
func (ns *Namespace) Printf(format string, a ...interface{}) (n int, err error) {
|
||||
return _fmt.Printf(format, a...)
|
||||
func (ns *Namespace) Printf(format string, a ...interface{}) string {
|
||||
return _fmt.Sprintf(format, a...)
|
||||
|
||||
}
|
||||
|
||||
func (ns *Namespace) Println(a ...interface{}) (n int, err error) {
|
||||
return _fmt.Println(a...)
|
||||
func (ns *Namespace) Println(a ...interface{}) string {
|
||||
return _fmt.Sprintln(a...)
|
||||
}
|
||||
|
@@ -24,18 +24,33 @@ func init() {
|
||||
f := func(d *deps.Deps) *internal.TemplateFuncsNamespace {
|
||||
ctx := New()
|
||||
|
||||
examples := [][2]string{
|
||||
{`{{ print "works!" }}`, `works!`},
|
||||
{`{{ printf "%s!" "works" }}`, `works!`},
|
||||
{`{{ println "works!" }}`, "works!\n"},
|
||||
ns := &internal.TemplateFuncsNamespace{
|
||||
Name: name,
|
||||
Context: func() interface{} { return ctx },
|
||||
}
|
||||
|
||||
return &internal.TemplateFuncsNamespace{
|
||||
Name: name,
|
||||
Context: func() interface{} { return ctx },
|
||||
Aliases: map[string]interface{}{},
|
||||
Examples: examples,
|
||||
}
|
||||
ns.AddMethodMapping(ctx.Print,
|
||||
[]string{"print"},
|
||||
[][2]string{
|
||||
{`{{ print "works!" }}`, `works!`},
|
||||
},
|
||||
)
|
||||
|
||||
ns.AddMethodMapping(ctx.Println,
|
||||
[]string{"println"},
|
||||
[][2]string{
|
||||
{`{{ println "works!" }}`, "works!\n"},
|
||||
},
|
||||
)
|
||||
|
||||
ns.AddMethodMapping(ctx.Printf,
|
||||
[]string{"printf"},
|
||||
[][2]string{
|
||||
{`{{ printf "%s!" "works" }}`, `works!`},
|
||||
},
|
||||
)
|
||||
|
||||
return ns
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user