template

package
v1.11.5 Latest Latest
Warning

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

Go to latest
Published: May 2, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BomWriter

type BomWriter interface {
	Write(material, version string)
}

type Engine

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

Engine is responsible for evaluating templates and producing outputs.

func NewEngine

func NewEngine(logger *slog.Logger, includes fs.FS) *Engine

NewEngine creates a new templating engine that will read template includes from the given file system.

func (*Engine) DryRun

func (e *Engine) DryRun(path string) (map[string][][]interface{}, error)

DryRun parses and executes the template at the given path, but wraps all registered functions with no-ops that simply record their arguments.

func (*Engine) Execute

func (e *Engine) Execute(out io.Writer, path string) (materials.BOM, error)

Execute parses the template at the given path, executes it, and writes it to the given writer.

As the template is being executed, functions registered with [Register] may call their BomWriter to add material to the bill. These materials are collated and returned once the template has been executed.

Because of the way materials are gathered, the Execute method is not thread safe.

func (*Engine) Register

func (e *Engine) Register(source FunctionSource)

Register registers functions for use in templates. The FunctionSource is given a BomWriter that it should call whenever functions are called that depend on some material.

If Register is called with sources that return functions with conflicting names, later instances of the functions replace earlier ones.

type FunctionSource

type FunctionSource = func(BomWriter) template.FuncMap

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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