Documentation ¶
Overview ¶
Package generate provides the generation of useful methods, variables, and constants for Goki code.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var KiMethodsTmpl = template.Must(template.New("KiMethods"). Funcs(template.FuncMap{ "HasEmbedDirective": HasEmbedDirective, "HasNoNewDirective": HasNoNewDirective, "KiPkg": KiPkg, }).Parse( ` {{if not (HasNoNewDirective .)}} // New{{.Name}} adds a new [{{.Name}}] with the given name // to the given parent. If the name is unspecified, it defaults // to the ID (kebab-case) name of the type, plus the // [{{KiPkg .}}Ki.NumLifetimeChildren] of the given parent. func New{{.Name}}(par {{KiPkg .}}Ki, name ...string) *{{.Name}} { return par.NewChild({{.Name}}Type, name...).(*{{.Name}}) } {{end}} // KiType returns the [*gti.Type] of [{{.Name}}] func (t *{{.Name}}) KiType() *gti.Type { return {{.Name}}Type } // New returns a new [*{{.Name}}] value func (t *{{.Name}}) New() {{KiPkg .}}Ki { return &{{.Name}}{} } {{if HasEmbedDirective .}} // {{.Name}}Embedder is an interface that all types that embed {{.Name}} satisfy type {{.Name}}Embedder interface { As{{.Name}}() *{{.Name}} } // As{{.Name}} returns the given value as a value of type {{.Name}} if the type // of the given value embeds {{.Name}}, or nil otherwise func As{{.Name}}(k {{KiPkg .}}Ki) *{{.Name}} { if k == nil || k.This() == nil { return nil } if t, ok := k.({{.Name}}Embedder); ok { return t.As{{.Name}}() } return nil } // As{{.Name}} satisfies the [{{.Name}}Embedder] interface func (t *{{.Name}}) As{{.Name}}() *{{.Name}} { return t } {{end}} `, ))
KiMethodsTmpl is a template that contains the methods and functions specific to [ki.Ki] types.
Functions ¶
func Generate ¶
Generate is the main entry point to code generation that does all of the generation according to the given config info. It overrides the [config.Config.Generate.Gtigen.InterfaceConfigs] info.
func HasEmbedDirective ¶ added in v0.1.23
HasEmbedDirective returns whether the given gtigen.Type has a "goki:embedder" comment directive. This function is used in KiMethodsTmpl.
func HasNoNewDirective ¶ added in v0.1.23
HasNoNewDirective returns whether the given gtigen.Type has a "goki:no-new" comment directive. This function is used in KiMethodsTmpl.
Types ¶
This section is empty.