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.go9
-rw-r--r--tpl/fmt/init.go8
2 files changed, 15 insertions, 2 deletions
diff --git a/tpl/fmt/fmt.go b/tpl/fmt/fmt.go
index 96695442e..96113a598 100644
--- a/tpl/fmt/fmt.go
+++ b/tpl/fmt/fmt.go
@@ -15,15 +15,17 @@ package fmt
import (
_fmt "fmt"
+ "github.com/gohugoio/hugo/helpers"
)
// New returns a new instance of the fmt-namespaced template functions.
func New() *Namespace {
- return &Namespace{}
+ return &Namespace{helpers.NewDistinctErrorLogger()}
}
// Namespace provides template functions for the "fmt" namespace.
type Namespace struct {
+ errorLogger *helpers.DistinctLogger
}
// Print returns string representation of the passed arguments.
@@ -41,3 +43,8 @@ func (ns *Namespace) Printf(format string, a ...interface{}) string {
func (ns *Namespace) Println(a ...interface{}) string {
return _fmt.Sprintln(a...)
}
+
+func (ns *Namespace) Errorf(format string, a ...interface{}) string {
+ ns.errorLogger.Printf(format, a...)
+ return _fmt.Sprintf(format, a...)
+}
diff --git a/tpl/fmt/init.go b/tpl/fmt/init.go
index a3398b862..76c68957a 100644
--- a/tpl/fmt/init.go
+++ b/tpl/fmt/init.go
@@ -50,8 +50,14 @@ func init() {
},
)
- return ns
+ ns.AddMethodMapping(ctx.Errorf,
+ []string{"errorf"},
+ [][2]string{
+ {`{{ errorf "%s." "failed" }}`, `failed.`},
+ },
+ )
+ return ns
}
internal.AddTemplateFuncsNamespace(f)