Documentation
¶
Overview ¶
Package generate provides the generation of useful methods, variables, and constants for Cogent Core code.
Index ¶
- Variables
- func Generate(c *config.Config) error
- func GetWebcoreExamples(c *config.Config) (ordmap.Map[string, []byte], error)
- func HasEmbedDirective(typ *gtigen.Type) bool
- func HasNoNewDirective(typ *gtigen.Type) bool
- func KiPkg(typ *gtigen.Type) string
- func ParsePackages(cfg *config.Config) ([]*packages.Package, error)
- func Webcore(c *config.Config) error
- func WriteWebcoregen(c *config.Config, examples ordmap.Map[string, []byte]) error
Constants ¶
This section is empty.
Variables ¶
var KiMethodsTmpl = template.Must(template.New("KiMethods"). Funcs(template.FuncMap{ "HasEmbedDirective": HasEmbedDirective, "HasNoNewDirective": HasNoNewDirective, "DocToComment": gtigen.DocToComment, "KiPkg": KiPkg, }).Parse( ` {{if not (HasNoNewDirective .)}} // New{{.LocalName}} adds a new [{{.LocalName}}] with the given name to the given parent: {{DocToComment .Doc}} func New{{.LocalName}}(par {{KiPkg .}}Ki, name ...string) *{{.LocalName}} { return par.NewChild({{.LocalName}}Type, name...).(*{{.LocalName}}) } {{end}} // KiType returns the [*gti.Type] of [{{.LocalName}}] func (t *{{.LocalName}}) KiType() *gti.Type { return {{.LocalName}}Type } // New returns a new [*{{.LocalName}}] value func (t *{{.LocalName}}) New() {{KiPkg .}}Ki { return &{{.LocalName}}{} } {{if HasEmbedDirective .}} // {{.LocalName}}Embedder is an interface that all types that embed {{.LocalName}} satisfy type {{.LocalName}}Embedder interface { As{{.LocalName}}() *{{.LocalName}} } // As{{.LocalName}} returns the given value as a value of type {{.LocalName}} if the type // of the given value embeds {{.LocalName}}, or nil otherwise func As{{.LocalName}}(k {{KiPkg .}}Ki) *{{.LocalName}} { if k == nil || k.This() == nil { return nil } if t, ok := k.({{.LocalName}}Embedder); ok { return t.As{{.LocalName}}() } return nil } // As{{.LocalName}} satisfies the [{{.LocalName}}Embedder] interface func (t *{{.LocalName}}) As{{.LocalName}}() *{{.LocalName}} { 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 GetWebcoreExamples ¶ added in v0.0.3
GetWebcoreExamples collects and returns all of the webcore examples.
func HasEmbedDirective ¶
HasEmbedDirective returns whether the given gtigen.Type has a "core:embedder" comment directive. This function is used in KiMethodsTmpl.
func HasNoNewDirective ¶
HasNoNewDirective returns whether the given gtigen.Type has a "core:no-new" comment directive. This function is used in KiMethodsTmpl.
func KiPkg ¶
KiPkg returns the package identifier for the ki package in the context of the given type ("" if it is already in the ki package, and "ki." otherwise)
func ParsePackages ¶
ParsePackages parses the package(s) based on the given config info.
Types ¶
This section is empty.