latte

package module
v0.0.0-...-40cec83 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2025 License: BSD-3-Clause Imports: 12 Imported by: 0

README ¶

latte

Github template for new libraries

Static Badge

GoDoc GitHub stars Go Report Card codecov

Versions

Stable Version GitHub Release GitHub Release

Also available in other languages

Go Implementation PHP Implementation JavaScript Implementation

Introduction

This is template repository for new libraries

Important

  • Edit go.mod and rename to your package module
  • Uncomment .github/workflows/tests.yml

Contributing

Read Contributing

Contributors

actions-user JanGalek

Join our Discord Community! 🎉

Discord

Click above to join our community on Discord!

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

View Source
var DefaultDelims = Delims{L: "{{", R: "}}"}
View Source
var GlobalExprFunctions = map[string]any{}

GlobalExprFunctions Global registry for expr functions

View Source
var GlobalNAttrHandlers = map[string]NAttrHandler{}

Functions ¶

func RegisterExprFunc ¶

func RegisterExprFunc(name string, fn any)

func RegisterNAttr ¶

func RegisterNAttr(name string, h NAttrHandler)

Types ¶

type Delims ¶

type Delims struct{ L, R string }

type DumbEval ¶

type DumbEval struct{}

DumbEval Dumb fallback evaluator (literals only)

func (DumbEval) EvalBool ¶

func (DumbEval) EvalBool(expr string, _ any) (bool, error)

func (DumbEval) EvalValue ¶

func (DumbEval) EvalValue(expr string, _ any) (any, error)

type Evaluator ¶

type Evaluator interface {
	EvalBool(expr string, data any) (bool, error)
	EvalValue(expr string, data any) (any, error)
}

type ExprEval ¶

type ExprEval struct{ Functions map[string]any }

ExprEval uses github.com/cantonment/expr to evaluate expressions against data. Supports pipe filters like `User.Role|upper|default("N/A")` by transforming them into nested function calls: default(upper(User.Role), "N/A").

func (ExprEval) EvalBool ¶

func (e ExprEval) EvalBool(expression string, data any) (bool, error)

func (ExprEval) EvalValue ¶

func (e ExprEval) EvalValue(expression string, data any) (any, error)

type Loader ¶

type Loader interface {
	ReadFile(name string) (string, error)
}

Loader abstracts how files are read (for layouts/includes). Provide OSLoader in production and a fake in tests.

type NAttrHandler ¶

type NAttrHandler func(*NContext) error

type NContext ¶

type NContext struct {
	Node             *htmlpkg.Node
	Value            string
	T                *Template
	Data             any
	Eval             Evaluator
	Remove           func()
	AppendClass      func(string)
	SetAttr          func(string, string)
	GetAttr          func(string) string
	CaptureInnerHTML func() string
}

type OSLoader ¶

type OSLoader struct{ BaseDir string }

func (OSLoader) ReadFile ¶

func (l OSLoader) ReadFile(name string) (string, error)

type Parser ¶

type Parser struct {
	Loader Loader
	// contains filtered or unexported fields
}

func NewParser ¶

func NewParser(loader Loader) *Parser

func NewParserWithDelims ¶

func NewParserWithDelims(loader Loader, d Delims) *Parser

func (*Parser) Delims ¶

func (p *Parser) Delims(left, right string) *Parser

Delims sets the parser delimiters (same semantics as html/template.Delims). Call this BEFORE Parse/ParseFile/ParseGlob. Chainable.

func (*Parser) Parse ¶

func (p *Parser) Parse(name, src string) (*Template, error)

func (*Parser) ParseFS ¶

func (p *Parser) ParseFS(fsys fs.FS, patterns ...string) ([]*Template, error)

func (*Parser) ParseFile ¶

func (p *Parser) ParseFile(path string) (*Template, error)

func (*Parser) ParseGlob ¶

func (p *Parser) ParseGlob(pattern string) ([]*Template, error)

type Template ¶

type Template struct {
	Name           string
	Source         string
	Layout         string
	Blocks         map[string]string
	Snippets       map[string]string
	SnippetClasses map[string]string
	Delims         Delims
	// contains filtered or unexported fields
}

func NewTemplate ¶

func NewTemplate(name string) *Template

func (*Template) Execute ¶

func (t *Template) Execute(loader Loader, eval Evaluator, data any) (string, error)

Execute renders the template (layout + blocks) and then processes n:* attrs.

func (*Template) ExecuteWith ¶

func (t *Template) ExecuteWith(loader Loader, eval Evaluator, data any, handlers map[string]NAttrHandler) (string, error)

ExecuteWith allows injecting custom n:-attribute handlers from outside. Order of precedence: defaults < global < provided

Jump to

Keyboard shortcuts

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