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
diff options
context:
space:
mode:
authorTom Helmer Hansen <tom@adapt.dk>2015-01-17 17:46:27 +0300
committerbep <bjorn.erik.pedersen@gmail.com>2015-01-18 16:54:26 +0300
commite08cabadb6f0d61b818dfe4be404decb6c6e8ca2 (patch)
treebf35c4399c7a19387e4beb26c746f1de82495297 /tpl
parent871e811339b660232557dca10a6d181a5320d745 (diff)
Rewrite first argument to interface{}
Diffstat (limited to 'tpl')
-rw-r--r--tpl/template.go22
1 files changed, 20 insertions, 2 deletions
diff --git a/tpl/template.go b/tpl/template.go
index f392f81f0..1ddc04b57 100644
--- a/tpl/template.go
+++ b/tpl/template.go
@@ -880,6 +880,24 @@ func Chomp(text interface{}) (string, error) {
return chompRegexp.ReplaceAllString(s, ""), nil
}
+// Trim leading/trailing characters defined by b from a
+func Trim(a interface{}, b string) (string, error) {
+ aStr, err := cast.ToStringE(a)
+ if err != nil {
+ return "", err
+ }
+ return strings.Trim(aStr, b), nil
+}
+
+// Replace all occurences of b with c in a
+func Replace(a interface{}, b string, c string) (string, error) {
+ aStr, err := cast.ToStringE(a)
+ if err != nil {
+ return "", err
+ }
+ return strings.Replace(aStr, b, c, -1), nil
+}
+
func SafeHtml(text string) template.HTML {
return template.HTML(text)
}
@@ -1237,8 +1255,8 @@ func init() {
"relref": RelRef,
"apply": Apply,
"chomp": Chomp,
- "replace": func(a string, b string, c string) string { return strings.Replace(a, b, c, -1) },
- "trim": func(a string, b string) string { return strings.Trim(a, b) },
+ "replace": Replace,
+ "trim": Trim,
}
chompRegexp = regexp.MustCompile("[\r\n]+$")