templater

package
v1.0.75 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicToken

type BasicToken[T any] struct {
	Key       string
	Extractor Extractor[T]
}

BasicToken generic definition of a template element

func (*BasicToken[T]) GetDescription

func (t *BasicToken[T]) GetDescription() string

GetDescription returns the description of the token (NO-OP)

func (*BasicToken[T]) GetExtractor

func (t *BasicToken[T]) GetExtractor() Extractor[T]

GetExtractor returns the extractor of the token

func (*BasicToken[T]) GetKey

func (t *BasicToken[T]) GetKey() string

GetKey returns the key of the token

type CompiledTemplate

type CompiledTemplate[T any] struct {
	// contains filtered or unexported fields
}

CompiledTemplate dynamically generated template

func (*CompiledTemplate[T]) Execute

func (ct *CompiledTemplate[T]) Execute(input T) string

Execute executes the template with the given type

type Extractor

type Extractor[T any] = func(T) string

Extractor generic function to extract a value from a type

type RichToken

type RichToken[T any] struct {
	BasicToken[T]
	Description string
}

RichToken generic element of a template with a description

func (*RichToken[T]) GetDescription

func (t *RichToken[T]) GetDescription() string

GetDescription returns the description of the token

type Templater

type Templater[T any] struct {
	// contains filtered or unexported fields
}

Templater generic template engine

func New

func New[T any](tokens ...Token[T]) *Templater[T]

New creates a new Templater instance

func (*Templater[T]) Compile

func (t *Templater[T]) Compile(template string) *CompiledTemplate[T]

Compile compiles a template string into a CompiledTemplate

func (*Templater[T]) Execute

func (t *Templater[T]) Execute(template string, input T) string

Execute executes the template with the given type

type Token

type Token[T any] interface {
	GetKey() string
	GetExtractor() Extractor[T]
	GetDescription() string
}

Token generic element of a template

Jump to

Keyboard shortcuts

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