Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Default = map[string]Test{ "odd": testOdd, "even": testEven, "divisibleby": testDivisibleBy, "defined": testDefined, "undefined": testUndefined, "filter": testFilter, "test": testTest, "none": testNone, "boolean": testBoolean, "false": testFalse, "true": testTrue, "integer": testInteger, "float": testFloat, "lower": testLower, "upper": testUpper, "string": testString, "mapping": testMapping, "number": testNumber, "sequence": testSequence, "iterable": testIterable, "callable": testCallable, "sameas": testSameAs, "escaped": testEscaped, "in": testIn, "==": wrapOperator(operator.Eq), "eq": wrapOperator(operator.Eq), "equalto": wrapOperator(operator.Eq), "!=": wrapOperator(operator.Ne), "ne": wrapOperator(operator.Ne), ">": wrapOperator(operator.Gt), "gt": wrapOperator(operator.Gt), "greaterthan": wrapOperator(operator.Gt), "<": wrapOperator(operator.Lt), "lt": wrapOperator(operator.Lt), "lessthan": wrapOperator(operator.Lt), "<=": wrapOperator(operator.Le), "le": wrapOperator(operator.Le), ">=": wrapOperator(operator.Ge), "ge": wrapOperator(operator.Ge), }
Functions ¶
This section is empty.
Types ¶
type EnvOpts ¶
type EnvOpts struct { *lexer.EnvLexerInformation Optimized bool Extensions map[string]func(*Environment) extensions.IExtension // TODO jinja accepts also extensions names but it's python import magic I don't know how to do it in golang. Undefined UndefinedConstructor Finalize func(...any) any AutoEscape any // bool or func(string)bool Loader *Loader CacheSize int AutoReload bool }
func DefaultEnvOpts ¶
func DefaultEnvOpts() *EnvOpts
type Environment ¶
type Environment struct { Sandboxed bool Overlayed bool LinkedTo *Environment Concat func([]string) string ContextClass runtime.ContextClass TemplateClass Class *lexer.EnvLexerInformation Optimized bool Extensions ExtensionsMap Undefined UndefinedConstructor Finalize func(...any) any AutoEscape func(name string) bool Loader *Loader Cache Cache AutoReload bool Filters map[string]filters.Filter Tests map[string]Test Globals map[string]any Policies map[string]any }
Environment is the core component of Jinja. It contains important shared variables like configuration, filters, tests, globals and others. Instances of this class may be modified if they are not shared and if no template was loaded so far. Modifications on environments after the first template was loaded will lead to surprising effects and undefined behavior.
func New ¶
func New(opts *EnvOpts) (*Environment, error)
func (*Environment) GetTemplate ¶
func (env *Environment) GetTemplate(name any, parent *string, globals map[string]any) (ITemplate, error)
GetTemplate loads a template by name with `Loader` and returns a `Template`. If the template does not exist a `TemplateNotFound` exception is raised.
func (*Environment) JoinPath ¶
func (env *Environment) JoinPath(v string, parent string) string
JoinPath joins a template with the parent. By default, all the lookups are relative to the loader root so this method returns the `template` parameter unchanged, but if the paths should be relative to the parent template, this function can be used to calculate the real template name.
Subclasses may override this method and implement template path joining here.
func (*Environment) MakeGlobals ¶
func (env *Environment) MakeGlobals(globals map[string]any) map[string]any
type ExtensionsMap ¶
type ExtensionsMap map[string]extensions.IExtension
func LoadExtensions ¶
func LoadExtensions(env *Environment, extensions map[string]func(*Environment) extensions.IExtension) ExtensionsMap
type Loader ¶
type Loader struct {
LoaderEmbed
}
func NewFileSystemLoader ¶
func NewFileSystemLoader[S utils.StrOrSlice](searchPath S, encoding string, followLinks bool) *Loader
type LoaderEmbed ¶
type Test ¶
type Test func(env *Environment, firstArg any, args ...any) (bool, error)
Test represents a test function. Some tests only require one variable