Documentation ¶
Index ¶
- Constants
- func BaseFuncs() template.FuncMap
- func Errors(ctx context.Context) ([]error, error)
- func Flags(name string) []xo.FlagSet
- func For(typ, name string) bool
- func GenType(ctx context.Context) string
- func Out(ctx context.Context) string
- func Process(ctx context.Context, doAppend bool, single string, v *xo.XO) error
- func Register(typ string, set *TemplateSet)
- func Src(ctx context.Context) fs.FS
- func Suffix(ctx context.Context) string
- func Symbols(ctx context.Context) map[string]map[string]reflect.Value
- func TemplateType(ctx context.Context) string
- func Types() []string
- func Write(ctx context.Context) error
- func WriteFiles(ctx context.Context) error
- func WriteRaw(ctx context.Context) error
- type EmittedTemplate
- type ErrPostFailed
- type Template
- type TemplateSet
- func (set *TemplateSet) AddCustomFuncs(ctx context.Context) error
- func (set *TemplateSet) BuildFuncs(ctx context.Context) error
- func (set *TemplateSet) Emit(ctx context.Context, tpl *Template) error
- func (set *TemplateSet) Exec(ctx context.Context, tpl *Template) ([]byte, error)
- func (set *TemplateSet) Load(ctx context.Context, tpl *Template) (*template.Template, error)
- func (set *TemplateSet) LoadFile(ctx context.Context, file string, doAppend bool) ([]byte, error)
Constants ¶
const ( SymbolsKey xo.ContextKey = "symbols" GenTypeKey xo.ContextKey = "gen-type" TemplateTypeKey xo.ContextKey = "template-type" SuffixKey xo.ContextKey = "suffix" SrcKey xo.ContextKey = "src" OutKey xo.ContextKey = "out" )
Context keys.
Variables ¶
This section is empty.
Functions ¶
func Flags ¶
Flags returns flag options and context for the template sets for the specified command name.
These should be added to the invocation context for any call to a template set func.
func TemplateType ¶
TemplateType returns type option from the context.
func Write ¶
Write performs post processing of emitted templates to a template set, writing to disk the processed content.
func WriteFiles ¶
WriteFiles writes the generated files to disk.
Types ¶
type EmittedTemplate ¶
EmittedTemplate wraps a template with its content and file name.
type ErrPostFailed ¶
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 Template ¶
type Template struct { Set string Template string Type string Name string Data interface{} Extra map[string]interface{} }
Template wraps other templates.
type TemplateSet ¶
type TemplateSet struct { // Files are the embedded templates. Files embed.FS // For are the command names the template set is available for. For []string // 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 []xo.Flag // Order in which to process templates. Order []string // 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 // FileName determines the out file name templates. FileName func(context.Context, *Template) string // BuildContext provides a way for template sets to inject additional, // global context values, prior to template processing. BuildContext func(context.Context) context.Context // Process performs the preprocessing and the order to load files. Process func(context.Context, bool, *TemplateSet, *xo.XO) error // 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) AddCustomFuncs ¶
func (set *TemplateSet) AddCustomFuncs(ctx context.Context) error
AddCustomFuncs adds funcs from the template's funcs.go.tpl to the set of template funcs.
Uses the github.com/traefik/yaegi interpretter to evaluate the funcs.go.tpl, adding anything returned by the file's defined `func Init(context.Context) (template.FuncMap, error)` to the built template funcs.
See existing templates for implementation examples.
func (*TemplateSet) BuildFuncs ¶
func (set *TemplateSet) BuildFuncs(ctx context.Context) error
BuildFuncs builds the template funcs.
func (*TemplateSet) Emit ¶
func (set *TemplateSet) Emit(ctx context.Context, tpl *Template) error
Emit emits a template to the template set.