~evanj/cms

ref: 8efa6eb4fd1aad49d40bb3850530c531add998da cms/internal/s/tmpl/tmpl.go -rw-r--r-- 493 bytes
8efa6eb4Evan M Jones WIP(stripe): *. 1 year, 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package tmpl

import (
	"html/template"
	"strings"
)

//go:generate embed -pattern */* -id tmpls

var all *template.Template

func MustParse(name string) *template.Template {
	if all == nil {

		fns := template.FuncMap{
			"inc":   func(i int) int { return i + 1 },
			"title": func(str string) string { return strings.Title(str) },
		}

		all = template.New("cms")
		for key, val := range tmpls {
			all = template.Must(all.New(key).Funcs(fns).Parse(val))
		}

	}

	return all.Lookup(name)
}