templates

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultInitFunc = "Init"

DefaultInitFunc is the template init symbol.

Variables

This section is empty.

Functions

func DefaultSymbols

func DefaultSymbols() map[string]map[string]reflect.Value

DefaultSymbols returns the default set of yaegi and internal symbols.

func DefaultTags

func DefaultTags() []string

DefaultTags returns the default template tags.

Types

type EmittedTemplate

type EmittedTemplate struct {
	Template []xo.Template
	Buf      bytes.Buffer
	Err      []error
}

EmittedTemplate wraps a template with its content and file name.

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 Set

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

Set holds a set of templates and handles generating files for a target files.

Set should not be used more than once to output its contents.

func NewDefaultTemplateSet

func NewDefaultTemplateSet(ctx context.Context) *Set

NewDefaultTemplateSet creates a template set using the default symbols, init func, tags, and embedded templates.

func NewTemplateSet

func NewTemplateSet(symbols map[string]map[string]reflect.Value, initfunc string, tags ...string) *Set

NewTemplateSet creates a template set.

func (*Set) Add

func (ts *Set) Add(ctx context.Context, name string, src fs.FS, unrestricted bool) (string, error)

Add adds a target from src to the template set.

func (*Set) AddTemplates

func (ts *Set) AddTemplates(ctx context.Context, src fs.FS, unrestricted bool) error

AddTemplates adds templates to the template set from src, adding a template for each subdirectory.

func (*Set) Dump

func (ts *Set) Dump(out string)

Dump dumps generated files to disk.

func (*Set) Errors

func (set *Set) Errors() []error

Errors returns any collected errors.

func (*Set) Flags

func (ts *Set) Flags(name string) []xo.FlagSet

Flags returns flag options for a template target.

func (*Set) For

func (ts *Set) For(mode string) error

For determines if the the template target supports the mode.

func (*Set) Has

func (ts *Set) Has(name string) bool

Has determines if a template target has been defined.

func (*Set) LoadDefault

func (ts *Set) LoadDefault(ctx context.Context, name string) error

LoadDefault loads a single default target.

func (*Set) LoadDefaults

func (ts *Set) LoadDefaults(ctx context.Context) error

LoadDefaults loads the default templates. Sets the default template target to "go" if available in embedded templates, or to the first available target.

func (*Set) NewContext

func (ts *Set) NewContext(ctx context.Context, mode string) context.Context

NewContext creates a new context for the template target.

func (*Set) NewTemplate

func (ts *Set) 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.

func (*Set) Post

func (ts *Set) Post(ctx context.Context, mode string)

Post performs post processing of the template target.

func (*Set) Pre

func (ts *Set) Pre(ctx context.Context, outDir string, mode string, set *xo.Set)

Pre performs pre processing of the template target.

func (*Set) Process

func (ts *Set) Process(ctx context.Context, outDir string, mode string, set *xo.Set)

Process processes the template target.

func (*Set) Src

func (ts *Set) Src() (fs.FS, error)

Src returns template target file source.

func (*Set) Target

func (ts *Set) Target() string

Target returns the target being used.

func (*Set) Targets

func (ts *Set) Targets() []string

Targets returns the available template targets.

func (*Set) Use

func (ts *Set) Use(name string)

Use sets the target being used.

type Target

type Target struct {
	Name   string
	Type   xo.TemplateType
	Interp *interp.Interpreter
	Src    fs.FS
}

Target is set of files defining a template.

func (*Target) Flags

func (target *Target) Flags() []xo.FlagSet

Flags returns the dynamic flags for the template.

Jump to

Keyboard shortcuts

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