mirror of
https://github.com/ent/ent.git
synced 2026-05-22 09:31:45 +03:00
doc: update examples for custom templates
This commit is contained in:
committed by
Ariel Mashraki
parent
e26e99b643
commit
c6f9d25d8e
@@ -12,23 +12,35 @@ package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/facebook/ent/entc"
|
||||
"github.com/facebook/ent/entc/gen"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
)
|
||||
|
||||
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.
|
||||
opts := []entc.Option{
|
||||
entc.Funcs(template.FuncMap{"title": strings.ToTitle}),
|
||||
entc.TemplateFiles("template/static.tmpl"),
|
||||
}
|
||||
err := entc.Generate("./schema", &gen.Config{
|
||||
Header: `
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated (@generated) by entc, DO NOT EDIT.
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
`,
|
||||
IDType: &field.TypeInfo{Type: field.TypeInt},
|
||||
})
|
||||
Templates: []*template.Template{
|
||||
template.Must(template.New("debug").
|
||||
Funcs(gen.Funcs).
|
||||
ParseFiles("template/debug.tmpl")),
|
||||
},
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
log.Fatal("running ent codegen:", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user