genutil

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2018 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
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 CppFormat

func CppFormat(filename string) error

CppFormat formats cpp code file

func GeneratePackage

func GeneratePackage(pkg *build.Package) (files map[string]bool, err error)

GeneratePackage generates codes for package

func GoFmt

func GoFmt(filename string) error

GoFmt formats go code file

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

func OpenTemplatesDir(lang, dir string) ([]os.FileInfo, error)

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

func ParseTemplateFilename(filename string) (kind, suffix string)

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

type Bean struct {
	*build.Bean
	File *File
}

Bean wraps build.Bean

func NewBean

func NewBean(file *build.File, b *build.Bean) *Bean

func (*Bean) AddTag

func (bean *Bean) AddTag(key, value string, field *build.Field) *build.Field

AddTag is a chain function for adding tag

func (*Bean) AddTagNX

func (bean *Bean) AddTagNX(key, value string, field *build.Field) *build.Field

func (*Bean) BuildExtends added in v0.1.3

func (bean *Bean) BuildExtends(ctx *Context) []string

Extends gets extends of bean as a string slice

type Bool added in v0.1.2

type Bool bool

func (Bool) Get added in v0.1.2

func (b Bool) Get() bool

func (*Bool) Set added in v0.1.2

func (b *Bool) Set(v bool) string

func (Bool) String added in v0.1.2

func (b Bool) String() string

type BuildTypeFunc

type BuildTypeFunc func(build.Type) string

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
	// 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

func (ctx *Context) AutoGenDeclaration() string

AutoGenDeclaration returns a declaration which would be written to each generated file header e.g. // AUTO-GENERATED by midc!! DON'T EDIT!!

func (*Context) BuildType

func (ctx *Context) BuildType(typ build.Type) string

BuildType executes buildType function

func (*Context) Extension

func (ctx *Context) Extension(at string, data interface{}) (string, error)

Extension inserts code for extensions at specific position

func (*Context) FindBean

func (ctx *Context) FindBean(name string) *build.Bean

FindBean finds bean by name in current package

func (*Context) Getenv

func (ctx *Context) Getenv(key string) string

Getenv gets custom envvar

func (*Context) JSInitValue added in v0.1.3

func (ctx *Context) JSInitValue(typ build.Type) string

JSInitValue returns init value of javascript by Type

type File

type File struct {
	*build.File
	// contains filtered or unexported fields
}

File wraps build.File

func (*File) FindGroup added in v0.1.3

func (f *File) FindGroup(name string) *build.Group

func (File) GenerateDeclsBySubTemplates

func (f File) GenerateDeclsBySubTemplates() (string, error)

type GenDecl

type GenDecl struct {
	*build.GenDecl
	File *File
}

GenDecl wraps build.GenDecl

func NewGenDecl

func NewGenDecl(file *build.File, c *build.GenDecl) *GenDecl

type Group added in v0.1.3

type Group struct {
	*build.Group
	File *File
}

Group wraps build.Group

func NewGroup added in v0.1.3

func NewGroup(file *build.File, g *build.Group) *Group

type Int added in v0.1.2

type Int int

func (*Int) Add added in v0.1.2

func (i *Int) Add(delta int) int

func (Int) Get added in v0.1.2

func (i Int) Get() int

func (*Int) Incr added in v0.1.3

func (i *Int) Incr(delta int) int

func (*Int) Set added in v0.1.2

func (i *Int) Set(v int) string

func (Int) String added in v0.1.2

func (i Int) String() string

func (*Int) Sub added in v0.1.2

func (i *Int) Sub(delta int) int

type Package

type Package struct {
	*build.Package
}

Package wraps build.Package

func (Package) GenerateDeclsBySubTemplates

func (pkg Package) GenerateDeclsBySubTemplates() (string, error)

type String added in v0.1.2

type String string

func (String) Get added in v0.1.2

func (s String) Get() string

func (*String) Set added in v0.1.2

func (s *String) Set(v string) string

func (String) String added in v0.1.2

func (s String) String() string

type Template

type Template struct {
	*template.Template
}

Template wraps template.Template

func NewTemplate

func NewTemplate(temp *template.Template) *Template

NewTemplate creates a Template by template.Template

func (*Template) Lookup

func (temp *Template) Lookup(name string) *Template

Lookup overrides template.Template.Lookup method

type TemplateMeta

type TemplateMeta struct {
	File   string
	Values map[string]string
	// contains filtered or unexported fields
}

TemplateMeta represents meta information of a template file

Jump to

Keyboard shortcuts

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