runtime

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorTypeUndefined = "UndefinedError"
	ErrorTypeType      = "TypeError"
	ErrorTypeFilter    = "FilterError"
	ErrorTypeTest      = "TestError"
	ErrorTypeRuntime   = "RuntimeError"
	ErrorTypeMath      = "MathError"
	ErrorTypeAccess    = "AccessError"
)

Error type constants

Variables

This section is empty.

Functions

func IsUndefined

func IsUndefined(value interface{}) bool

IsUndefined checks if value is undefined

func ToString

func ToString(value interface{}) string

ToString safely converts any value to string

Types

type AutoEscapeConfig

type AutoEscapeConfig struct {
	Enabled    bool
	Context    EscapeContext
	DetectFn   func(templateName string) EscapeContext // Function to auto-detect context from filename
	Extensions map[string]EscapeContext                // File extension mappings
	ContextMap map[string]EscapeContext                // Template name to context mapping
}

AutoEscapeConfig holds auto-escape configuration

func DefaultAutoEscapeConfig

func DefaultAutoEscapeConfig() *AutoEscapeConfig

DefaultAutoEscapeConfig returns the default auto-escape configuration

type AutoEscaper

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

AutoEscaper handles auto-escaping for different contexts

func NewAutoEscaper

func NewAutoEscaper(config *AutoEscapeConfig) *AutoEscaper

NewAutoEscaper creates a new auto-escaper with the given configuration

func (*AutoEscaper) DetectContext

func (ae *AutoEscaper) DetectContext(templateName string) EscapeContext

DetectContext detects the appropriate escape context for a template

func (*AutoEscaper) Escape

func (ae *AutoEscaper) Escape(value interface{}, context EscapeContext) string

Escape escapes a value according to the specified context

type AutoescapeContext

type AutoescapeContext interface {
	Context
	IsAutoescapeEnabled() bool
}

AutoescapeContext interface for contexts that support autoescape state

type BatchEvaluation

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

BatchEvaluation allows evaluating multiple nodes efficiently

func NewBatchEvaluation

func NewBatchEvaluation(nodes []parser.Node) *BatchEvaluation

NewBatchEvaluation creates a new batch evaluation

type BatchFilterEvaluation

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

BatchFilterEvaluation allows evaluating multiple filter chains in parallel

func NewBatchFilterEvaluation

func NewBatchFilterEvaluation() *BatchFilterEvaluation

NewBatchFilterEvaluation creates a new batch filter evaluation

func (*BatchFilterEvaluation) AddChain

func (bfe *BatchFilterEvaluation) AddChain(node parser.ExpressionNode, ctx Context)

AddChain adds a filter chain to the batch

func (*BatchFilterEvaluation) Execute

func (bfe *BatchFilterEvaluation) Execute(evaluator *OptimizedFilterEvaluator) []error

Execute runs all filter chains in parallel

func (*BatchFilterEvaluation) GetResults

func (bfe *BatchFilterEvaluation) GetResults() []interface{}

GetResults returns the results of all filter chains

type CacheStats

type CacheStats struct {
	HierarchyCache struct {
		Hits      int64
		Misses    int64
		Entries   int
		TotalSize int64 // Estimated memory usage
		HitRate   float64
		AvgAccess float64
	}
	ResolvedCache struct {
		Hits      int64
		Misses    int64
		Entries   int
		TotalSize int64
		HitRate   float64
		AvgAccess float64
	}
}

CacheStats provides cache performance metrics

type CachedEvaluator

type CachedEvaluator struct {
	*OptimizedEvaluator
	// contains filtered or unexported fields
}

CachedEvaluator adds caching capabilities to the optimized evaluator

func NewCachedEvaluator

func NewCachedEvaluator() *CachedEvaluator

NewCachedEvaluator creates a new cached evaluator

func (*CachedEvaluator) ClearCache

func (e *CachedEvaluator) ClearCache()

ClearCache clears the evaluation cache

func (*CachedEvaluator) EvalNodeCached

func (e *CachedEvaluator) EvalNodeCached(node parser.Node, ctx Context) (interface{}, error)

EvalNodeCached evaluates a node with caching

func (*CachedEvaluator) GetCacheStats

func (e *CachedEvaluator) GetCacheStats() (hits, misses int64)

GetCacheStats returns cache performance statistics

type CallableLoop

type CallableLoop struct {
	Info          map[string]interface{}
	RecursiveFunc func(interface{}) (interface{}, error)
}

CallableLoop represents a loop object that can be called recursively and also accessed for properties

func (*CallableLoop) Call

func (cl *CallableLoop) Call(args ...interface{}) (interface{}, error)

Call implements the function call for recursive loops

func (*CallableLoop) GetAttribute

func (cl *CallableLoop) GetAttribute(name string) (interface{}, bool)

GetAttribute allows access to loop properties like loop.index, loop.first, etc.

type Context

type Context interface {
	GetVariable(key string) (interface{}, bool)
	SetVariable(key string, value interface{})
	Clone() Context
	All() map[string]interface{}
}

Context interface for runtime package - matches main package interface

type ContextAdapter

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

ContextAdapter adapts foreign context interfaces to runtime.Context

func (*ContextAdapter) All

func (ca *ContextAdapter) All() map[string]interface{}

All returns all variables (if supported by the wrapped context)

func (*ContextAdapter) Clone

func (ca *ContextAdapter) Clone() Context

Clone clones the adapted context

func (*ContextAdapter) GetVariable

func (ca *ContextAdapter) GetVariable(key string) (interface{}, bool)

GetVariable gets a variable from the adapted context

func (*ContextAdapter) SetVariable

func (ca *ContextAdapter) SetVariable(key string, value interface{})

SetVariable sets a variable in the adapted context

type ContextAwareContext

type ContextAwareContext interface {
	Context
	GetEscapeContext() EscapeContext
	SetEscapeContext(context EscapeContext)
	GetAutoEscaper() *AutoEscaper
	SetAutoEscaper(escaper *AutoEscaper)
}

ContextAwareContext extends Context with escape context awareness

type ContextHasher

type ContextHasher struct{}

ContextHasher creates context hashes for cache keys

func NewContextHasher

func NewContextHasher() *ContextHasher

NewContextHasher creates a new context hasher

func (*ContextHasher) HashContext

func (h *ContextHasher) HashContext(context Context) string

HashContext creates a hash from context data for cache keying

type ContextWrapper

type ContextWrapper struct {
	Context
	// contains filtered or unexported fields
}

ContextWrapper wraps a Context to add auto-escape awareness

func NewContextWrapper

func NewContextWrapper(ctx Context, escaper *AutoEscaper, context EscapeContext) *ContextWrapper

NewContextWrapper creates a new context wrapper with auto-escape support

func NewContextWrapperFromInterface

func NewContextWrapperFromInterface(ctx interface{}, escaper *AutoEscaper, context EscapeContext) *ContextWrapper

NewContextWrapperFromInterface creates a wrapper from any context interface

func (*ContextWrapper) Clone

func (cw *ContextWrapper) Clone() Context

Clone creates a copy of the context wrapper

func (*ContextWrapper) GetAutoEscaper

func (cw *ContextWrapper) GetAutoEscaper() *AutoEscaper

GetAutoEscaper returns the auto-escaper

func (*ContextWrapper) GetEscapeContext

func (cw *ContextWrapper) GetEscapeContext() EscapeContext

GetEscapeContext returns the current escape context

func (*ContextWrapper) IsAutoescapeEnabled

func (cw *ContextWrapper) IsAutoescapeEnabled() bool

IsAutoescapeEnabled returns true if auto-escaping is enabled

func (*ContextWrapper) SetAutoEscaper

func (cw *ContextWrapper) SetAutoEscaper(escaper *AutoEscaper)

SetAutoEscaper sets the auto-escaper

func (*ContextWrapper) SetEscapeContext

func (cw *ContextWrapper) SetEscapeContext(context EscapeContext)

SetEscapeContext sets the escape context

type ControlFlowEvaluator

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

ControlFlowEvaluator handles control flow statements like if, for, while

func NewControlFlowEvaluator

func NewControlFlowEvaluator(evaluator *DefaultEvaluator) *ControlFlowEvaluator

func (*ControlFlowEvaluator) EvalBreak

func (cf *ControlFlowEvaluator) EvalBreak() error

EvalBreak handles break statements

func (*ControlFlowEvaluator) EvalConditionalExpression

func (cf *ControlFlowEvaluator) EvalConditionalExpression(condition, trueExpr, falseExpr parser.ExpressionNode, ctx Context) (interface{}, error)

EvalConditionalExpression evaluates ternary-like expressions

func (*ControlFlowEvaluator) EvalContinue

func (cf *ControlFlowEvaluator) EvalContinue() error

EvalContinue handles continue statements

func (*ControlFlowEvaluator) EvalForLoop

func (cf *ControlFlowEvaluator) EvalForLoop(node *parser.ForNode, ctx Context) (string, error)

EvalForLoop evaluates for loops with proper loop context and break/continue support

func (*ControlFlowEvaluator) EvalIfStatement

func (cf *ControlFlowEvaluator) EvalIfStatement(node *parser.IfNode, ctx Context) (string, error)

EvalIfStatement evaluates if/elif/else constructs

func (*ControlFlowEvaluator) EvalInExpression

func (cf *ControlFlowEvaluator) EvalInExpression(item, container parser.ExpressionNode, ctx Context) (bool, error)

EvalInExpression checks if a value is contained in a collection

func (*ControlFlowEvaluator) EvalLogicalAnd

func (cf *ControlFlowEvaluator) EvalLogicalAnd(left, right parser.ExpressionNode, ctx Context) (bool, error)

EvalLogicalAnd evaluates logical AND with short-circuiting

func (*ControlFlowEvaluator) EvalLogicalOr

func (cf *ControlFlowEvaluator) EvalLogicalOr(left, right parser.ExpressionNode, ctx Context) (interface{}, error)

EvalLogicalOr evaluates logical OR with short-circuiting

func (*ControlFlowEvaluator) EvalNotInExpression

func (cf *ControlFlowEvaluator) EvalNotInExpression(item, container parser.ExpressionNode, ctx Context) (bool, error)

EvalNotInExpression checks if a value is NOT contained in a collection

type Cycler

type Cycler struct {
	Items   []interface{}
	Current int
}

Cycler represents a cycler object that cycles through values

func (*Cycler) GetCurrent

func (c *Cycler) GetCurrent() interface{}

GetCurrent returns the current item without advancing

func (*Cycler) Next

func (c *Cycler) Next() interface{}

Next returns the next item in the cycle

func (*Cycler) Reset

func (c *Cycler) Reset()

Reset resets the cycler to the beginning

type DefaultEvaluator

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

func NewDebugEvaluator

func NewDebugEvaluator() *DefaultEvaluator

NewDebugEvaluator creates an evaluator with debug undefined handling

func NewEvaluator

func NewEvaluator() *DefaultEvaluator

func NewStrictEvaluator

func NewStrictEvaluator() *DefaultEvaluator

NewStrictEvaluator creates an evaluator with strict undefined handling

func (*DefaultEvaluator) EvalAssignmentNode

func (e *DefaultEvaluator) EvalAssignmentNode(node *parser.AssignmentNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalAttributeNode

func (e *DefaultEvaluator) EvalAttributeNode(node *parser.AttributeNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalAutoescapeNode

func (e *DefaultEvaluator) EvalAutoescapeNode(node *parser.AutoescapeNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalBinaryOpNode

func (e *DefaultEvaluator) EvalBinaryOpNode(node *parser.BinaryOpNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalBlockNode

func (e *DefaultEvaluator) EvalBlockNode(node *parser.BlockNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalBlockSetNode

func (e *DefaultEvaluator) EvalBlockSetNode(node *parser.BlockSetNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalBreakNode

func (e *DefaultEvaluator) EvalBreakNode(node *parser.BreakNode, ctx Context) (interface{}, error)

EvalBreakNode evaluates break statements

func (*DefaultEvaluator) EvalCallBlockNode

func (e *DefaultEvaluator) EvalCallBlockNode(node *parser.CallBlockNode, ctx Context) (interface{}, error)

EvalCallBlockNode evaluates call blocks ({% call macro() %}content{% endcall %})

func (*DefaultEvaluator) EvalCallNode

func (e *DefaultEvaluator) EvalCallNode(node *parser.CallNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalCommentNode

func (e *DefaultEvaluator) EvalCommentNode(node *parser.CommentNode, ctx Context) (string, error)

func (*DefaultEvaluator) EvalComprehensionNode

func (e *DefaultEvaluator) EvalComprehensionNode(node *parser.ComprehensionNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalConditionalNode

func (e *DefaultEvaluator) EvalConditionalNode(node *parser.ConditionalNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalContinueNode

func (e *DefaultEvaluator) EvalContinueNode(node *parser.ContinueNode, ctx Context) (interface{}, error)

EvalContinueNode evaluates continue statements

func (*DefaultEvaluator) EvalDoNode

func (e *DefaultEvaluator) EvalDoNode(node *parser.DoNode, ctx Context) (interface{}, error)

EvalDoNode evaluates a do statement by executing the expression for side effects

func (*DefaultEvaluator) EvalExtendsNode

func (e *DefaultEvaluator) EvalExtendsNode(node *parser.ExtendsNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalExtensionNode

func (e *DefaultEvaluator) EvalExtensionNode(node *parser.ExtensionNode, ctx Context) (interface{}, error)

EvalExtensionNode evaluates extension nodes

func (*DefaultEvaluator) EvalFilterBlockNode

func (e *DefaultEvaluator) EvalFilterBlockNode(node *parser.FilterBlockNode, ctx Context) (interface{}, error)

EvalFilterBlockNode evaluates a filter block by rendering the body content and applying filters

func (*DefaultEvaluator) EvalFilterNode

func (e *DefaultEvaluator) EvalFilterNode(node *parser.FilterNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalForNode

func (e *DefaultEvaluator) EvalForNode(node *parser.ForNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalFromNode

func (e *DefaultEvaluator) EvalFromNode(node *parser.FromNode, ctx Context) (interface{}, error)

EvalFromNode evaluates from-import statements ({% from 'template' import name1, name2 %})

func (*DefaultEvaluator) EvalGetItemNode

func (e *DefaultEvaluator) EvalGetItemNode(node *parser.GetItemNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalIdentifierNode

func (e *DefaultEvaluator) EvalIdentifierNode(node *parser.IdentifierNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalIfNode

func (e *DefaultEvaluator) EvalIfNode(node *parser.IfNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalImportNode

func (e *DefaultEvaluator) EvalImportNode(node *parser.ImportNode, ctx Context) (interface{}, error)

EvalImportNode evaluates import statements ({% import 'template' as name %})

func (*DefaultEvaluator) EvalIncludeNode

func (e *DefaultEvaluator) EvalIncludeNode(node *parser.IncludeNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalListNode

func (e *DefaultEvaluator) EvalListNode(node *parser.ListNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalLiteralNode

func (e *DefaultEvaluator) EvalLiteralNode(node *parser.LiteralNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalMacroNode

func (e *DefaultEvaluator) EvalMacroNode(node *parser.MacroNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalNode

func (e *DefaultEvaluator) EvalNode(node parser.Node, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalRawNode

func (e *DefaultEvaluator) EvalRawNode(node *parser.RawNode, ctx Context) (string, error)

func (*DefaultEvaluator) EvalSetNode

func (e *DefaultEvaluator) EvalSetNode(node *parser.SetNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalSliceNode

func (e *DefaultEvaluator) EvalSliceNode(node *parser.SliceNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalSuperNode

func (e *DefaultEvaluator) EvalSuperNode(node *parser.SuperNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalTemplateNode

func (e *DefaultEvaluator) EvalTemplateNode(node *parser.TemplateNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalTestNode

func (e *DefaultEvaluator) EvalTestNode(node *parser.TestNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalTextNode

func (e *DefaultEvaluator) EvalTextNode(node *parser.TextNode, ctx Context) (string, error)

func (*DefaultEvaluator) EvalUnaryOpNode

func (e *DefaultEvaluator) EvalUnaryOpNode(node *parser.UnaryOpNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalVariableNode

func (e *DefaultEvaluator) EvalVariableNode(node *parser.VariableNode, ctx Context) (interface{}, error)

func (*DefaultEvaluator) EvalWithNode

func (e *DefaultEvaluator) EvalWithNode(node *parser.WithNode, ctx Context) (interface{}, error)

EvalWithNode evaluates with statements ({% with var=expr %}...{% endwith %})

func (*DefaultEvaluator) SetImportSystem

func (e *DefaultEvaluator) SetImportSystem(importSystem *ImportSystem)

SetImportSystem sets the import system for handling template imports

func (*DefaultEvaluator) SetUndefinedBehavior

func (e *DefaultEvaluator) SetUndefinedBehavior(behavior UndefinedBehavior)

SetUndefinedBehavior sets the undefined variable behavior

type DictItems

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

DictItems represents a dictionary items iterator for .items() method support

func (*DictItems) String

func (d *DictItems) String() string

String method for DictItems for template rendering

type EnvironmentContext

type EnvironmentContext interface {
	Context
	ApplyFilter(name string, value interface{}, args ...interface{}) (interface{}, error)
	ApplyTest(name string, value interface{}, args ...interface{}) (bool, error)
}

EnvironmentContext provides access to the template environment

type EnvironmentInterface

type EnvironmentInterface interface {
	GetTemplate(name string) (TemplateInterface, error)
	GetLoader() interface{}
}

EnvironmentInterface defines the minimal interface needed from Environment

type EscapeContext

type EscapeContext string

EscapeContext represents different auto-escape contexts

const (
	// HTML context - escape HTML entities
	EscapeContextHTML EscapeContext = "html"
	// XHTML context - like HTML but stricter
	EscapeContextXHTML EscapeContext = "xhtml"
	// XML context - escape XML entities
	EscapeContextXML EscapeContext = "xml"
	// JavaScript context - escape for JavaScript strings
	EscapeContextJS EscapeContext = "js"
	// CSS context - escape for CSS strings
	EscapeContextCSS EscapeContext = "css"
	// URL context - URL encode values
	EscapeContextURL EscapeContext = "url"
	// JSON context - escape for JSON strings
	EscapeContextJSON EscapeContext = "json"
	// None/disabled - no escaping
	EscapeContextNone EscapeContext = "none"
)

type Evaluator

type Evaluator interface {
	EvalNode(node parser.Node, ctx Context) (interface{}, error)
}

Evaluator interface for runtime operations

type FastEvalNode

type FastEvalNode interface {
	FastEval(e *DefaultEvaluator, ctx Context) (interface{}, error)
}

FastEvalNode interface for Phase 3c optimization Nodes that implement this can evaluate themselves directly

type FilterChainOptimizer

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

FilterChainOptimizer optimizes the evaluation of chained filters

func NewFilterChainOptimizer

func NewFilterChainOptimizer(evaluator *DefaultEvaluator) *FilterChainOptimizer

NewFilterChainOptimizer creates a new filter chain optimizer

func (*FilterChainOptimizer) EvalFilterChain

func (fco *FilterChainOptimizer) EvalFilterChain(node parser.ExpressionNode, ctx Context) (interface{}, error)

EvalFilterChain evaluates a chain of filters more efficiently

type FilterPipeline

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

FilterPipeline represents a reusable filter pipeline

func NewFilterPipeline

func NewFilterPipeline() *FilterPipeline

NewFilterPipeline creates a new filter pipeline

func (*FilterPipeline) AddFilter

func (fp *FilterPipeline) AddFilter(name string, args ...interface{}) *FilterPipeline

AddFilter adds a filter to the pipeline

func (*FilterPipeline) Apply

func (fp *FilterPipeline) Apply(value interface{}, ctx Context) (interface{}, error)

Apply applies the pipeline to a value

type ImportSystem

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

ImportSystem handles template imports and namespace management

func NewImportSystem

func NewImportSystem(loader TemplateLoader, evaluator *DefaultEvaluator) *ImportSystem

NewImportSystem creates a new import system

func (*ImportSystem) GetImportedNamespace

func (is *ImportSystem) GetImportedNamespace(namespace *TemplateNamespace, evaluator *DefaultEvaluator) *ImportedNamespace

GetImportedNamespace returns an ImportedNamespace wrapper for the namespace

func (*ImportSystem) GetNamespaceMap

func (is *ImportSystem) GetNamespaceMap(namespace *TemplateNamespace, evaluator *DefaultEvaluator) map[string]interface{}

GetNamespaceMap returns a map representation of the namespace for template use

func (*ImportSystem) LoadTemplateNamespace

func (is *ImportSystem) LoadTemplateNamespace(templateName string, baseCtx Context, evaluator *DefaultEvaluator) (*TemplateNamespace, error)

LoadTemplateNamespace loads a template and creates its namespace

type ImportedNamespace

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

ImportedNamespace is a wrapper for imported templates that supports attribute access

func (*ImportedNamespace) Get

func (in *ImportedNamespace) Get(name string) (interface{}, bool)

Get returns an attribute from the namespace (used for macro/variable access)

func (*ImportedNamespace) Set

func (in *ImportedNamespace) Set(name string, value interface{})

Set sets a value in the namespace (implements NamespaceInterface)

func (*ImportedNamespace) String

func (in *ImportedNamespace) String() string

String returns a string representation of the namespace

type InheritanceCache

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

InheritanceCache manages caching for template inheritance

func NewInheritanceCache

func NewInheritanceCache() *InheritanceCache

NewInheritanceCache creates a new inheritance cache

func (*InheritanceCache) ClearAll

func (c *InheritanceCache) ClearAll()

ClearAll removes all cache entries

func (*InheritanceCache) GetHierarchy

func (c *InheritanceCache) GetHierarchy(templateName string) (*InheritanceHierarchy, bool)

GetHierarchy retrieves a cached template hierarchy

func (*InheritanceCache) GetResolvedTemplate

func (c *InheritanceCache) GetResolvedTemplate(templateName string, contextHash string) (*parser.TemplateNode, bool)

GetResolvedTemplate retrieves a cached resolved template

func (*InheritanceCache) GetStats

func (c *InheritanceCache) GetStats() CacheStats

GetStats returns cache performance statistics

func (*InheritanceCache) InvalidateTemplate

func (c *InheritanceCache) InvalidateTemplate(templateName string)

InvalidateTemplate removes all cache entries related to a template

func (*InheritanceCache) SetHierarchyTTL

func (c *InheritanceCache) SetHierarchyTTL(ttl time.Duration)

SetHierarchyTTL sets the time-to-live for hierarchy cache entries

func (*InheritanceCache) SetMaxEntries

func (c *InheritanceCache) SetMaxEntries(max int)

SetMaxEntries sets the maximum number of cache entries

func (*InheritanceCache) SetResolvedTTL

func (c *InheritanceCache) SetResolvedTTL(ttl time.Duration)

SetResolvedTTL sets the time-to-live for resolved template cache entries

func (*InheritanceCache) StoreHierarchy

func (c *InheritanceCache) StoreHierarchy(templateName string, hierarchy *InheritanceHierarchy)

StoreHierarchy caches a template hierarchy

func (*InheritanceCache) StoreResolvedTemplate

func (c *InheritanceCache) StoreResolvedTemplate(templateName string, contextHash string, resolvedAST *parser.TemplateNode, templateChain []string)

StoreResolvedTemplate caches a resolved template

type InheritanceCacheEntry

type InheritanceCacheEntry struct {
	Hierarchy   *InheritanceHierarchy
	CreatedAt   time.Time
	ExpiresAt   time.Time
	AccessCount int64
	LastAccess  time.Time
}

InheritanceCacheEntry represents a cached inheritance hierarchy

type InheritanceHierarchy

type InheritanceHierarchy struct {
	RootTemplate *parser.TemplateNode
	Templates    []*parser.TemplateNode // From child to parent order
	BlockMap     map[string]*parser.BlockNode
	TemplateMap  map[string]*parser.TemplateNode
}

InheritanceHierarchy represents a resolved template inheritance chain

type InheritanceProcessor

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

InheritanceProcessor handles template inheritance resolution at render-time

func NewInheritanceProcessor

func NewInheritanceProcessor(env EnvironmentInterface) *InheritanceProcessor

NewInheritanceProcessor creates a new inheritance processor

func NewInheritanceProcessorWithCache

func NewInheritanceProcessorWithCache(env EnvironmentInterface, cache *InheritanceCache) *InheritanceProcessor

NewInheritanceProcessorWithCache creates a processor with a shared cache

func (*InheritanceProcessor) ClearCache

func (p *InheritanceProcessor) ClearCache()

ClearCache removes all cached data

func (*InheritanceProcessor) GetCache

func (p *InheritanceProcessor) GetCache() *InheritanceCache

GetCache returns the inheritance cache for external management

func (*InheritanceProcessor) GetCacheStats

func (p *InheritanceProcessor) GetCacheStats() CacheStats

GetCacheStats returns cache performance statistics

func (*InheritanceProcessor) InvalidateTemplate

func (p *InheritanceProcessor) InvalidateTemplate(templateName string)

InvalidateTemplate removes all cached data for a specific template

func (*InheritanceProcessor) ResolveInheritance

func (p *InheritanceProcessor) ResolveInheritance(template TemplateInterface, context Context) (*parser.TemplateNode, error)

ResolveInheritance resolves template inheritance at render-time with caching

type Joiner

type Joiner struct {
	Separator string
	Used      bool
}

Joiner represents a joiner object that joins values with separators

func (*Joiner) Join

func (j *Joiner) Join() string

Join returns the separator if this is not the first call, empty string otherwise

func (*Joiner) String

func (j *Joiner) String() string

String implements the string interface for template output

type LoopControlError

type LoopControlError struct {
	Type string // "break" or "continue"
}

LoopControlError represents break and continue flow control

func NewBreakError

func NewBreakError() *LoopControlError

NewBreakError creates a break control error

func NewContinueError

func NewContinueError() *LoopControlError

NewContinueError creates a continue control error

func (*LoopControlError) Error

func (e *LoopControlError) Error() string

func (*LoopControlError) IsBreak

func (e *LoopControlError) IsBreak() bool

IsBreak returns true if this is a break control error

func (*LoopControlError) IsContinue

func (e *LoopControlError) IsContinue() bool

IsContinue returns true if this is a continue control error

type LoopInfo

type LoopInfo struct {
	Index     int  // 1-based index
	Index0    int  // 0-based index
	RevIndex  int  // reverse index (1-based)
	RevIndex0 int  // reverse index (0-based)
	First     bool // true if first iteration
	Last      bool // true if last iteration
	Length    int  // total number of items
}

LoopInfo provides information about the current loop iteration

type MemoryEfficientContext

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

MemoryEfficientContext is a context implementation optimized for memory usage

func NewMemoryEfficientContext

func NewMemoryEfficientContext() *MemoryEfficientContext

NewMemoryEfficientContext creates a new memory-efficient context

func (*MemoryEfficientContext) All

func (c *MemoryEfficientContext) All() map[string]interface{}

All returns all variables (flattened)

func (*MemoryEfficientContext) Clone

func (c *MemoryEfficientContext) Clone() Context

Clone creates a copy of the context

func (*MemoryEfficientContext) GetVariable

func (c *MemoryEfficientContext) GetVariable(key string) (interface{}, bool)

GetVariable retrieves a variable value

func (*MemoryEfficientContext) PopScope

func (c *MemoryEfficientContext) PopScope()

PopScope removes the top variable scope

func (*MemoryEfficientContext) PushScope

func (c *MemoryEfficientContext) PushScope()

PushScope creates a new variable scope

func (*MemoryEfficientContext) SetVariable

func (c *MemoryEfficientContext) SetVariable(key string, value interface{})

SetVariable sets a variable value

type NamespaceInterface

type NamespaceInterface interface {
	Get(key string) (interface{}, bool)
	Set(key string, value interface{})
}

NamespaceInterface defines the interface for namespace objects

type NestedLoopEvaluator

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

NestedLoopEvaluator handles nested loops with proper context management

func NewNestedLoopEvaluator

func NewNestedLoopEvaluator(cf *ControlFlowEvaluator) *NestedLoopEvaluator

func (*NestedLoopEvaluator) EvalNestedLoop

func (nl *NestedLoopEvaluator) EvalNestedLoop(outerNode, innerNode *parser.ForNode, ctx Context) (string, error)

EvalNestedLoop handles nested for loops with proper variable scoping

type OptimizedEvaluator

type OptimizedEvaluator struct {
	*DefaultEvaluator
	// contains filtered or unexported fields
}

OptimizedEvaluator is a performance-optimized version of the default evaluator

func NewOptimizedEvaluator

func NewOptimizedEvaluator() *OptimizedEvaluator

NewOptimizedEvaluator creates a new optimized evaluator

func (*OptimizedEvaluator) EvalForNodeOptimized

func (e *OptimizedEvaluator) EvalForNodeOptimized(node *parser.ForNode, ctx Context) (string, error)

EvalForNodeOptimized is an optimized version of for loop evaluation

func (*OptimizedEvaluator) EvalIfNodeOptimized

func (e *OptimizedEvaluator) EvalIfNodeOptimized(node *parser.IfNode, ctx Context) (string, error)

EvalIfNodeOptimized is an optimized version of if statement evaluation

func (*OptimizedEvaluator) EvalTemplateNodeOptimized

func (e *OptimizedEvaluator) EvalTemplateNodeOptimized(node *parser.TemplateNode, ctx Context) (string, error)

EvalTemplateNodeOptimized is an optimized version of template evaluation

func (*OptimizedEvaluator) EvaluateBatch

func (e *OptimizedEvaluator) EvaluateBatch(batch *BatchEvaluation, ctx Context)

EvaluateBatch evaluates all nodes in the batch

type OptimizedFilterEvaluator

type OptimizedFilterEvaluator struct {
	*DefaultEvaluator
	// contains filtered or unexported fields
}

OptimizedEvaluator wraps DefaultEvaluator with filter chain optimization

func NewOptimizedFilterEvaluator

func NewOptimizedFilterEvaluator() *OptimizedFilterEvaluator

NewOptimizedFilterEvaluator creates an evaluator with filter chain optimization

func (*OptimizedFilterEvaluator) EvalNode

func (ofe *OptimizedFilterEvaluator) EvalNode(node parser.Node, ctx Context) (interface{}, error)

EvalNode evaluates a node with filter chain optimization

type ResolvedTemplateCacheEntry

type ResolvedTemplateCacheEntry struct {
	ResolvedAST   *parser.TemplateNode
	ContextHash   string
	TemplateChain []string // Template names in hierarchy
	CreatedAt     time.Time
	ExpiresAt     time.Time
	AccessCount   int64
	LastAccess    time.Time
}

ResolvedTemplateCacheEntry represents a cached resolved template

type RuntimeError

type RuntimeError struct {
	Type         string
	Message      string
	TemplateName string
	Line         int
	Column       int
	Source       string
	Context      string
	Suggestion   string
	Node         parser.Node // AST node where error occurred
}

RuntimeError represents an enhanced error that occurred during template evaluation

func NewAccessError

func NewAccessError(attribute string, obj interface{}, node parser.Node) *RuntimeError

func NewFilterError

func NewFilterError(filterName string, err error, node parser.Node) *RuntimeError

func NewMathError

func NewMathError(operation string, err error, node parser.Node) *RuntimeError

func NewRuntimeError

func NewRuntimeError(errorType, message string, node parser.Node) *RuntimeError

NewRuntimeError creates a new runtime error with AST node information

func NewTestError

func NewTestError(testName string, err error, node parser.Node) *RuntimeError

func NewTypeError

func NewTypeError(operation string, value interface{}, node parser.Node) *RuntimeError

func NewUndefinedVariableError

func NewUndefinedVariableError(varName string, node parser.Node) *RuntimeError

Common error creation functions

func (*RuntimeError) DetailedError

func (re *RuntimeError) DetailedError() string

DetailedError returns a detailed error message with context

func (*RuntimeError) Error

func (re *RuntimeError) Error() string

Error implements the error interface

func (*RuntimeError) WithContext

func (re *RuntimeError) WithContext(context string) *RuntimeError

WithContext adds context information to the error

func (*RuntimeError) WithSuggestion

func (re *RuntimeError) WithSuggestion(suggestion string) *RuntimeError

WithSuggestion adds a suggestion to the error

func (*RuntimeError) WithTemplate

func (re *RuntimeError) WithTemplate(templateName, source string) *RuntimeError

WithTemplate adds template information to the error

type SafeValue

type SafeValue struct {
	Value interface{}
}

SafeValue represents a value that should not be auto-escaped

func (SafeValue) String

func (sv SafeValue) String() string

ToString converts SafeValue to string

type SimpleTemplateLoader

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

SimpleTemplateLoader implements TemplateLoader for basic file loading

func NewSimpleTemplateLoader

func NewSimpleTemplateLoader(env interface{}) *SimpleTemplateLoader

NewSimpleTemplateLoader creates a new simple template loader

func (*SimpleTemplateLoader) LoadTemplate

func (stl *SimpleTemplateLoader) LoadTemplate(name string) (*parser.TemplateNode, error)

LoadTemplate loads a template AST by name

func (*SimpleTemplateLoader) TemplateExists

func (stl *SimpleTemplateLoader) TemplateExists(name string) bool

TemplateExists checks if a template exists

type StrictUndefinedFactory

type StrictUndefinedFactory struct{}

StrictUndefinedFactory creates strict undefined values

func NewStrictUndefinedFactory

func NewStrictUndefinedFactory() *StrictUndefinedFactory

NewStrictUndefinedFactory creates a factory for strict undefined values

func (*StrictUndefinedFactory) Create

func (f *StrictUndefinedFactory) Create(name string, node parser.Node) *Undefined

Create creates a new strict undefined value

type SuperCallDetector

type SuperCallDetector struct{}

SuperCallDetector checks if a node contains super() calls

func NewSuperCallDetector

func NewSuperCallDetector() *SuperCallDetector

NewSuperCallDetector creates a new super() call detector

func (*SuperCallDetector) HasSuperCalls

func (d *SuperCallDetector) HasSuperCalls(node parser.Node) bool

HasSuperCalls checks if the given node contains any {{ super() }} calls

type SuperResolver

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

SuperResolver handles {{ super() }} call resolution during inheritance processing

func NewSuperResolver

func NewSuperResolver(hierarchy *InheritanceHierarchy, context Context, blockMap map[string]*parser.BlockNode) *SuperResolver

NewSuperResolver creates a new super() call resolver

func (*SuperResolver) ProcessTemplateWithSuperCalls

func (s *SuperResolver) ProcessTemplateWithSuperCalls(template *parser.TemplateNode) (*parser.TemplateNode, error)

ProcessTemplateWithSuperCalls processes an entire template to resolve super() calls

func (*SuperResolver) ResolveSuperCalls

func (s *SuperResolver) ResolveSuperCalls(node parser.Node, currentBlockName string) (parser.Node, error)

ResolveSuperCalls processes all {{ super() }} calls in the given AST node

type TemplateInterface

type TemplateInterface interface {
	AST() *parser.TemplateNode
	Name() string
}

TemplateInterface defines the minimal interface needed from Template

type TemplateLoader

type TemplateLoader interface {
	LoadTemplate(name string) (*parser.TemplateNode, error)
	TemplateExists(name string) bool
}

TemplateLoader interface for loading templates

type TemplateMacro

type TemplateMacro struct {
	Name       string
	Parameters []string
	Defaults   map[string]interface{}
	Body       []parser.Node
	Context    Context // The context in which the macro was defined
}

TemplateMacro represents a macro that can be called from templates

func (*TemplateMacro) Call

func (tm *TemplateMacro) Call(evaluator *DefaultEvaluator, callCtx Context, args []interface{}, kwargs map[string]interface{}) (interface{}, error)

Call executes the macro with the given arguments

type TemplateNamespace

type TemplateNamespace struct {
	TemplateName string
	Macros       map[string]*TemplateMacro
	Variables    map[string]interface{}
	Context      Context
	// contains filtered or unexported fields
}

TemplateNamespace represents an imported template's namespace

type Undefined

type Undefined struct {
	Name     string
	Behavior UndefinedBehavior
	Hint     string
	Node     parser.Node
}

Undefined represents an undefined value in templates

func NewDebugUndefined

func NewDebugUndefined(name string, hint string, node parser.Node) *Undefined

NewDebugUndefined creates a debug undefined value with hint

func NewStrictUndefined

func NewStrictUndefined(name string, node parser.Node) *Undefined

NewStrictUndefined creates a new strict undefined value

func NewUndefined

func NewUndefined(name string, behavior UndefinedBehavior, node parser.Node) *Undefined

NewUndefined creates a new undefined value

func (*Undefined) Error

func (u *Undefined) Error() error

Error returns an error for strict undefined behavior

func (*Undefined) String

func (u *Undefined) String() string

String returns the string representation based on behavior

type UndefinedBehavior

type UndefinedBehavior int

UndefinedBehavior defines how undefined variables should be handled

const (
	// UndefinedSilent returns empty string for undefined variables (default Jinja2 behavior)
	UndefinedSilent UndefinedBehavior = iota
	// UndefinedStrict raises an error when undefined variables are accessed
	UndefinedStrict
	// UndefinedDebug returns a debug string showing the undefined variable name
	UndefinedDebug
	// UndefinedChainFail fails on chained undefined access (e.g., undefined.attr)
	UndefinedChainFail
)

type UndefinedHandler

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

UndefinedHandler handles undefined variable access based on configuration

func NewUndefinedHandler

func NewUndefinedHandler(behavior UndefinedBehavior) *UndefinedHandler

NewUndefinedHandler creates a new undefined handler

func (*UndefinedHandler) GetUndefinedBehavior

func (h *UndefinedHandler) GetUndefinedBehavior() UndefinedBehavior

GetUndefinedBehavior returns the current undefined behavior

func (*UndefinedHandler) Handle

func (h *UndefinedHandler) Handle(name string, node parser.Node) (interface{}, error)

Handle handles an undefined variable access

func (*UndefinedHandler) HandleAttributeAccess

func (h *UndefinedHandler) HandleAttributeAccess(undefined *Undefined, attrName string, node parser.Node) (interface{}, error)

HandleAttributeAccess handles attribute access on undefined values

func (*UndefinedHandler) HandleFunctionCall

func (h *UndefinedHandler) HandleFunctionCall(undefined *Undefined, args []interface{}, node parser.Node) (interface{}, error)

HandleFunctionCall handles function calls on undefined values

func (*UndefinedHandler) HandleItemAccess

func (h *UndefinedHandler) HandleItemAccess(undefined *Undefined, key interface{}, node parser.Node) (interface{}, error)

HandleItemAccess handles item access on undefined values

func (*UndefinedHandler) IsCallableUndefined

func (h *UndefinedHandler) IsCallableUndefined(value interface{}) bool

IsCallableUndefined checks if an undefined value should allow function calls

func (*UndefinedHandler) SetUndefinedBehavior

func (h *UndefinedHandler) SetUndefinedBehavior(behavior UndefinedBehavior)

SetUndefinedBehavior sets the undefined behavior

Jump to

Keyboard shortcuts

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