var TypeDict = reflect.TypeOf(Dict{})
func CaseInsensitive(data sort.Interface) sort.Interface
CaseInsensitive returns the the data sorted in a case insensitive way (if string).
func Self(r *Renderer) map[string]func() string
type Context struct {
// contains filtered or unexported fields
}
func EmptyContext() *Context
func NewContext(data map[string]interface{}) *Context
func (ctx *Context) Get(name string) interface{}
func (ctx *Context) Has(name string) bool
func (ctx *Context) Inherit() *Context
func (ctx *Context) Merge(other *Context) *Context
Merge updates this context with the key/value pairs from another context.
func (ctx *Context) Set(name string, value interface{})
func (ctx *Context) Update(other map[string]interface{}) *Context
Update updates this context with the key/value pairs from a map.
type Dict struct { Pairs []*Pair }
func NewDict() *Dict
func (d *Dict) Get(key *Value) *Value
func (d *Dict) Keys() ValuesList
func (d *Dict) String() string
type EvalConfig struct { *config.Config Filters *FilterSet Globals *Context Statements *StatementSet Tests *TestSet Loader TemplateLoader }
func NewEvalConfig(cfg *config.Config) *EvalConfig
func (cfg *EvalConfig) GetTemplate(filename string) (*nodes.Template, error)
func (cfg *EvalConfig) Inherit() *EvalConfig
type Evaluator struct { *EvalConfig Ctx *Context }
func (e *Evaluator) Eval(node nodes.Expression) *Value
func (e *Evaluator) EvalTest(expr *nodes.TestExpression) *Value
func (e *Evaluator) EvaluateFiltered(expr *nodes.FilteredExpression) *Value
EvaluateFiltered evaluate a filtered expression
func (e *Evaluator) ExecuteFilter(fc *nodes.FilterCall, v *Value) *Value
ExecuteFilter execute a filter node
func (e *Evaluator) ExecuteFilterByName(name string, in *Value, params *VarArgs) *Value
ExecuteFilterByName execute a filter given its name
func (e *Evaluator) ExecuteTest(tc *nodes.TestCall, v *Value) *Value
func (e *Evaluator) ExecuteTestByName(name string, in *Value, params *VarArgs) *Value
FilterFunction is the type filter functions must fulfil
type FilterFunction func(e *Evaluator, in *Value, params *VarArgs) *Value
type FilterSet map[string]FilterFunction
func (fs FilterSet) Exists(name string) bool
Exists returns true if the given filter is already registered
func (fs *FilterSet) Register(name string, fn FilterFunction) error
Register registers a new filter. If there's already a filter with the same name, Register will panic. You usually want to call this function in the filter's init() function: http://golang.org/doc/effective_go.html#init
See http://www.florian-schlachter.de/post/gonja/ for more about writing filters and tags.
func (fs *FilterSet) Replace(name string, fn FilterFunction) error
Replace replaces an already registered filter with a new implementation. Use this function with caution since it allows you to change existing filter behaviour.
func (fs *FilterSet) Update(other FilterSet) FilterSet
type KwArg struct { Name string Default interface{} }
FilterFunction is the type filter functions must fulfil
type Macro func(params *VarArgs) *Value
func MacroNodeToFunc(node *nodes.Macro, r *Renderer) (Macro, error)
type MacroSet map[string]Macro
func (ms MacroSet) Exists(name string) bool
Exists returns true if the given filter is already registered
func (ms *MacroSet) Register(name string, fn Macro) error
Register registers a new filter. If there's already a filter with the same name, Register will panic. You usually want to call this function in the filter's init() function: http://golang.org/doc/effective_go.html#init
See http://www.florian-schlachter.de/post/gonja/ for more about writing filters and tags.
func (ms *MacroSet) Replace(name string, fn Macro) error
Replace replaces an already registered filter with a new implementation. Use this function with caution since it allows you to change existing filter behaviour.
type Pair struct { Key *Value Value *Value }
func (p *Pair) String() string
ReducedVarArgs represents pythonic variadic args/kwargs but values are reduced (ie. kwargs given as args are accessible by name)
type ReducedVarArgs struct { *VarArgs // contains filtered or unexported fields }
func (rva *ReducedVarArgs) Error() string
func (rva *ReducedVarArgs) IsError() bool
IsError returns true if there was an error on Expect call
Renderer is a node visitor in charge of rendering
type Renderer struct { *EvalConfig Ctx *Context Template *Template Root *nodes.Template Out *strings.Builder Trim *TrimState }
func NewRenderer(ctx *Context, out *strings.Builder, cfg *EvalConfig, tpl *Template) *Renderer
NewRenderer initialize a new renderer
func (r *Renderer) EndTag(trim *nodes.Trim)
func (r *Renderer) Eval(node nodes.Expression) *Value
func (r *Renderer) Evaluator() *Evaluator
func (r *Renderer) Execute() error
func (r *Renderer) ExecuteWrapper(wrapper *nodes.Wrapper) error
ExecuteWrapper wraps the nodes.Wrapper execution logic
func (r *Renderer) Flush(lstrip bool)
func (r *Renderer) FlushAndTrim(trim, lstrip bool)
func (r *Renderer) Inherit() *Renderer
Inherit creates a new sub renderer
func (r *Renderer) LStrip()
func (r *Renderer) RenderValue(value *Value)
RenderValue properly render a value
func (r *Renderer) StartTag(trim *nodes.Trim, lstrip bool)
func (r *Renderer) String() string
func (r *Renderer) Tag(trim *nodes.Trim, lstrip bool)
func (r *Renderer) Visit(node nodes.Node) (nodes.Visitor, error)
Visit implements the nodes.Visitor interface
func (r *Renderer) WriteString(txt string) (int, error)
WriteString wraps the triming policy
type Statement interface { nodes.Statement Execute(*Renderer, *nodes.StatementBlock) error }
type StatementSet map[string]parser.StatementParser
func (ss StatementSet) Exists(name string) bool
Exists returns true if the given test is already registered
func (ss *StatementSet) Register(name string, parser parser.StatementParser) error
Registers a new tag. You usually want to call this function in the tag's init() function: http://golang.org/doc/effective_go.html#init
See http://www.florian-schlachter.de/post/gonja/ for more about writing filters and tags.
func (ss *StatementSet) Replace(name string, parser parser.StatementParser) error
Replaces an already registered tag with a new implementation. Use this function with caution since it allows you to change existing tag behaviour.
func (ss *StatementSet) Update(other StatementSet) StatementSet
type Template struct { Name string Reader io.Reader Source string Env *EvalConfig Loader TemplateLoader Tokens *tokens.Stream Parser *parser.Parser Root *nodes.Template Macros MacroSet }
func NewTemplate(name string, source string, cfg *EvalConfig) (*Template, error)
func (tpl *Template) Execute(ctx map[string]interface{}) (string, error)
Executes the template and returns the rendered template as a string
func (tpl *Template) ExecuteBytes(ctx map[string]interface{}) ([]byte, error)
Executes the template and returns the rendered template as a []byte
type TemplateLoader interface { GetTemplate(string) (*Template, error) }
TestFunction is the type test functions must fulfil
type TestFunction func(*Context, *Value, *VarArgs) (bool, error)
TestSet maps test names to their TestFunction handler
type TestSet map[string]TestFunction
func (ts TestSet) Exists(name string) bool
Exists returns true if the given test is already registered
func (ts *TestSet) Register(name string, fn TestFunction) error
Register registers a new test. If there's already a test with the same name, RegisterTest will panic. You usually want to call this function in the test's init() function: http://golang.org/doc/effective_go.html#init
See http://www.florian-schlachter.de/post/gonja/ for more about writing tests and tags.
func (ts *TestSet) Replace(name string, fn TestFunction) error
Replace replaces an already registered test with a new implementation. Use this function with caution since it allows you to change existing test behaviour.
func (ts *TestSet) Update(other TestSet) TestSet
TrimState stores and apply trim policy
type TrimState struct { Should bool ShouldBlock bool Buffer *strings.Builder }
func (ts *TrimState) TrimBlocks(r rune) bool
type Value struct { Val reflect.Value Safe bool // used to indicate whether a Value needs explicit escaping in the template }
func AsSafeValue(i interface{}) *Value
AsSafeValue works like AsValue, but does not apply the 'escape' filter.
func AsValue(i interface{}) *Value
AsValue converts any given Value to a gonja.Value Usually being used within oSn functions passed to a template through a Context or within filter functions.
Example:
AsValue("my string")
func ToValue(data interface{}) *Value
func ValueError(err error) *Value
func (v *Value) Bool() bool
Bool returns the underlying value as bool. If the value is not bool, false will always be returned. If you're looking for true/false-evaluation of the underlying value, have a look on the IsTrue()-function.
func (v *Value) CanSlice() bool
CanSlice checks whether the underlying value is of type array, slice or string. You normally would use CanSlice() before using the Slice() operation.
func (v *Value) Contains(other *Value) bool
Contains checks whether the underlying value (which must be of type struct, map, string, array or slice) contains of another Value (e. g. used to check whether a struct contains of a specific field or a map contains a specific key).
Example:
AsValue("Hello, World!").Contains(AsValue("World")) == true
func (v *Value) EqualValueTo(other *Value) bool
EqualValueTo checks whether two values are containing the same value or object.
func (v *Value) Error() string
func (v *Value) Escaped() string
Escaped returns the escaped version of String()
func (v *Value) Float() float64
Float returns the underlying value as a float (converts the underlying value, if necessary). If it's not possible to convert the underlying value, it will return 0.0.
func (v *Value) Get(key string) (*Value, bool)
func (v *Value) Getattr(name string) (*Value, bool)
func (v *Value) Getitem(key interface{}) (*Value, bool)
func (v *Value) Index(i int) *Value
Index gets the i-th item of an array, slice or string. Otherwise it will return NIL.
func (v *Value) Integer() int
Integer returns the underlying value as an integer (converts the underlying value, if necessary). If it's not possible to convert the underlying value, it will return 0.
func (v *Value) Interface() interface{}
Interface gives you access to the underlying value.
func (v *Value) IsBool() bool
IsBool checks whether the underlying value is a bool
func (v *Value) IsCallable() bool
func (v *Value) IsDict() bool
func (v *Value) IsError() bool
func (v *Value) IsFloat() bool
IsFloat checks whether the underlying value is a float
func (v *Value) IsInteger() bool
IsInteger checks whether the underlying value is an integer
func (v *Value) IsIterable() bool
func (v *Value) IsList() bool
func (v *Value) IsNil() bool
IsNil checks whether the underlying value is NIL
func (v *Value) IsNumber() bool
IsNumber checks whether the underlying value is either an integer or a float.
func (v *Value) IsString() bool
IsString checks whether the underlying value is a string
func (v *Value) IsTrue() bool
IsTrue tries to evaluate the underlying value the Pythonic-way:
Returns TRUE in one the following cases:
Otherwise returns always FALSE.
func (v *Value) Items() []*Pair
func (v *Value) Iterate(fn func(idx, count int, key, value *Value) bool, empty func())
Iterate iterates over a map, array, slice or a string. It calls the function's first argument for every value with the following arguments:
idx current 0-index count total amount of items key *Value for the key or item value *Value (only for maps, the respective value for a specific key)
If the underlying value has no items or is not one of the types above, the empty function (function's second argument) will be called.
func (v *Value) IterateOrder(fn func(idx, count int, key, value *Value) bool, empty func(), reverse bool, sorted bool, caseSensitive bool)
IterateOrder behaves like Value.Iterate, but can iterate through an array/slice/string in reverse. Does not affect the iteration through a map because maps don't have any particular order. However, you can force an order using the `sorted` keyword (and even use `reversed sorted`).
func (v *Value) Keys() ValuesList
func (v *Value) Len() int
Len returns the length for an array, chan, map, slice or string. Otherwise it will return 0.
func (v *Value) Negate() *Value
Negate tries to negate the underlying value. It's mainly used for the NOT-operator and in conjunction with a call to return_value.IsTrue() afterwards.
Example:
AsValue(1).Negate().IsTrue() == false
func (v *Value) Set(key string, value interface{}) error
func (v *Value) Slice(i, j int) *Value
Slice slices an array, slice or string. Otherwise it will return an empty []int.
func (v *Value) String() string
String returns a string for the underlying value. If this value is not of type string, gonja tries to convert it. Currently the following types for underlying values are supported:
NIL values will lead to an empty string. Unsupported types are leading to their respective type name.
type ValuesList []*Value
func (vl ValuesList) Contains(value *Value) bool
func (vl ValuesList) Len() int
func (vl ValuesList) Less(i, j int) bool
func (vl ValuesList) String() string
func (vl ValuesList) Swap(i, j int)
VarArgs represents pythonic variadic args/kwargs
type VarArgs struct { Args []*Value KwArgs map[string]*Value }
func NewVarArgs() *VarArgs
func (va *VarArgs) Expect(args int, kwargs []*KwArg) *ReducedVarArgs
Expect validates VarArgs against an expected signature
func (va *VarArgs) ExpectArgs(args int) *ReducedVarArgs
ExpectArgs ensures VarArgs receive only arguments
func (va *VarArgs) ExpectKwArgs(kwargs []*KwArg) *ReducedVarArgs
ExpectKwArgs allow to specify optionnaly expected KwArgs
func (va *VarArgs) ExpectNothing() *ReducedVarArgs
ExpectNothing ensures VarArgs does not receive any argument
func (va *VarArgs) First() *Value
First returns the first argument or nil AsValue
func (va *VarArgs) GetKwarg(key string, fallback interface{}) *Value
GetKwarg gets a keyword arguments with fallback on default value