templates

package
v0.0.0-...-fe6f8ac Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddKnownType

func AddKnownType(ctx context.Context, name string) error

AddKnownType adds a known type name to a template set.

func Driver

func Driver(ctx context.Context) string

Driver returns driver option from the context.

func Emit

func Emit(ctx context.Context, tpl *Template) error

Emit emits a template to a template set.

func Errors

func Errors(ctx context.Context) ([]error, error)

Errors returns errors collected during file generation.

func GenType

func GenType(ctx context.Context) string

GenType returns the the gen-type option from the context.

func NthParam

func NthParam(ctx context.Context) func(int) string

NthParam returns the nth-param option from the context.

func Out

func Out(ctx context.Context) string

Out returns out option from the context.

func Process

func Process(ctx context.Context, doAppend bool, single string, order ...string) error

Process processes emitted templates for a template set.

func Register

func Register(typ string, set *TemplateSet)

Register registers a template set.

func Schema

func Schema(ctx context.Context) string

Schema returns schema option from the context.

func Src

func Src(ctx context.Context) fs.FS

Src returns src option from the context.

func Suffix

func Suffix(ctx context.Context) string

Suffix returns suffix option from the context.

func TemplateType

func TemplateType(ctx context.Context) string

TemplateType returns type option from the context.

func Types

func Types() []string

Types returns the registered type names of template sets.

func Write

func Write(ctx context.Context) error

Write performs post processing of emitted templates to a template set, writing to disk the processed content.

func WriteFiles

func WriteFiles(ctx context.Context) error

WriteFiles writes the generated files to disk.

func WriteRaw

func WriteRaw(ctx context.Context) error

WriteRaw writes the raw templates for a template set.

Types

type ContextKey

type ContextKey string

ContextKey is a context key.

const (
	GenTypeKey      ContextKey = "gen-type"
	TemplateTypeKey ContextKey = "template-type"
	SuffixKey       ContextKey = "suffix"
	DriverKey       ContextKey = "driver"
	SchemaKey       ContextKey = "schema"
	SrcKey          ContextKey = "src"
	NthParamKey     ContextKey = "nth-param"
	OutKey          ContextKey = "out"
)

Context keys.

type EmittedTemplate

type EmittedTemplate struct {
	Template *Template
	Buf      []byte
	File     string
	Err      []error
}

EmittedTemplate wraps a template with its content and file name.

type Enum

type Enum struct {
	Name    string
	Values  []*EnumValue
	Enum    *models.Enum
	Comment string
}

Enum is a enum type template.

type EnumValue

type EnumValue struct {
	Name    string
	Val     *models.EnumValue
	Comment string
}

EnumValue is a enum value template.

type ErrPostFailed

type ErrPostFailed struct {
	File string
	Err  error
}

ErrPostFailed is the post failed error.

func (*ErrPostFailed) Error

func (err *ErrPostFailed) Error() string

Error satisfies the error interface.

func (*ErrPostFailed) Unwrap

func (err *ErrPostFailed) Unwrap() error

Unwrap satisfies the unwrap interface.

type Field

type Field struct {
	Name    string
	Type    string
	Zero    string
	Prec    int
	Col     *models.Column
	Comment string
}

Field is a field template.

type Flag

type Flag struct {
	ContextKey  ContextKey
	Desc        string
	PlaceHolder string
	Default     string
	Short       rune
	Value       interface{}
	Enums       []string
}

Flag is a option flag.

type FlagSet

type FlagSet struct {
	Type string
	Name string
	Flag Flag
}

FlagSet wraps a option flag with context information.

func Flags

func Flags() []FlagSet

Flags returns flag options and context for the template sets.

These should be added to the invocation context for any call to a template set func.

type ForeignKey

type ForeignKey struct {
	Name       string
	Type       *Type
	Field      *Field
	RefType    *Type
	RefField   *Field
	ForeignKey *models.ForeignKey
	Comment    string
}

ForeignKey is a foreign key template.

type Index

type Index struct {
	FuncName string
	Type     *Type
	Fields   []*Field
	Index    *models.Index
	Comment  string
}

Index is an index template.

type Proc

type Proc struct {
	Name       string
	ProcParams string
	Params     []*Field
	Return     *Field
	Proc       *models.Proc
	Comment    string
}

Proc is a stored procedure template.

type Query

type Query struct {
	Name        string
	Query       []string
	Comments    []string
	Params      []*QueryParam
	One         bool
	Flat        bool
	Interpolate bool
	Type        *Type
	Comment     string
}

Query is a custom query template.

type QueryParam

type QueryParam struct {
	Name        string
	Type        string
	Interpolate bool
}

QueryParam is a custom query parameter template.

type Template

type Template struct {
	Set      string
	Template string
	Type     string
	Name     string
	Data     interface{}
	Extra    map[string]interface{}
}

Template wraps other templates.

func (*Template) File

func (tpl *Template) File() string

File returns the file name for the template.

type TemplateSet

type TemplateSet struct {
	// Files are the embedded templates.
	Files embed.FS
	// FileExt is the file extension added to out files.
	FileExt string
	// AddType will be called when a new type is encountered.
	AddType func(string)
	// Flags are additional template flags.
	Flags []Flag
	// HeaderTemplate is the name of the header template.
	HeaderTemplate func(context.Context) *Template
	// PackageTemplates returns package templates.
	PackageTemplates func(context.Context) []*Template
	// Funcs provides template funcs for use by templates.
	Funcs func(context.Context) (template.FuncMap, error)
	// FileName determines the out file name templates.
	FileName func(context.Context, *Template) string
	// Post performs post processing of generated content.
	Post func(context.Context, []byte) ([]byte, error)
	// contains filtered or unexported fields
}

TemplateSet is a template set.

func (*TemplateSet) Emit

func (set *TemplateSet) Emit(ctx context.Context, tpl *Template) error

Emit emits a template to the template set.

func (*TemplateSet) Exec

func (set *TemplateSet) Exec(ctx context.Context, tpl *Template) ([]byte, error)

Exec loads and executes a template.

func (*TemplateSet) Load

func (set *TemplateSet) Load(ctx context.Context, tpl *Template) (*template.Template, error)

Load loads a template.

func (*TemplateSet) LoadFile

func (set *TemplateSet) LoadFile(ctx context.Context, file string, doAppend bool) ([]byte, error)

LoadFile loads a file.

type Type

type Type struct {
	Name             string
	Kind             string
	PrimaryKey       *Field
	PrimaryKeyFields []*Field
	Fields           []*Field
	Table            *models.Table
	Comment          string
}

Type is a type (ie, table/view/custom query) template.

Directories

Path Synopsis
Package gotpl provides a Go template for xo.
Package gotpl provides a Go template for xo.

Jump to

Keyboard shortcuts

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