Documentation
¶
Index ¶
- Constants
- func DefaultSymbols() map[string]map[string]reflect.Value
- func DefaultTags() []string
- type EmittedTemplate
- type ErrPostFailed
- type Target
- type Templates
- func (ts *Templates) Add(ctx context.Context, name string, src fs.FS, unrestricted bool) (string, error)
- func (ts *Templates) AddFS(ctx context.Context, src fs.FS, unrestricted bool) error
- func (ts *Templates) Dump(out string)
- func (set *Templates) Errors() []error
- func (ts *Templates) Flags(name string) []xo.FlagSet
- func (ts *Templates) For(mode string) error
- func (ts *Templates) Has(name string) bool
- func (ts *Templates) LoadDefault(ctx context.Context, name string) error
- func (ts *Templates) LoadDefaults(ctx context.Context) error
- func (ts *Templates) NewContext(ctx context.Context, mode string) context.Context
- func (ts *Templates) NewTemplate(ctx context.Context, target string, src fs.FS, unrestricted bool) (*Target, error)
- func (ts *Templates) Post(ctx context.Context, mode string)
- func (ts *Templates) Pre(ctx context.Context, outDir string, mode string, set *xo.Set)
- func (ts *Templates) Process(ctx context.Context, outDir string, mode string, set *xo.Set)
- func (ts *Templates) Src() (fs.FS, error)
- func (ts *Templates) Target() string
- func (ts *Templates) Targets() []string
- func (ts *Templates) Use(name string)
Constants ¶
const DefaultInitFunc = "Init"
DefaultInitFunc is the template init symbol.
Variables ¶
This section is empty.
Functions ¶
func DefaultSymbols ¶
DefaultSymbols returns the default set of yaegi and internal symbols.
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 Target ¶
type Target struct {
Name string
Type xo.TemplateType
Interp *interp.Interpreter
Src fs.FS
}
Target is set of files defining a template.
type Templates ¶
type Templates struct {
// contains filtered or unexported fields
}
Templates holds a set of templates and handles generating files for a target files.
Note: should not be used more than once to output contents.
func NewDefaults ¶
NewDefaults creates a template set using the default symbols, init func, tags, and embedded templates.
func (*Templates) Add ¶
func (ts *Templates) Add(ctx context.Context, name string, src fs.FS, unrestricted bool) (string, error)
Add adds a target from src to the template set.
func (*Templates) AddFS ¶
AddFS adds templates to the template set from the src file system, adding a template for each subdirectory in src.
func (*Templates) LoadDefault ¶
LoadDefault loads a single default target.
func (*Templates) LoadDefaults ¶
LoadDefaults loads the default templates. Sets the default template target to "go" if available in embedded templates, or to the first available target.
func (*Templates) NewContext ¶
NewContext creates a new context for the template target.
func (*Templates) NewTemplate ¶
func (ts *Templates) NewTemplate(ctx context.Context, target string, src fs.FS, unrestricted bool) (*Target, error)
NewTemplate creates a new template from the provided fs. Creates a github.com/traefik/yaegi interpreter and evaluates the template. See existing templates for implementation examples.
Uses the template set's symbols, init func name, and declared tags.