Documentation ΒΆ
Index ΒΆ
- func Traverse(cur parse.Node, visitors ...Visitor)
- type AnalysisHelper
- func (h *AnalysisHelper) AddError(node parse.Node, err string)
- func (h *AnalysisHelper) AddFunc(name string, fn interface{})
- func (h *AnalysisHelper) AddWarning(node parse.Node, err string)
- func (h *AnalysisHelper) Context() context.Context
- func (h *AnalysisHelper) FuncMap() FuncMap
- func (h *AnalysisHelper) GetDefinedField(name string) *FieldNode
- func (h *AnalysisHelper) IsDefinedTemplate(name string) bool
- func (h *AnalysisHelper) WithContext(ctx context.Context)
- type Analyzer
- type AnalyzerFunc
- type CompilerOption
- type CompilerOptions
- type FieldNode
- type FuncMap
- type ParseOptions
- type RenderOption
- type RenderProcess
- type Template
- type TemplateProvider
- type Visitor
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
Types ΒΆ
type AnalysisHelper ΒΆ
type AnalysisHelper struct {
// contains filtered or unexported fields
}
AnalysisHelper is a struct that contains all the data collected during an analysis of a TemplateProvider.
An Analysis runs in two passes. The first pass collects important contextual information about the template definition tree that can be accessed in the second pass. The second pass is the actual analysis of the template definition tree where errors and warnings are added.
func Analyze ΒΆ
func Analyze(tp TemplateProvider, opts ParseOptions, analyzers []Analyzer) (*AnalysisHelper, error)
Analyze uses reflection on the given TemplateProvider while also parsing the templateProvider text to perform an analysis. The analysis is performed by the given analyzers. The analysis is returned as an AnalysisHelper struct.
func (*AnalysisHelper) AddFunc ΒΆ
func (h *AnalysisHelper) AddFunc(name string, fn interface{})
func (*AnalysisHelper) AddWarning ΒΆ
func (h *AnalysisHelper) AddWarning(node parse.Node, err string)
func (*AnalysisHelper) Context ΒΆ
func (h *AnalysisHelper) Context() context.Context
func (*AnalysisHelper) FuncMap ΒΆ
func (h *AnalysisHelper) FuncMap() FuncMap
func (*AnalysisHelper) GetDefinedField ΒΆ
func (h *AnalysisHelper) GetDefinedField(name string) *FieldNode
func (*AnalysisHelper) IsDefinedTemplate ΒΆ
func (h *AnalysisHelper) IsDefinedTemplate(name string) bool
IsDefinedTemplate returns true if the given template name is defined in the analysis target via {{define}}, or defined by any of its embedded templates.
func (*AnalysisHelper) WithContext ΒΆ
func (h *AnalysisHelper) WithContext(ctx context.Context)
type Analyzer ΒΆ
type Analyzer func(res *AnalysisHelper) AnalyzerFunc
Analyzer is a type that parses templateProvider text and performs an analysis
type CompilerOption ΒΆ
type CompilerOption func(opts *CompilerOptions)
CompilerOption is a function that can be used to modify the CompilerOptions
func UseAnalyzers ΒΆ
func UseAnalyzers(analyzers ...Analyzer) CompilerOption
func UseFuncs ΒΆ
func UseFuncs(funcs FuncMap) CompilerOption
func UseParseOptions ΒΆ
func UseParseOptions(parseOpts ParseOptions) CompilerOption
UseParseOptions sets the ParseOptions for the template CompilerOptions. These options are used internally with the html/template package.
type CompilerOptions ΒΆ
type CompilerOptions struct {
// contains filtered or unexported fields
}
CompilerOptions holds options that control the template compiler
type FieldNode ΒΆ
type ParseOptions ΒΆ
ParseOptions controls the behavior of the templateProvider parser used by Analyze.
type RenderOption ΒΆ
type RenderOption func(p *RenderProcess)
func WithFuncs ΒΆ
func WithFuncs(funcs template.FuncMap) RenderOption
WithFuncs appends the given Template.FuncMap to the Template's internal func map. These functions become available in the Template during execution
func WithName ΒΆ
func WithName(name string) RenderOption
WithName copies the Template's default parse.Tree and adds it back to the Template under the given name, effectively aliasing the Template.
func WithTarget ΒΆ
func WithTarget(target ...string) RenderOption
WithTarget sets the render Target to the given Template name.
type RenderProcess ΒΆ
type Template ΒΆ
type Template[T TemplateProvider] interface { // Render can be used to execute the internal template. Render(w io.Writer, data T, opts ...RenderOption) error // RenderToChan can be used to execute the internal template and write the result to a channel. RenderToChan(ch chan string, data T, opts ...RenderOption) error // RenderToString can be used to execute the internal template and return the result as a string. RenderToString(data T, opts ...RenderOption) (string, error) }
func Compile ΒΆ
func Compile[T TemplateProvider](tp T, opts ...CompilerOption) (Template[T], error)
Compile takes the given TemplateProvider, parses the templateProvider text and then recursively compiles all nested templates into one managed Template instance.
Compile also spawns a watcher routine. If the given TemplateProvider or any nested templates within implement TemplateWatcher, they can send signals over the given channel when it is time for the templateProvider to be recompiled.
func MustCompile ΒΆ
func MustCompile[T TemplateProvider](p T, opts ...CompilerOption) Template[T]
type TemplateProvider ΒΆ
type TemplateProvider interface {
TemplateText() string
}
TemplateProvider is a struct type that returns its corresponding template text.