github.com/go/docker@v1.12.0-rc2/utils/templates/templates.go (about) 1 package templates 2 3 import ( 4 "encoding/json" 5 "strings" 6 "text/template" 7 ) 8 9 // basicFunctions are the set of initial 10 // functions provided to every template. 11 var basicFunctions = template.FuncMap{ 12 "json": func(v interface{}) string { 13 a, _ := json.Marshal(v) 14 return string(a) 15 }, 16 "split": strings.Split, 17 "join": strings.Join, 18 "title": strings.Title, 19 "lower": strings.ToLower, 20 "upper": strings.ToUpper, 21 } 22 23 // Parse creates a new annonymous template with the basic functions 24 // and parses the given format. 25 func Parse(format string) (*template.Template, error) { 26 return NewParse("", format) 27 } 28 29 // NewParse creates a new tagged template with the basic functions 30 // and parses the given format. 31 func NewParse(tag, format string) (*template.Template, error) { 32 return template.New(tag).Funcs(basicFunctions).Parse(format) 33 }