~evanj/cms

ref: 276ecdc6f2a4e9f6b0221d1cc68f178cfff9f186 cms/internal/v/v.go -rw-r--r-- 801 bytes
276ecdc6Evan J Fix(cache): When deleting item, don't error out on cache miss of the 4 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
29
30
31
32
33
34
35
36
37
38
package v

import (
	"html/template"
	"strings"

	"git.sr.ht/~evanj/cms/internal/m/tier"
	"git.sr.ht/~evanj/cms/internal/m/user"
)

//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) },
			"paid": func(u user.User) bool {
				if u == nil {
					return false
				}
				return u.Org().Tier().Is(tier.Business) || u.Org().Tier().Is(tier.Enterprise)
			},
			"isFree": func(t tier.Tier) bool { return t.Is(tier.Free) },
		}

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

	}

	return all.Lookup(name)
}