-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtemplates.go
59 lines (51 loc) · 1.47 KB
/
templates.go
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) Liam Stanley <liam@liam.sh>. All rights reserved. Use of
// this source code is governed by the MIT license that can be found in
// the LICENSE file.
package entrest
import (
"embed"
"text/template"
"entgo.io/ent/entc/gen"
)
var (
funcMap = template.FuncMap{
"zplural": Pluralize,
"zkebab": KebabCase,
"zsingular": Singularize,
"zpascal": PascalCase,
"zcamel": CamelCase,
"zsnake": SnakeCase,
// Use this function when you want to invoke annotation functions (which are
// often created if they depend on [Config]).
"getAnnotation": GetAnnotation,
"getSortableFields": GetSortableFields,
"getFilterableFields": GetFilterableFields,
"getFilterGroups": GetFilterGroups,
"getOperationIDName": GetOperationIDName,
"getPathName": GetPathName,
}
//go:embed templates
templateDir embed.FS
baseTemplates = gen.MustParse(
gen.NewTemplate("rest").Funcs(funcMap).
SkipIf(func(g *gen.Graph) bool { return GetConfig(g.Config).Handler == HandlerNone }).
ParseFS(
templateDir,
"templates/*.tmpl",
"templates/helper/*.tmpl",
"templates/helper/**/*.tmpl",
),
)
testingTemplates = gen.MustParse(
gen.NewTemplate("resttest").Funcs(funcMap).
SkipIf(func(g *gen.Graph) bool { return !GetConfig(g.Config).WithTesting }).
ParseFS(
templateDir,
"templates/testing/*.tmpl",
),
)
)
// FuncMaps export FuncMaps to use custom templates.
func FuncMaps() template.FuncMap {
return funcMap
}