entc/gen: add gen.Template for ent extensions (#859)

This commit is contained in:
Ariel Mashraki
2020-10-18 14:17:20 +03:00
committed by GitHub
parent 7635d45c8a
commit 17ee19e23a
6 changed files with 119 additions and 84 deletions

View File

@@ -18,10 +18,9 @@ import (
func main() {
// A usage for custom templates with external functions.
// One template is defined in the option below, and the
// second template is provided with the `Templates` field.
// second template is provided with the `Templates` option.
opts := []entc.Option{
entc.Funcs(template.FuncMap{"title": strings.ToTitle}),
entc.TemplateFiles("template/static.tmpl"),
entc.TemplateFiles("template/debug.tmpl"),
}
err := entc.Generate("./schema", &gen.Config{
Header: `
@@ -31,10 +30,10 @@ func main() {
// Code generated by entc, DO NOT EDIT.
`,
Templates: []*template.Template{
template.Must(template.New("debug").
Funcs(gen.Funcs).
ParseFiles("template/debug.tmpl")),
Templates: []*gen.Template{
gen.MustParse(gen.NewTemplate("static").
Funcs(template.FuncMap{"title": strings.ToTitle}).
ParseFiles("template/static.tmpl")),
},
}, opts...)
if err != nil {