render

package
v0.0.0-...-015b1eb Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2017 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RootTemplateSetName    = ""
	DefaultTemplateSetName = "default"
)

Variables

This section is empty.

Functions

func BuildExtraFuncs

func BuildExtraFuncs(r *Renderer) template.FuncMap

func RegistBuiltinTemplate

func RegistBuiltinTemplate(typeName string, templateSetName string, templateContent string)

RegistBuiltinTemplate regist a builtin template for a type with the given name.

func RegistType

func RegistType(typeName string, obj interface{}, handler Handler)

RegistType regist a type for renderring.

Types

type Appendable

type Appendable interface {
	Append(items ...interface{}) error
}

Appendable represents a mutable list of items.

type ColumnList

type ColumnList struct {
	// contains filtered or unexported fields
}

func NewColumnList

func NewColumnList() *ColumnList

func (*ColumnList) Append

func (cl *ColumnList) Append(items ...interface{}) error

func (*ColumnList) Cols

func (cl *ColumnList) Cols() []*context.ColumnMeta

func (*ColumnList) Index

func (cl *ColumnList) Index(i int) interface{}

func (*ColumnList) Len

func (cl *ColumnList) Len() int

type Handler

type Handler func(*Renderer, interface{}) (interface{}, error)

Handler takes a renderer and an object (TableMeta/SelectStmt...) as parameters, returns an object (the 'dot' object) for template renderring.

type Indexer

type Indexer interface {
	Len() int
	// Panic if out of range
	Index(i int) interface{}
}

Indexer represents a random accessable array.

type PkgName

type PkgName struct {

	// Full import path, empty if it's builtin or in current package.
	PkgPath string
	// contains filtered or unexported fields
}

PkgName represents a package used in source code.

func (*PkgName) String

func (pn *PkgName) String() string

PkgName is dynamicly determined by current scope. For example, "github.com/go-sql-driver/mysql" maybe render as "mysql" in one scope or "mysql_1" in another scope due to name conflict.

type Renderer

type Renderer struct {
	// Global context.
	*context.Context

	// Which file is renderring.
	*Scopes

	// Go type adapter.
	*TypeAdapter

	// Extra functions used in templates.
	ExtraFuncs template.FuncMap

	// Map type -> (template set name -> template).
	Templates map[reflect.Type]map[string]*template.Template

	// Use which set of templates for renderring.
	// Find the first of TemplateSetName/DefaultTemplateSetName/RootTemplateSetName
	// to render.
	TemplateSetName string
}

Renderer contain information to render objects.

func NewRenderer

func NewRenderer(ctx *context.Context) (*Renderer, error)

NewRenderer create Renderer from Context.

func (*Renderer) AddTemplate

func (r *Renderer) AddTemplate(typeName string, templateSetName string, templateContent string) error

AddTemplate add a template (in a template set ) for a type.

func (*Renderer) Render

func (r *Renderer) Render(obj interface{}, w io.Writer) error

Render an object.

func (*Renderer) Use

func (r *Renderer) Use(templateSetName string)

Use set template set name for renderring.

type Scope

type Scope struct {
	// contains filtered or unexported fields
}

Used to store information in a (file) scope.

func NewScope

func NewScope(name string) *Scope

func (*Scope) ImportPkg

func (scope *Scope) ImportPkg(pkgPath string) string

Import a package into the (file) scope and return a unique pkg name.

func (*Scope) ListPkg

func (scope *Scope) ListPkg() [][]string

List (pkgPath, pkgName) in the (file) scope. pkgName will be "_" if the package is imported but not used.

func (*Scope) UsePkg

func (scope *Scope) UsePkg(pkgPath string) string

Import (if not yet) package then use it.

type Scopes

type Scopes struct {
	// contains filtered or unexported fields
}

Set of Scope.

func NewScopes

func NewScopes() *Scopes

func (*Scopes) CreatePkgName

func (scopes *Scopes) CreatePkgName(pkgPath string) *PkgName

func (*Scopes) CreateTypeName

func (scopes *Scopes) CreateTypeName(pkgPath, typeName string) *TypeName

func (*Scopes) CreateTypeNameFromSpec

func (scopes *Scopes) CreateTypeNameFromSpec(s string) *TypeName

Create TypeName from dot-seperated spec:

[pkgPath.]type

Example:

"[]byte"
"sql.NullString"
"github.com/go-sql-driver/mysql.NullTime"

func (*Scopes) CurrScope

func (scopes *Scopes) CurrScope() *Scope

Current (file) scope.

func (*Scopes) SwitchScope

func (scopes *Scopes) SwitchScope(scopeName string) *Scope

Switch to a (file) scope.

type StringList

type StringList struct {
	// contains filtered or unexported fields
}

StringList is just a list of strings.

func NewStringList

func NewStringList() *StringList

func (*StringList) Append

func (sl *StringList) Append(items ...interface{}) error

func (*StringList) Index

func (sl *StringList) Index(i int) interface{}

func (*StringList) Len

func (sl *StringList) Len() int

func (*StringList) Strings

func (sl *StringList) Strings() []string

type StringsContainer

type StringsContainer interface {
	Strings() []string
}

StringsContainer represents a list of strings.

type TypeAdapter

type TypeAdapter struct {
	*Scopes
	AllNullTypes bool
}

For adapting database type and go type.

func NewTypeAdapter

func NewTypeAdapter(scopes *Scopes) *TypeAdapter

func (*TypeAdapter) AdaptType

func (ta *TypeAdapter) AdaptType(ft *ts.FieldType) *TypeName

Main method of TypeAdapter. Find a type suitable to store a db field data.

func (*TypeAdapter) CastType

func (ta *TypeAdapter) CastType(srcExpr string, srcTypeName, dstTypeName *TypeName) (string, error)

type TypeName

type TypeName struct {
	// The pkg containing the type.
	*PkgName

	// Name of the type.
	TypeName string
}

TypeName represents a type used in source code.

func (*TypeName) Spec

func (tn *TypeName) Spec() string

Spec returns the full (unique) spec of the type name.

func (*TypeName) String

func (tn *TypeName) String() string

Return "PkgName.TypeName". Note that PkgName is dynamicly determined by current scope. See PkgName's doc.

type UniqueStringList

type UniqueStringList struct {
	// contains filtered or unexported fields
}

UniqueStringList is a list of unique strings.

func NewUniqueStringList

func NewUniqueStringList(converter func(string) string, default_ string) *UniqueStringList

func (*UniqueStringList) Append

func (usl *UniqueStringList) Append(items ...interface{}) error

func (*UniqueStringList) Index

func (usl *UniqueStringList) Index(i int) interface{}

func (*UniqueStringList) Len

func (usl *UniqueStringList) Len() int

func (*UniqueStringList) Strings

func (usl *UniqueStringList) Strings() []string

Jump to

Keyboard shortcuts

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