diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-05-01 18:40:34 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-05-01 21:44:15 +0200 |
commit | 690b0f8ff5795318dfa3834a5a75d6623e7d934a (patch) | |
tree | 1112306f4c6fecc0966d880dec702c3804633deb /tpl/fmt | |
parent | e2b067f0504ba41ef45786e2f83d7002bd13a7eb (diff) |
tpl: Add docshelper for template funcs
And fix some other minor related issues.
Updates #3418
Diffstat (limited to 'tpl/fmt')
-rw-r--r-- | tpl/fmt/fmt.go | 13 | ||||
-rw-r--r-- | tpl/fmt/init.go | 35 |
2 files changed, 32 insertions, 16 deletions
diff --git a/tpl/fmt/fmt.go b/tpl/fmt/fmt.go index 5e320fede..ca31ec522 100644 --- a/tpl/fmt/fmt.go +++ b/tpl/fmt/fmt.go @@ -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...) } diff --git a/tpl/fmt/init.go b/tpl/fmt/init.go index 0f4296263..98070b777 100644 --- a/tpl/fmt/init.go +++ b/tpl/fmt/init.go @@ -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 } |