genutil

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2016 License: MIT Imports: 13 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) (*os.File, 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 *build.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) Extends

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

Extends gets extends of bean as a string slice

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

type File

type File struct {
	*build.File
}

File wraps build.File

func (File) GenerateDeclsBySubTemplates

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

type GenDecl

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

GenDecl wraps build.GenDecl

func NewGenDecl

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

type Package

type Package struct {
	*build.Package
}

Package wraps build.Package

func (Package) GenerateDeclsBySubTemplates

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

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
}

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