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 FuncMapProvider
- 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 FuncMapProvider ¶
type FuncMapProvider interface {
TemplateFuncMap() FuncMap
}
FuncMapProvider is a struct type that returns its corresponding template functions. To be used in conjunction with the TemplateProvider interface.
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.
func MustCompile ¶
func MustCompile[T TemplateProvider](p T, opts ...CompilerOption) Template[T]
MustCompile is a helper function that wraps Compile and panics if the template fails to compile.
type TemplateProvider ¶
type TemplateProvider interface {
TemplateText() string
}
TemplateProvider is a struct type that returns its corresponding template text.