~evanj/cms

ref: 991b370ac6b6208e5f2fd7dcada177d52be58d9f cms/internal/v/v.go -rw-r--r-- 490 bytes
991b370aEvan M Jones Feat(Big): Added a few things here... 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 v

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)
}