templateutil

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPathAliases

func AddPathAliases(tmpl *template.Template, names []string) error

func DefinedTemplates

func DefinedTemplates(name, src string) ([]string, error)

func FilterFuncMap

func FilterFuncMap(funcs template.FuncMap, required map[string]struct{}) template.FuncMap

func FunctionNameSignature

func FunctionNameSignature(funcs template.FuncMap) string

func FunctionNameSignatureFromNames

func FunctionNameSignatureFromNames(names []string) string

func FunctionNameSignatureFromSet

func FunctionNameSignatureFromSet(names map[string]struct{}) string

func MergeFuncMaps

func MergeFuncMaps(funcMaps ...template.FuncMap) template.FuncMap

func MergeFunctionSignatures

func MergeFunctionSignatures(signatures ...string) string

func Names

func Names(funcs template.FuncMap) map[string]struct{}

func NormalizeContractType

func NormalizeContractType(typeName string) string

func PathAliases

func PathAliases(name string) []string

func PathBase

func PathBase(name string) string

func ReferencedTemplates

func ReferencedTemplates(name, src string) ([]string, error)

func RequiredFuncs

func RequiredFuncs(name, src string) ([]string, error)

Types

type CachedTemplate

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

func NewCachedTemplate

func NewCachedTemplate(base *template.Template, requiredFuncs map[string]struct{}) *CachedTemplate

func (*CachedTemplate) Template

func (cached *CachedTemplate) Template(functions template.FuncMap) (*template.Template, func(), error)

func (*CachedTemplate) TemplateResolving added in v0.14.0

func (cached *CachedTemplate) TemplateResolving(resolve func(name string) (any, bool)) (*template.Template, func(), error)

TemplateResolving is Template with the functions the template calls looked up by resolve, rather than filtered from a map of every function.

type ContractDeclaration added in v0.14.0

type ContractDeclaration struct {
	Annotation string
	Name       string
	Type       string
}

ContractDeclaration is one typed root declaration, such as "@model Site github.com/acme/site.Site".

type FileScan added in v0.14.0

type FileScan struct {
	Defined    []string
	Referenced []string
	Required   []string
	Contracts  []ContractDeclaration
	// ParseErr is set when the file does not parse; Defined, Referenced and
	// Required are empty then.
	ParseErr error
}

FileScan is what one template file declares and uses: the templates it defines and calls, the functions it calls, and its typed root declarations.

func ScanTemplate added in v0.14.0

func ScanTemplate(name, src string) *FileScan

ScanTemplate reads what the template source declares and uses, parsing it once.

type RootContract

type RootContract struct {
	Annotation string
	Type       string
}

type Scanner added in v0.14.0

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

Scanner reads template files from one file system. With a key, which identifies the file system, each file is scanned once and kept in the store, for template trees whose files do not change.

func (Scanner) DefinedTemplates added in v0.14.0

func (s Scanner) DefinedTemplates(names []string) map[string]struct{}

DefinedTemplates returns the names the files can be called by: their paths, base names and aliases, and the templates they define.

func (Scanner) File added in v0.14.0

func (s Scanner) File(name string) (*FileScan, error)

File returns the scan of the template file name.

func (Scanner) IsFile added in v0.14.0

func (s Scanner) IsFile(name string) bool

IsFile reports whether name is a file. With a key, files found are remembered.

func (Scanner) ReferencedTemplates added in v0.14.0

func (s Scanner) ReferencedTemplates(names []string) map[string]struct{}

ReferencedTemplates returns the templates the files call. Files that cannot be read or parsed are skipped; parsing them for rendering reports why.

func (Scanner) RequiredFuncs added in v0.14.0

func (s Scanner) RequiredFuncs(names []string) (map[string]struct{}, error)

RequiredFuncs returns the functions the files call.

func (Scanner) RootContracts added in v0.14.0

func (s Scanner) RootContracts(names []string) (map[string]RootContract, error)

RootContracts returns the typed root declarations of the files by root name. A name declared with two types is an error.

type Store

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

func NewStore

func NewStore() *Store

func (*Store) Load

func (store *Store) Load(key string) (*CachedTemplate, bool)

func (*Store) Mutex

func (store *Store) Mutex(key string) *sync.Mutex

func (*Store) Scanner added in v0.14.0

func (store *Store) Scanner(fsys fs.FS, key string) Scanner

Scanner returns a scanner for fsys. An empty key scans files on every call.

func (*Store) Store

func (store *Store) Store(key string, entry *CachedTemplate)

Jump to

Keyboard shortcuts

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