loader

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: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadAll

func ReadAll(r io.Reader) (string, error)

Types

type AdvancedLoader

type AdvancedLoader interface {
	Loader
	LoadTemplate(name string) (*parser.TemplateNode, error)
	ResolveTemplateName(name string) string
	GetSourceWithMetadata(name string) (*TemplateSource, error)
}

Enhanced Loader interface for advanced template loading

type BaseLoader

type BaseLoader struct{}

Base implementation (keeping compatibility)

func (*BaseLoader) IsCached

func (b *BaseLoader) IsCached(name string) bool

func (*BaseLoader) ListTemplates

func (b *BaseLoader) ListTemplates() ([]string, error)

type CacheCleanup

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

LRU Cache cleanup helper

func NewCacheCleanup

func NewCacheCleanup(cache *LRUCache, interval time.Duration) *CacheCleanup

NewCacheCleanup creates a new cache cleanup helper

func (*CacheCleanup) Start

func (cc *CacheCleanup) Start()

Start begins the cleanup routine

func (*CacheCleanup) Stop

func (cc *CacheCleanup) Stop()

Stop stops the cleanup routine

type CacheStats

type CacheStats struct {
	Hits   int64
	Misses int64
	Size   int
}

CacheStats provides information about cache performance

type CachingLoader

type CachingLoader interface {
	AdvancedLoader
	ClearCache()
	GetCacheStats() CacheStats
}

CachingLoader interface for loaders that support caching

type ChainLoader

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

ChainLoader combines multiple loaders, trying them in order

func NewChainLoader

func NewChainLoader(loaders ...AdvancedLoader) *ChainLoader

NewChainLoader creates a new chain loader

func (*ChainLoader) AddLoader

func (c *ChainLoader) AddLoader(loader AdvancedLoader)

AddLoader adds a loader to the chain

func (*ChainLoader) GetSource

func (c *ChainLoader) GetSource(name string) (string, error)

GetSource implements the base Loader interface

func (*ChainLoader) GetSourceWithMetadata

func (c *ChainLoader) GetSourceWithMetadata(name string) (*TemplateSource, error)

GetSourceWithMetadata gets template source with metadata using the first loader that succeeds

func (*ChainLoader) IsCached

func (c *ChainLoader) IsCached(name string) bool

IsCached checks if any loader has the template cached

func (*ChainLoader) ListTemplates

func (c *ChainLoader) ListTemplates() ([]string, error)

ListTemplates returns templates from all loaders

func (*ChainLoader) LoadTemplate

func (c *ChainLoader) LoadTemplate(name string) (*parser.TemplateNode, error)

LoadTemplate loads a template using the first loader that succeeds

func (*ChainLoader) ResolveTemplateName

func (c *ChainLoader) ResolveTemplateName(name string) string

ResolveTemplateName resolves using the first loader

type DirectTemplateParser

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

DirectTemplateParser parses templates without Environment coupling This eliminates circular dependencies in template loading

func NewDirectTemplateParser

func NewDirectTemplateParser() *DirectTemplateParser

NewDirectTemplateParser creates a parser that works independently of Environment

func NewDirectTemplateParserWithConfig

func NewDirectTemplateParserWithConfig(config *lexer.LexerConfig) *DirectTemplateParser

NewDirectTemplateParserWithConfig creates a parser with custom lexer configuration

func (*DirectTemplateParser) GetLexerConfig

func (p *DirectTemplateParser) GetLexerConfig() *lexer.LexerConfig

GetLexerConfig returns the current lexer configuration

func (*DirectTemplateParser) ParseTemplate

func (p *DirectTemplateParser) ParseTemplate(name, content string) (*parser.TemplateNode, error)

ParseTemplate parses template content directly without Environment involvement

func (*DirectTemplateParser) SetLexerConfig

func (p *DirectTemplateParser) SetLexerConfig(config *lexer.LexerConfig)

SetLexerConfig updates the lexer configuration

type DiscoveryLoader

type DiscoveryLoader interface {
	AdvancedLoader
	SearchTemplates(pattern string) ([]string, error)
	GetTemplatesByExtension(ext string) ([]string, error)
	GetTemplatesInDirectory(dir string) ([]string, error)
	GetTemplateInfo(name string) (*TemplateInfo, error)
}

DiscoveryLoader interface for advanced template discovery

type EmbedLoader

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

EmbedLoader loads templates from embedded filesystem

func NewEmbedLoader

func NewEmbedLoader(embedFS embed.FS, prefix string, parser TemplateParser) *EmbedLoader

NewEmbedLoader creates a new embed filesystem loader

func (*EmbedLoader) ClearCache

func (e *EmbedLoader) ClearCache()

ClearCache clears the template cache

func (*EmbedLoader) GetCacheStats

func (e *EmbedLoader) GetCacheStats() CacheStats

GetCacheStats returns cache performance statistics

func (*EmbedLoader) GetSource

func (e *EmbedLoader) GetSource(name string) (string, error)

GetSource implements the base Loader interface

func (*EmbedLoader) GetSourceWithMetadata

func (e *EmbedLoader) GetSourceWithMetadata(name string) (*TemplateSource, error)

GetSourceWithMetadata retrieves the source content of a template with metadata

func (*EmbedLoader) IsCached

func (e *EmbedLoader) IsCached(name string) bool

IsCached checks if a template is cached

func (*EmbedLoader) ListTemplates

func (e *EmbedLoader) ListTemplates() ([]string, error)

ListTemplates returns a list of all available templates

func (*EmbedLoader) LoadTemplate

func (e *EmbedLoader) LoadTemplate(name string) (*parser.TemplateNode, error)

LoadTemplate loads and parses a template by name

func (*EmbedLoader) ResolveTemplateName

func (e *EmbedLoader) ResolveTemplateName(name string) string

ResolveTemplateName resolves a template name to its canonical form

func (*EmbedLoader) SetExtensions

func (e *EmbedLoader) SetExtensions(extensions []string)

SetExtensions sets the file extensions to search for

type FileSystemLoader

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

FileSystemLoader loads templates from the filesystem

func NewFileSystemLoader

func NewFileSystemLoader(searchPaths []string, parser TemplateParser) *FileSystemLoader

NewFileSystemLoader creates a new filesystem loader

func (*FileSystemLoader) ClearCache

func (f *FileSystemLoader) ClearCache()

ClearCache clears the template cache

func (*FileSystemLoader) GetCacheStats

func (f *FileSystemLoader) GetCacheStats() CacheStats

GetCacheStats returns cache performance statistics

func (*FileSystemLoader) GetSource

func (f *FileSystemLoader) GetSource(name string) (string, error)

GetSource implements the base Loader interface

func (*FileSystemLoader) GetSourceWithMetadata

func (f *FileSystemLoader) GetSourceWithMetadata(name string) (*TemplateSource, error)

GetSourceWithMetadata retrieves the source content of a template with metadata

func (*FileSystemLoader) GetTemplateInfo

func (f *FileSystemLoader) GetTemplateInfo(name string) (*TemplateInfo, error)

GetTemplateInfo returns detailed information about a template

func (*FileSystemLoader) GetTemplatesByExtension

func (f *FileSystemLoader) GetTemplatesByExtension(ext string) ([]string, error)

GetTemplatesByExtension returns all templates with a specific extension

func (*FileSystemLoader) GetTemplatesInDirectory

func (f *FileSystemLoader) GetTemplatesInDirectory(dir string) ([]string, error)

GetTemplatesInDirectory returns all templates in a specific directory

func (*FileSystemLoader) IsCached

func (f *FileSystemLoader) IsCached(name string) bool

IsCached checks if a template is cached

func (*FileSystemLoader) ListTemplates

func (f *FileSystemLoader) ListTemplates() ([]string, error)

ListTemplates returns a list of all available templates

func (*FileSystemLoader) LoadTemplate

func (f *FileSystemLoader) LoadTemplate(name string) (*parser.TemplateNode, error)

LoadTemplate loads and parses a template by name

func (*FileSystemLoader) ResolveTemplateName

func (f *FileSystemLoader) ResolveTemplateName(name string) string

ResolveTemplateName resolves a template name to its canonical form

func (*FileSystemLoader) SearchTemplates

func (f *FileSystemLoader) SearchTemplates(pattern string) ([]string, error)

SearchTemplates searches for templates matching a pattern (glob-style)

func (*FileSystemLoader) SetExtensions

func (f *FileSystemLoader) SetExtensions(extensions []string)

SetExtensions sets the file extensions to search for

func (f *FileSystemLoader) SetFollowLinks(follow bool)

SetFollowLinks enables or disables following symbolic links

type LRUCache

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

LRUCache implements a Least Recently Used cache for templates

func NewLRUCache

func NewLRUCache(maxSize int) *LRUCache

NewLRUCache creates a new LRU cache with the specified maximum size

func (*LRUCache) Clear

func (c *LRUCache) Clear()

Clear removes all items from the cache

func (*LRUCache) Get

Get retrieves a template from the cache

func (*LRUCache) Keys

func (c *LRUCache) Keys() []string

Keys returns all keys currently in the cache

func (*LRUCache) Put

func (c *LRUCache) Put(key string, template *parser.TemplateNode, source *TemplateSource, ttl time.Duration)

Put adds or updates a template in the cache

func (*LRUCache) Remove

func (c *LRUCache) Remove(key string) bool

Remove removes a specific key from the cache

func (*LRUCache) Size

func (c *LRUCache) Size() int

Size returns the current number of items in the cache

func (*LRUCache) Stats

func (c *LRUCache) Stats() CacheStats

Stats returns cache statistics

type LRUFileSystemLoader

type LRUFileSystemLoader struct {
	*FileSystemLoader
	// contains filtered or unexported fields
}

LRUFileSystemLoader extends FileSystemLoader with LRU caching

func NewLRUFileSystemLoader

func NewLRUFileSystemLoader(searchPaths []string, parser TemplateParser, maxCacheSize int, cacheTTL time.Duration) *LRUFileSystemLoader

NewLRUFileSystemLoader creates a filesystem loader with LRU caching

func (*LRUFileSystemLoader) ClearCache

func (l *LRUFileSystemLoader) ClearCache()

ClearCache clears the LRU cache

func (*LRUFileSystemLoader) EvictExpiredItems

func (l *LRUFileSystemLoader) EvictExpiredItems() int

EvictExpiredItems manually removes expired items from the cache

func (*LRUFileSystemLoader) GetCacheKeys

func (l *LRUFileSystemLoader) GetCacheKeys() []string

GetCacheKeys returns all keys currently in the LRU cache

func (*LRUFileSystemLoader) GetCacheStats

func (l *LRUFileSystemLoader) GetCacheStats() CacheStats

GetCacheStats returns LRU cache statistics

func (*LRUFileSystemLoader) IsCached

func (l *LRUFileSystemLoader) IsCached(name string) bool

IsCached checks if a template is cached in the LRU cache

func (*LRUFileSystemLoader) LoadTemplate

func (l *LRUFileSystemLoader) LoadTemplate(name string) (*parser.TemplateNode, error)

LoadTemplate loads and parses a template with LRU caching

func (*LRUFileSystemLoader) SetCacheTTL

func (l *LRUFileSystemLoader) SetCacheTTL(ttl time.Duration)

SetCacheTTL sets the time-to-live for cached templates

type Loader

type Loader interface {
	GetSource(name string) (string, error)
	IsCached(name string) bool
	ListTemplates() ([]string, error)
}

Base Loader interface (keeping compatibility with existing code)

type LoaderFunc

type LoaderFunc func(name string) (string, error)

func (LoaderFunc) GetSource

func (f LoaderFunc) GetSource(name string) (string, error)

func (LoaderFunc) IsCached

func (f LoaderFunc) IsCached(name string) bool

func (LoaderFunc) ListTemplates

func (f LoaderFunc) ListTemplates() ([]string, error)

type StringLoader

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

StringLoader loads templates from string content (useful for testing)

func NewStringLoader

func NewStringLoader(parser TemplateParser) *StringLoader

NewStringLoader creates a new string loader

func (*StringLoader) AddTemplate

func (s *StringLoader) AddTemplate(name, content string)

AddTemplate adds a template with the given name and content

func (*StringLoader) GetSource

func (s *StringLoader) GetSource(name string) (string, error)

GetSource implements the base Loader interface

func (*StringLoader) GetSourceWithMetadata

func (s *StringLoader) GetSourceWithMetadata(name string) (*TemplateSource, error)

GetSourceWithMetadata retrieves the source content of a template with metadata

func (*StringLoader) IsCached

func (s *StringLoader) IsCached(name string) bool

IsCached always returns true for string loader (templates are in memory)

func (*StringLoader) ListTemplates

func (s *StringLoader) ListTemplates() ([]string, error)

ListTemplates returns a list of all available templates

func (*StringLoader) LoadTemplate

func (s *StringLoader) LoadTemplate(name string) (*parser.TemplateNode, error)

LoadTemplate loads and parses a template by name

func (*StringLoader) ResolveTemplateName

func (s *StringLoader) ResolveTemplateName(name string) string

ResolveTemplateName resolves a template name (identity function for string loader)

type TemplateInfo

type TemplateInfo struct {
	Name         string
	Path         string
	Size         int64
	ModTime      time.Time
	Extension    string
	Directory    string
	Dependencies []string
}

TemplateInfo provides detailed information about a template

type TemplateParser

type TemplateParser interface {
	ParseTemplate(name, content string) (*parser.TemplateNode, error)
}

TemplateParser interface for parsing template content

type TemplateSource

type TemplateSource struct {
	Name     string
	Content  string
	ModTime  time.Time
	Checksum string
}

TemplateSource represents a template source with metadata

Jump to

Keyboard shortcuts

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