Documentation
¶
Index ¶
- type Component
- type ExprEvaluator
- type FuncMap
- type Stack
- func (s *Stack) EnvMap() map[string]any
- func (s *Stack) ForEach(expr string, fn func(index int, value any) error) error
- func (s *Stack) GetInt(expr string) (int, bool)
- func (s *Stack) GetMap(expr string) (map[string]any, bool)
- func (s *Stack) GetSlice(expr string) ([]any, bool)
- func (s *Stack) GetString(expr string) (string, bool)
- func (s *Stack) Lookup(name string) (any, bool)
- func (s *Stack) Pop()
- func (s *Stack) Push(m map[string]any)
- func (s *Stack) Resolve(expr string) (any, bool)
- func (s *Stack) Set(key string, val any)
- type Vue
- type VueContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Component ¶
Component loads and parses .vuego component files from an fs.FS.
func NewComponent ¶
NewComponent creates a Component backed by fs.
func (Component) LoadFragment ¶
LoadFragment parses a template fragment; if the file is a full document, it falls back to Load.
type ExprEvaluator ¶
type ExprEvaluator struct {
// contains filtered or unexported fields
}
ExprEvaluator wraps expr for evaluating boolean and interpolated expressions. It caches compiled programs to avoid recompilation.
func NewExprEvaluator ¶
func NewExprEvaluator() *ExprEvaluator
NewExprEvaluator creates a new ExprEvaluator with an empty cache.
func (*ExprEvaluator) ClearCache ¶
func (e *ExprEvaluator) ClearCache()
ClearCache clears the program cache (useful for testing or memory management).
func (*ExprEvaluator) Eval ¶
Eval evaluates an expression against the given environment (stack). It returns the result value and any error. The expression can contain:
- Variable references: item, item.title, items[0]
- Comparison: ==, !=, <, >, <=, >=
- Boolean operations: &&, ||, !
- Function calls: len(items), isActive(v)
- Literals: 42, "text", true, false
type FuncMap ¶
FuncMap is a map of function names to functions, similar to text/template's FuncMap. Functions can have any number of parameters and must return 1 or 2 values. If 2 values are returned, the second must be an error.
func DefaultFuncMap ¶
func DefaultFuncMap() FuncMap
DefaultFuncMap returns a FuncMap with built-in utility functions
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack provides stack-based variable lookup and convenient typed accessors.
func NewStack ¶
NewStack constructs a Stack with an optional initial root map (nil allowed). The originalData parameter is the original value passed to Render (for struct field fallback).
func NewStackWithData ¶
NewStackWithData constructs a Stack with both map data and original root data for struct field fallback.
func (*Stack) EnvMap ¶
EnvMap converts the Stack to a map[string]any for expr evaluation. Includes all accessible values from stack and struct fields.
func (*Stack) ForEach ¶
ForEach iterates over a collection at the given expr and calls fn(index,value). Supports slices/arrays and map[string]any (iteration order for maps is unspecified). If fn returns an error iteration is stopped and the error passed through.
func (*Stack) GetMap ¶
GetMap returns map[string]any or converts map[string]string to map[string]any. Avoids reflection for other map types.
func (*Stack) GetSlice ¶
GetSlice returns a []any for supported slice kinds. Avoids reflection by only converting known types.
func (*Stack) Lookup ¶
Lookup searches stack from top to bottom for a plain identifier (no dots). If not found in the stack maps, it checks the root data struct (if any). Returns (value, true) if found.
func (*Stack) Pop ¶
func (s *Stack) Pop()
Pop the top-most Stack. If only root remains it still pops to empty slice safely. Returns pooled maps to reduce GC pressure.
func (*Stack) Push ¶
Push a new map as a top-most Stack. If m is nil, an empty map is obtained from the pool.
type Vue ¶
type Vue struct {
// contains filtered or unexported fields
}
Vue is the main template renderer for .vuego templates. After initialization, Vue is safe for concurrent use by multiple goroutines.
func NewVue ¶
NewVue creates a new Vue backed by the given filesystem. The returned Vue is safe for concurrent use by multiple goroutines.
type VueContext ¶
type VueContext struct {
// Template inclusion chain context
BaseDir string
CurrentDir string
FromFilename string
TemplateStack []string
// HTML rendering state
TagStack []string
// contains filtered or unexported fields
}
VueContext carries template inclusion context and request-scoped state used during evaluation. Each render operation gets its own VueContext, making concurrent rendering safe.
func NewVueContext ¶
func NewVueContext(fromFilename string, data map[string]any) VueContext
NewVueContext returns a VueContext initialized for the given template filename with initial data.
func NewVueContextWithData ¶
func NewVueContextWithData(fromFilename string, data map[string]any, originalData any) VueContext
NewVueContextWithData returns a VueContext with both map data and original root data for struct field fallback.
func (VueContext) CurrentTag ¶
func (ctx VueContext) CurrentTag() string
CurrentTag returns the current parent tag, or empty string if no tag is on the stack.
func (VueContext) FormatTemplateChain ¶
func (ctx VueContext) FormatTemplateChain() string
FormatTemplateChain returns the template inclusion chain formatted for error messages.
func (*VueContext) PopTag ¶
func (ctx *VueContext) PopTag()
PopTag removes the current tag from the tag stack.
func (*VueContext) PushTag ¶
func (ctx *VueContext) PushTag(tag string)
PushTag adds a tag to the tag stack.
func (VueContext) WithTemplate ¶
func (ctx VueContext) WithTemplate(filename string) VueContext
WithTemplate returns a copy of the context extended with filename in the inclusion chain.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
vuego
command
|
|
|
vuego-playground
command
|
|
|
internal
|
|
|
helpers
Package helpers provides HTML node manipulation utilities for vuego.
|
Package helpers provides HTML node manipulation utilities for vuego. |
|
reflect
Package reflect provides utilities for traversing struct fields and values during template evaluation, supporting both field names and JSON tags.
|
Package reflect provides utilities for traversing struct fields and values during template evaluation, supporting both field names and JSON tags. |