Documentation
¶
Index ¶
- func AddPathAliases(tmpl *template.Template, names []string) error
- func DefinedTemplates(name, src string) ([]string, error)
- func FilterFuncMap(funcs template.FuncMap, required map[string]struct{}) template.FuncMap
- func FunctionNameSignature(funcs template.FuncMap) string
- func FunctionNameSignatureFromNames(names []string) string
- func FunctionNameSignatureFromSet(names map[string]struct{}) string
- func HTMLAttrs(attrs map[string]string) template.HTMLAttr
- func MergeFuncMaps(funcMaps ...template.FuncMap) template.FuncMap
- func MergeFunctionSignatures(signatures ...string) string
- func Names(funcs template.FuncMap) map[string]struct{}
- func NormalizeContractType(typeName string) string
- func PathAliases(name string) []string
- func PathBase(name string) string
- func ReferencedTemplates(name, src string) ([]string, error)
- func RequiredFuncs(name, src string) ([]string, error)
- func WriteAttr(b *strings.Builder, name, value string)
- type CachedTemplate
- func (cached *CachedTemplate) NoteSize(entry string, size int)
- func (cached *CachedTemplate) Release(t *template.Template)
- func (cached *CachedTemplate) RequiredFuncs() map[string]struct{}
- func (cached *CachedTemplate) RootContracts() map[string]RootContract
- func (cached *CachedTemplate) SizeHint(entry string) int
- func (cached *CachedTemplate) Template(functions template.FuncMap) (*template.Template, error)
- func (cached *CachedTemplate) TemplateResolving(resolve func(name string) (any, bool)) (*template.Template, error)
- type ContractDeclaration
- type FileScan
- type RootContract
- type Scanner
- func (s Scanner) DefinedTemplates(names []string) map[string]struct{}
- func (s Scanner) Exists(name string) (bool, error)
- func (s Scanner) File(name string) (*FileScan, error)
- func (s Scanner) Glob(pattern string) ([]string, error)
- func (s Scanner) IsFile(name string) bool
- func (s Scanner) ReferencedTemplates(names []string) map[string]struct{}
- func (s Scanner) RequiredFuncs(names []string) (map[string]struct{}, error)
- func (s Scanner) RootContracts(names []string) (map[string]RootContract, error)
- type Store
- func (store *Store) Load(key string) (*CachedTemplate, bool)
- func (store *Store) Mutex(key string) *sync.Mutex
- func (store *Store) Scanner(fsys fs.FS, key string) Scanner
- func (store *Store) Store(key string, entry *CachedTemplate)
- func (store *Store) StoreText(key string, tmpl *texttemplate.Template)
- func (store *Store) Text(key string) (*texttemplate.Template, bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefinedTemplates ¶
func FilterFuncMap ¶
func FunctionNameSignature ¶
func HTMLAttrs ¶ added in v0.15.0
HTMLAttrs writes attrs as HTML attributes, sorted by name, each after a space, with their values escaped.
func MergeFunctionSignatures ¶
func NormalizeContractType ¶
func PathAliases ¶
func ReferencedTemplates ¶
func RequiredFuncs ¶
Types ¶
type CachedTemplate ¶
type CachedTemplate struct {
// contains filtered or unexported fields
}
func NewCachedTemplate ¶
func NewCachedTemplate( base *template.Template, requiredFuncs map[string]struct{}, contracts map[string]RootContract, ) *CachedTemplate
NewCachedTemplate keeps a parsed template with the functions its templates call and their typed root declarations.
func (*CachedTemplate) NoteSize ¶ added in v0.15.0
func (cached *CachedTemplate) NoteSize(entry string, size int)
NoteSize remembers the size of the output of a render of entry, for SizeHint.
func (*CachedTemplate) Release ¶ added in v0.15.0
func (cached *CachedTemplate) Release(t *template.Template)
Release takes back a copy of the template that Template or TemplateResolving returned, for a later render.
func (*CachedTemplate) RequiredFuncs ¶ added in v0.15.0
func (cached *CachedTemplate) RequiredFuncs() map[string]struct{}
RequiredFuncs returns the names of the functions the template calls, or nil when they are not known. The map is shared; do not change it.
func (*CachedTemplate) RootContracts ¶ added in v0.15.0
func (cached *CachedTemplate) RootContracts() map[string]RootContract
RootContracts returns the typed root declarations of the template's files by root name. The map is shared; do not change it.
func (*CachedTemplate) SizeHint ¶ added in v0.15.0
func (cached *CachedTemplate) SizeHint(entry string) int
SizeHint returns the capacity to start the output of a render of entry ("" for the template itself) with: the size of its last output and an eighth more, for output that grows a little, at most 4 MB; 0 before the first render.
func (*CachedTemplate) Template ¶
Template returns a copy of the template with functions, those of the functions the template calls. Give it back with Release when it has executed.
func (*CachedTemplate) TemplateResolving ¶ added in v0.14.0
func (cached *CachedTemplate) TemplateResolving(resolve func(name string) (any, bool)) (*template.Template, 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
ContractDeclaration is one typed root declaration, such as "@model Site github.com/acme/site.Site".
func Declarations ¶ added in v0.15.0
func Declarations(src string) ([]ContractDeclaration, string)
Declarations returns the typed root declarations of a template source and the type of its first @dot declaration, or "".
type FileScan ¶ added in v0.14.0
type FileScan struct {
Defined []string
Referenced []string
Required []string
Contracts []ContractDeclaration
// Dot is the type the file declares for its dot with @dot, or "".
Dot string
// ParseErr is set when the file does not parse; Defined, Referenced and
// Required are empty then.
ParseErr error
// contains filtered or unexported fields
}
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
ScanTemplate reads what the template source declares and uses, parsing it once.
type RootContract ¶
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 in the process, each file is scanned once, and whether a file exists and what a pattern matches asked once, and kept in the store, for template trees whose files do not change.
func (Scanner) DefinedTemplates ¶ added in v0.14.0
DefinedTemplates returns the names the files can be called by: their paths, base names and aliases, and the templates they define.
func (Scanner) Exists ¶ added in v0.15.0
Exists reports whether name is a file. With a key, the answer is remembered, also when the file is missing; errors other than a missing file are returned, and asked again next time.
func (Scanner) Glob ¶ added in v0.15.0
Glob returns the files pattern matches, as fs.Glob, without the directories that match. With a key, the matches are remembered. The slice may be shared: do not change it.
func (Scanner) IsFile ¶ added in v0.14.0
IsFile reports whether name is a file. With a key, the answer is remembered; see Exists.
func (Scanner) ReferencedTemplates ¶ added in v0.14.0
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
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.
The map may be shared: do not change it.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store keeps what the template cache of one partial tree learns: parsed templates, and of each file system the tree reads, the scans of its files, which files exist and what include patterns match. Every tree root has a store of its own, so two trees over the same directory, such as two applications in one test process, do not see each other's answers, such as a file that was missing when the other one looked.
func (*Store) Scanner ¶ added in v0.14.0
Scanner returns a scanner for fsys. An empty key, or a nil store, scans files on every call.
func (*Store) Store ¶
func (store *Store) Store(key string, entry *CachedTemplate)