generate

package
v0.1.0-pre2 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
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 = HexyaPath + "/src/models"
	// DatesPath is the go import path of the hexya/models/types/dates package
	DatesPath = HexyaPath + "/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"
	// PoolInterfacesPackage is the name of the pool packages with all model interfaces
	PoolInterfacesPackage = "m"
)

Variables

View Source
var (

	// ModelMixins are the names of the mixins declared in the models package
	ModelMixins = map[string]bool{
		"CommonMixin":    true,
		"BaseMixin":      true,
		"ModelMixin":     true,
		"TransientMixin": true,
	}
)

Functions

func CreateFileFromTemplate

func CreateFileFromTemplate(fileName string, template *template.Template, data interface{})

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

func ExtractFunctionName(node *ast.CallExpr) (string, error)

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
	FType       fieldtype.Type
	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
)

type ParamData

type ParamData struct {
	Name     string
	Variadic bool
	Type     TypeData
}

A ParamData holds the name and type of a method parameter

type TypeData

type TypeData struct {
	Type       string
	ImportPath string
}

A TypeData holds a Type string and optional import path for this type.

Jump to

Keyboard shortcuts

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