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:
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
}