Files
grafana/pkg/codegen/tmpl.go
Selene 8f29450594 Kindsys: Remove Raw kind category (#60992)
* Remove Raw references

* Remove more raws

* Re-generate files

* Remove raw folder from veneer

* Fix import

* Fix lint

* Bring back raw folder in grafana-schema

* Another lint

* Remove use of "Structured" word in kinds

* Delete unused function and remove some structured words

* Bunch more removals of structured name

Co-authored-by: sam boyer <sdboyer@grafana.com>
2023-01-05 13:54:42 -05:00

61 lines
1.3 KiB
Go

package codegen
import (
"bytes"
"embed"
"text/template"
"time"
"github.com/grafana/codejen"
)
// All the parsed templates in the tmpl subdirectory
var tmpls *template.Template
func init() {
base := template.New("codegen").Funcs(template.FuncMap{
"now": time.Now,
})
tmpls = template.Must(base.ParseFS(tmplFS, "tmpl/*.tmpl"))
}
//go:embed tmpl/*.tmpl
var tmplFS embed.FS
// The following group of types, beginning with tvars_*, all contain the set
// of variables expected by the corresponding named template file under tmpl/
type (
tvars_autogen_header struct {
GeneratorPath string
LineagePath string
LineageCUEPath string
GenLicense bool
}
tvars_gen_header struct {
MainGenerator string
Using []codejen.NamedJenny
From string
}
tvars_kind_registry struct {
// Header tvars_autogen_header
NumStructured int
PackageName string
KindPackagePrefix string
Kinds []*DeclForGen
}
tvars_coremodel_imports struct {
PackageName string
}
)
type HeaderVars = tvars_autogen_header
// GenGrafanaHeader creates standard header elements for generated Grafana files.
func GenGrafanaHeader(vars HeaderVars) string {
buf := new(bytes.Buffer)
if err := tmpls.Lookup("autogen_header.tmpl").Execute(buf, vars); err != nil {
panic(err)
}
return buf.String()
}