Documentation
¶
Index ¶
- Constants
- func ApplyMeta(outdir string, meta *TemplateMeta, data interface{}, dftName string) (io.WriteCloser, error)
- func CppFormat(filename string) error
- func GeneratePackage(pkg *build.Package) (files map[string]bool, err error)
- func GoFmt(filename string) error
- func Init(buildType BuildTypeFunc, plugin build.Plugin, config build.PluginRuntimeConfig)
- func OpenTemplatesDir(lang, dir string) ([]os.FileInfo, error)
- func ParseTemplateFile(filename string) (*TemplateMeta, *Template, error)
- func ParseTemplateFilename(filename string) (kind, suffix string)
- type Bean
- type Bool
- type BuildTypeFunc
- type Context
- func (ctx *Context) AutoGenDeclaration() string
- func (ctx *Context) BuildType(typ build.Type) string
- func (ctx *Context) Extension(at string, data interface{}) (string, error)
- func (ctx *Context) FindBean(name string) *build.Bean
- func (ctx *Context) Getenv(key string) string
- func (ctx *Context) JSInitValue(typ build.Type) string
- type File
- type GenDecl
- type Group
- type Int
- type Package
- type String
- type Template
- type TemplateMeta
Constants ¶
const ( // IncludesDir contains template files for `include` and `include_template` functions IncludesDir = "includes" // TemplateFileSuffix is the template filename suffix could be recognized TemplateFileSuffix = ".temp" )
Variables ¶
This section is empty.
Functions ¶
func ApplyMeta ¶
func ApplyMeta(outdir string, meta *TemplateMeta, data interface{}, dftName string) (io.WriteCloser, error)
ApplyMeta creates a target file by the template meta
func GeneratePackage ¶
GeneratePackage generates codes for package
func Init ¶
func Init( buildType BuildTypeFunc, plugin build.Plugin, config build.PluginRuntimeConfig, )
Init initializes generator NOTE: You MUST initialize generator before using generator
buildType is a function for building build.Type to a string plugin is the language plugin config is runtime config of the plugin
func OpenTemplatesDir ¶
OpenTemplatesDir opens a directory for getting all files and directories
func ParseTemplateFile ¶
func ParseTemplateFile(filename string) (*TemplateMeta, *Template, error)
ParseTemplateFile parses template file
func ParseTemplateFilename ¶
ParseTemplateFilename parses template filename: <kind>[.suffix[.flags]].temp `kind` maybe `package`,`file`,`const` and other bean kinds like `struct`,`protocol`,`service` etc. Examples:
struct.go.temp -> (struct, go) struct.h.temp -> (struct, h) struct.cpp.temp -> (struct, cpp) struct.cpp.1.temp -> (struct, cpp)
Types ¶
type Bean ¶
Bean wraps build.Bean
func (*Bean) BuildExtends ¶ added in v0.1.3
Extends gets extends of bean as a string slice
type BuildTypeFunc ¶
BuildTypeFunc is a function type which used to build `build.Type` to a string
type Context ¶
type Context struct {
// Pkg represents current package
Pkg *build.Package
// Root represents root template
Root *Template
// Plugin represents current plugin
Plugin build.Plugin
// Config represents current plugin runtime config
Config build.PluginRuntimeConfig
// Kind holds current template kind
Kind string
// Suffix holds current template suffix
Suffix string
// Pwd holds current template file directory
Pwd string
// Beans holds all beans in current package
Beans map[string]*build.Bean
Filename string
// contains filtered or unexported fields
}
Context holds current context for generating codes of specified package
func NewContext ¶
func NewContext( buildType BuildTypeFunc, plugin build.Plugin, config build.PluginRuntimeConfig, ) *Context
NewContext creates a context by buildType,plugin,plugin_config
func (*Context) AutoGenDeclaration ¶
AutoGenDeclaration returns a declaration which would be written to each generated file header e.g. // AUTO-GENERATED by midc!! DON'T EDIT!!
type File ¶
File wraps build.File
func (File) Gen ¶ added in v0.1.4
Gen generates file by predefined sub-template `T_const`, `T_<kind>`
func (File) GenerateDeclsBySubTemplates ¶
Depcrated API, use `Gen' instead
type Package ¶
Package wraps build.Package
func (Package) Gen ¶ added in v0.1.4
Gen generates file by predefined sub-template `T_const`, `T_group`, `T_<kind>`
func (Package) GenerateDeclsBySubTemplates ¶
Depcrated API, use `Gen' instead
type Template ¶
Template wraps template.Template
func NewTemplate ¶
NewTemplate creates a Template by template.Template
type TemplateMeta ¶
type TemplateMeta struct {
File string
Values map[string]string
// contains filtered or unexported fields
}
TemplateMeta represents meta information of a template file