Documentation ¶
Index ¶
- Constants
- Variables
- func CreateFileFromTemplate(fileName string, template *template.Template, data interface{})
- func CreatePool(modules []*ModuleInfo, dir string)
- func ExtractFunctionName(node *ast.CallExpr) (string, error)
- func GetModelsASTData(modules []*ModuleInfo) map[string]ModelASTData
- func GetModelsASTDataForModules(modInfos []*ModuleInfo, validate bool) map[string]ModelASTData
- type FieldASTData
- type MethodASTData
- type ModelASTData
- type ModuleInfo
- type PackageType
- type ParamData
- type TypeData
Constants ¶
const ( // HexyaPath is the go import path of the base hexya package HexyaPath = "github.com/hexya-erp/hexya" // ModelsPath is the go import path of the hexya/models package ModelsPath = "github.com/hexya-erp/hexya/src/models" // DatesPath is the go import path of the hexya/models/types/dates package DatesPath = "github.com/hexya-erp/hexya/src/models/types/dates" // PoolPath is the go import path of the autogenerated pool package PoolPath = "github.com/hexya-erp/pool" // PoolModelPackage is the name of the pool package with model data PoolModelPackage = "h" // PoolQueryPackage is the name of the pool package with query dat PoolQueryPackage = "q" )
Variables ¶
Functions ¶
func CreateFileFromTemplate ¶
CreateFileFromTemplate generates a new file from the given template and data
func CreatePool ¶
func CreatePool(modules []*ModuleInfo, dir string)
CreatePool generates the pool package by parsing the source code AST of the given program. The generated package will be put in the given dir.
func ExtractFunctionName ¶
ExtractFunctionName returns the name of the called function in the given call expression.
func GetModelsASTData ¶
func GetModelsASTData(modules []*ModuleInfo) map[string]ModelASTData
GetModelsASTData returns the ModelASTData of all models found when parsing program.
func GetModelsASTDataForModules ¶
func GetModelsASTDataForModules(modInfos []*ModuleInfo, validate bool) map[string]ModelASTData
GetModelsASTDataForModules returns the MethodASTData for all methods in given modules. If validate is true, then only models that have been explicitly declared will appear in the result. Mixins and embeddings will be inflated too. Use this if you want validate the whole application.
Types ¶
type FieldASTData ¶
type FieldASTData struct { Name string JSON string Help string Description string Selection map[string]string RelModel string Type TypeData IsRS bool MixinField bool EmbedField bool // contains filtered or unexported fields }
A FieldASTData is a holder for a field's data that will be used for pool code generation
type MethodASTData ¶
type MethodASTData struct { Name string Doc string PkgPath string Params []ParamData Returns []TypeData ToDeclare bool }
A MethodASTData is a holder for a method's data that will be used for pool code generation
type ModelASTData ¶
type ModelASTData struct { Name string ModelType string IsModelMixin bool Fields map[string]FieldASTData Methods map[string]MethodASTData Mixins map[string]bool Embeds map[string]bool Validated bool }
A ModelASTData holds fields and methods data of a Model
type ModuleInfo ¶
type ModuleInfo struct { packages.Package ModType PackageType FSet *token.FileSet }
A ModuleInfo is a wrapper around packages.Package with additional data to describe a module.
func GetModulePackages ¶
func GetModulePackages(packs []*packages.Package) []*ModuleInfo
GetModulePackages returns a slice of PackageInfo for packages that are hexya modules, that is: - A package that declares a "MODULE_NAME" constant - A package that is in a subdirectory of a package Also returns the 'hexya/models' package since all models are initialized there
func NewModuleInfo ¶
func NewModuleInfo(pack *packages.Package, modType PackageType, fSet *token.FileSet) *ModuleInfo
NewModuleInfo returns a pointer to a new moduleInfo instance
type PackageType ¶
type PackageType int8
A PackageType describes a type of module
const ( // Base is the PackageType for the base package of a module Base PackageType = iota // Models is the PackageType for the hexya/models package Models )