templateUtil.go 396 Bytes
Newer Older
1 2 3 4
package mixins

import (
	"io"
5
	"strings"
6 7 8 9 10 11 12
	"text/template"

	wish "github.com/warpfork/go-wish"
)

func doTemplate(tmplstr string, w io.Writer, data interface{}) {
	tmpl := template.Must(template.New("").
13 14 15
		Funcs(template.FuncMap{
			"title": func(s string) string { return strings.Title(s) },
		}).
16 17 18 19 20
		Parse(wish.Dedent(tmplstr)))
	if err := tmpl.Execute(w, data); err != nil {
		panic(err)
	}
}