template.go 424 B

123456789101112131415161718
  1. package template
  2. import (
  3. "strings"
  4. "text/template"
  5. )
  6. // funcMap defines functions for our template system.
  7. var funcMap = template.FuncMap{
  8. "join": func(s ...string) string {
  9. // first arg is sep, remaining args are strings to join
  10. return strings.Join(s[1:], s[0])
  11. },
  12. }
  13. func newTemplate(s string) (*template.Template, error) {
  14. return template.New("expansion").Option("missingkey=error").Funcs(funcMap).Parse(s)
  15. }