Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tpl/fmt
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-05-01 19:40:34 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-05-01 22:44:15 +0300
commit690b0f8ff5795318dfa3834a5a75d6623e7d934a (patch)
tree1112306f4c6fecc0966d880dec702c3804633deb /tpl/fmt
parente2b067f0504ba41ef45786e2f83d7002bd13a7eb (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.go13
-rw-r--r--tpl/fmt/init.go35
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
}