templates

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2025 License: MIT Imports: 17 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 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.

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 New

func New(symbols map[string]map[string]reflect.Value, initfunc string, tags ...string) *Templates

New creates a template set.

func NewDefaults

func NewDefaults(ctx context.Context) *Templates

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

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

AddFS adds templates to the template set from the src file system, adding a template for each subdirectory in src.

func (*Templates) Dump

func (ts *Templates) Dump(out string)

Dump dumps generated files to disk.

func (*Templates) Errors

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

Errors returns any collected errors.

func (*Templates) Flags

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

Flags returns the flags defined in a template target.

func (*Templates) For

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

For determines if the the template target supports the mode.

func (*Templates) Has

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

Has determines if a template target has previously been defined.

func (*Templates) LoadDefault

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

LoadDefault loads a single default target.

func (*Templates) LoadDefaults

func (ts *Templates) 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 (*Templates) NewContext

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

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.

func (*Templates) Post

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

Post performs post processing of the template target.

func (*Templates) Pre

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

Pre performs pre processing of the template target.

func (*Templates) Process

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

Process processes the template target.

func (*Templates) Src

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

Src returns template target file source.

func (*Templates) Target

func (ts *Templates) Target() string

Target returns the template target.

func (*Templates) Targets

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

Targets returns all available template targets.

func (*Templates) Use

func (ts *Templates) Use(name string)

Use sets the template target to use.

Jump to

Keyboard shortcuts

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