Add pluralize template func

Fixes #1438
This commit is contained in:
Bjørn Erik Pedersen
2015-09-22 22:24:24 +02:00
parent 74924dd50d
commit 751d4906ef
3 changed files with 14 additions and 1 deletions

View File

@@ -14,6 +14,7 @@
package tpl
import (
"bitbucket.org/pkg/inflect"
"bytes"
"errors"
"fmt"
@@ -1371,6 +1372,13 @@ func init() {
"readDir": ReadDir,
"seq": helpers.Seq,
"getenv": func(varName string) string { return os.Getenv(varName) },
"pluralize": func(in interface{}) (string, error) {
word, err := cast.ToStringE(in)
if err != nil {
return "", err
}
return inflect.Pluralize(word), nil
},
}
}