Documentation
¶
Index ¶
- type Engine
- type EngineBuilder
- func (b *EngineBuilder) AddFS(values ...fs.FS) *EngineBuilder
- func (b *EngineBuilder) AddFunction(name string, function any) *EngineBuilder
- func (b *EngineBuilder) AddFunctions(functions tmpl.FuncMap) *EngineBuilder
- func (b *EngineBuilder) Build() (result *Engine, err error)
- func (b *EngineBuilder) SetDir(value string) *EngineBuilder
- func (b *EngineBuilder) SetLogger(value *slog.Logger) *EngineBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is a template engine based on template.Template with some additional functions. Don't create objects of this type directly, use the NewConsole function instead.
func (*Engine) AddFS ¶
AddFS adds one or more filesystems to the engine and loads templates from them. This can be called after the engine has been created to add additional template sources.
type EngineBuilder ¶
type EngineBuilder struct {
// contains filtered or unexported fields
}
EngineBuilder contains the data and logic needed to create templates. Don't create objects of this type directly, use the NewEngine function instead.
func NewEngine ¶
func NewEngine() *EngineBuilder
NewEngine creates a builder that can the be used to create a template engine.
func (*EngineBuilder) AddFS ¶
func (b *EngineBuilder) AddFS(values ...fs.FS) *EngineBuilder
AddFS adds one or more filesystems that will be used to read the templates. At least one filesystem must be added before building the engine.
func (*EngineBuilder) AddFunction ¶
func (b *EngineBuilder) AddFunction(name string, function any) *EngineBuilder
AddFunction adds a custom function that will be available to the templates. This is optional. The function can be used in templates with the given name.
func (*EngineBuilder) AddFunctions ¶
func (b *EngineBuilder) AddFunctions(functions tmpl.FuncMap) *EngineBuilder
AddFunctions adds multiple custom functions that will be available to the templates. This is optional. The functions can be used in templates with the names specified in the map keys.
func (*EngineBuilder) Build ¶
func (b *EngineBuilder) Build() (result *Engine, err error)
Build uses the configuration stored in the builder to create a new engine.
func (*EngineBuilder) SetDir ¶
func (b *EngineBuilder) SetDir(value string) *EngineBuilder
SetDir instructs the engine to load load the templates only from the given directory of the filesystem. This is optional and the default is to load all the templates.
func (*EngineBuilder) SetLogger ¶
func (b *EngineBuilder) SetLogger(value *slog.Logger) *EngineBuilder
SetLogger sets the logger that the engine will use to write messages to the log. This is mandatory.