feat: Add defaultFuncMap to template
This commit is contained in:
parent
686faf0556
commit
ec05fbcf19
2 changed files with 76 additions and 1 deletions
|
@ -58,7 +58,19 @@ func (p *BaseProvider) getConfiguration(defaultTemplateFile string, funcMap temp
|
|||
err error
|
||||
)
|
||||
configuration := new(types.Configuration)
|
||||
tmpl := template.New(p.Filename).Funcs(funcMap)
|
||||
var defaultFuncMap = template.FuncMap{
|
||||
"replace": replace,
|
||||
"tolower": strings.ToLower,
|
||||
"normalize": normalize,
|
||||
"split": split,
|
||||
"contains": contains,
|
||||
}
|
||||
|
||||
for funcID, funcElement := range funcMap {
|
||||
defaultFuncMap[funcID] = funcElement
|
||||
}
|
||||
|
||||
tmpl := template.New(p.Filename).Funcs(defaultFuncMap)
|
||||
if len(p.Filename) > 0 {
|
||||
buf, err = ioutil.ReadFile(p.Filename)
|
||||
if err != nil {
|
||||
|
@ -93,6 +105,14 @@ func replace(s1 string, s2 string, s3 string) string {
|
|||
return strings.Replace(s3, s1, s2, -1)
|
||||
}
|
||||
|
||||
func contains(substr, s string) bool {
|
||||
return strings.Contains(s, substr)
|
||||
}
|
||||
|
||||
func split(sep, s string) []string {
|
||||
return strings.Split(s, sep)
|
||||
}
|
||||
|
||||
func normalize(name string) string {
|
||||
fargs := func(c rune) bool {
|
||||
return !unicode.IsLetter(c) && !unicode.IsNumber(c)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue