generator

package
v0.31.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuildingExamples bool

BuildingExamples turns on the building of the templates for the examples code. This is specific to automating the build of the examples database code. You do not normally need to set this.

View Source
var DatabaseTemplates []DatabaseTemplateI

DatabaseTemplates is the collection of templates that are executed once per database.

View Source
var DefaultButtonType = "github.com/goradd/goradd/pkg/page/control/button/Button"

DefaultButtonType defines what buttons will be used for generated forms. The button should also have a creator that has the type name DefaultButtonType + "Creator"

View Source
var DefaultControlTypeFunc = DefaultControlType

DefaultControlTypeFunc is the injected function that determines the default control type for a particular type of database column. It gets initialized here, so that if you want to replace it, you can first call the default function

View Source
var DefaultDataPagerType = "github.com/goradd/goradd/pkg/page/control/DataPager"

DefaultDataPagerType defines what pager will be used for generated forms. The pager should also have a creator that has the type name DefaultDataPagerType + "Creator"

View Source
var DefaultFormFieldWrapperType = "github.com/goradd/goradd/pkg/page/control/FormFieldWrapper"

DefaultFormFieldWrapperType defines what form control wrapper will be used for generated controls. The wrapper should also have a creator that has the type name DefaultFormFieldWrapperType + "Creator".

View Source
var DefaultStaticTextType = "github.com/goradd/goradd/pkg/page/control/Panel"

DefaultStaticTextType is the type of control to create to display content as static text rather than something editable.

View Source
var EnumTableTemplates []EnumTableTemplateI

EnumTableTemplates is the list of templates that are executed once per "enum" table.

View Source
var OneTimeTemplates []OneTimeTemplateI

OneTimeTemplates is the collection of templates that are executed once per codegen rum.

View Source
var TableTemplates []TableTemplateI

TableTemplates is the collection of templates that will be populated by the individual templates found

View Source
var Verbose = false

Verbose controls whether to output the list of files being written

Functions

func AddDatabaseTemplate added in v0.30.1

func AddDatabaseTemplate(t DatabaseTemplateI)

AddDatabaseTemplate adds a template to the DatabaseTemplates list.

func AddEnumTableTemplate added in v0.27.0

func AddEnumTableTemplate(t EnumTableTemplateI)

AddEnumTableTemplate adds a template to the EnumTableTemplates list.

func AddOneTimeTemplate

func AddOneTimeTemplate(t OneTimeTemplateI)

AddOneTimeTemplate adds a template to the OneTimeTemplates list.

func AddTableTemplate

func AddTableTemplate(t TableTemplateI)

func AsConstant

func AsConstant(i interface{}, typ query.GoColumnType) string

Returns the value formatted as a constant. Essentially this just surrounds strings in quotes.

func ControlPath added in v0.9.2

func ControlPath(ref interface{}) string

ControlPath returns the type of control for a column. It gets this first from the database description, and if there is no ControlPath indicated, then from the registered DefaultControlTypeFunc function.

func DefaultControlType

func DefaultControlType(ref interface{}) string

DefaultControlType returns the default control type for the given database column These types are module paths to the control, and the generator will resolve those to figure out the import paths and package names

func ExportCreator added in v0.2.0

func ExportCreator(creator interface{}) string

ExportCreator export the given creator so that it can be embedded in a go file. Empty items are not exported Not all creators can be exported. This function is mainly a helper for code generation of controls. Specifically, events and actions do not export cleanly currently. But that should not be a problem for code generation.

func Generate

func Generate()

func RegisterControlGenerator

func RegisterControlGenerator(c ControlGenerator, path string)

func RunGoImports added in v0.17.3

func RunGoImports(fileName string)

Types

type CodeGenerator added in v0.2.1

type CodeGenerator struct {
	// Tables is a map of the tables by database
	Tables map[string]map[string]TableType
	// EnumTables is a map of the enum tables by database
	EnumTables map[string]map[string]EnumTableType
	// contains filtered or unexported fields
}

func (*CodeGenerator) AddImportPaths added in v0.9.2

func (c *CodeGenerator) AddImportPaths(paths ...string)

AddImportPaths adds an import path to the import path list. In particular, it will help manage the package aliases so the path can be referred to using the correct package name or package alias. Call this on all paths used by the file before calling ImportString.

func (*CodeGenerator) AddObjectPath added in v0.9.2

func (c *CodeGenerator) AddObjectPath(p string)

AddObjectPath adds an object path to the import path list. In particular, it will help manage the package list so the object can referred to using the correct package name or package alias. Call this on all object paths used by the form before calling ImportString.

func (*CodeGenerator) ImportPackage added in v0.9.2

func (c *CodeGenerator) ImportPackage(imp string) string

func (*CodeGenerator) ImportStrings added in v0.9.2

func (c *CodeGenerator) ImportStrings() (ret string)

ImportStrings returns strings to use in an import statement for all of the objects and imports entered

func (*CodeGenerator) ObjectPackage added in v0.9.2

func (c *CodeGenerator) ObjectPackage(imp string) string

func (*CodeGenerator) ObjectType added in v0.9.2

func (c *CodeGenerator) ObjectType(p string) string

ObjectType returns the string that should be used for an object type given its module path

func (*CodeGenerator) ResetImports added in v0.9.2

func (c *CodeGenerator) ResetImports()

ResetImports resets the internal information of the code generator. Call this just before generating a file.

func (*CodeGenerator) WrapFormField added in v0.28.0

func (c *CodeGenerator) WrapFormField(wrapperType string, label string, forId string, child string) string

WrapFormField returns a creator template for a field wrapper with type wrapperType.

child should be the creator template for the control that will be wrapped.

type ConnectorParam

type ConnectorParam struct {
	Name        string
	Description string
	Typ         ControlType
	Template    string
	DoFunc      func(c page.ControlI, val interface{})
}

type ControlDescription

type ControlDescription struct {
	Path string
	// Package is the package alias to be used when referring to the package the control is in. It is generated on a per-file basis.
	Package string
	// Imports is the list of imported packages that the control uses
	Imports      []string
	ControlType  string
	ControlName  string
	ControlID    string // default id to generate
	DefaultLabel string
	Generator    ControlGenerator
	Connector    string
}

ControlDescription is matched with a Column below and provides additional information regarding how information in a column can be used to generate a default control to edit that information. It is specifically for code generation.

func (*ControlDescription) ControlIDConst added in v0.2.4

func (cd *ControlDescription) ControlIDConst() string

type ControlGenerator

type ControlGenerator interface {
	SupportsColumn(ref interface{}) bool
	GenerateCreator(ref interface{}, desc *ControlDescription) string
	GenerateRefresh(ref interface{}, desc *ControlDescription) string
	GenerateUpdate(ref interface{}, desc *ControlDescription) string
	GenerateModifies(ref interface{}, desc *ControlDescription) string
}

func GetControlGenerator

func GetControlGenerator(controlPath string) ControlGenerator

type ControlType

type ControlType int

type DatabaseTemplateI added in v0.30.1

type DatabaseTemplateI interface {
	GenerateDatabase(codegen CodeGenerator, dd *db.Model, _w io.Writer) (err error)
	FileName(key string) string
	Overwrite() bool
}

DatabaseTemplateI represents the interface for templates that are executed once per database.

type EnumTableTemplateI added in v0.27.0

type EnumTableTemplateI interface {
	GenerateEnumTable(codegen CodeGenerator, dd *db.Model, t EnumTableType, _w io.Writer) (err error)
	FileName(key string, t EnumTableType) string
	Overwrite() bool
}

EnumTableTemplateI represents the interface for templates that are executed once per enum table.

type EnumTableType added in v0.27.0

type EnumTableType struct {
	*db.EnumTable
}

type ImportPath added in v0.2.3

type ImportPath struct {
	Alias string
	Path  string
}

type ImportType

type ImportType struct {
	Path  string
	Alias string // blank if not needing an alias
}

ImportType represents an import path required for a control. This is analyzed per-table.

type Importer added in v0.8.0

type Importer interface {
	Imports() []string
}

type OneTimeTemplateI

type OneTimeTemplateI interface {
	GenerateOnce(codegen CodeGenerator, databases []db.DatabaseI, _w io.Writer) (err error)
	FileName() string
	Overwrite() bool
}

OneTimeTemplateI represents the interface for templates that are executed just once.

type ProviderGenerator added in v0.2.0

type ProviderGenerator interface {
	GenerateProvider(ref interface{}, desc *ControlDescription) string
}

type TableTemplateI

type TableTemplateI interface {
	GenerateTable(codegen CodeGenerator, dd *db.Model, t TableType, _w io.Writer) (err error)
	FileName(key string, t TableType) string
	Overwrite() bool
}

TableTemplateI represents the interface for templates that are executed once per regular table.

type TableType

type TableType struct {
	*db.Table

	Imports []ImportType
	// contains filtered or unexported fields
}

func (*TableType) ControlDescription added in v0.7.0

func (t *TableType) ControlDescription(ref interface{}) *ControlDescription

func (*TableType) GetColumnByDbName

func (t *TableType) GetColumnByDbName(name string) *db.Column

type Template

type Template struct {
	Overwrite bool
	TargetDir string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL