Documentation
¶
Index ¶
- Variables
- func AnyArgument(output *interface{}) func(*Value) error
- func BoolArgument(output *bool) func(*Value) error
- func CaseInsensitive(data sort.Interface) sort.Interface
- func FloatArgument(output *float64) func(v *Value) error
- func IntArgument(output *int) func(v *Value) error
- func KeywordArgument(name string, defaultValue *Value, transmuters ...ArgumentTransmuter) *argument
- func NumberArgument(output *float64) func(v *Value) error
- func OrArgument(transmuters ...ArgumentTransmuter) func(*Value) error
- func PositionalArgument(name string, fallback *Value, transmuters ...ArgumentTransmuter) *argument
- func Self(r *Renderer) map[string]func() string
- func StringArgument(output *string) func(*Value) error
- func StringEnumArgument(output *string, options []string) func(v *Value) error
- func StringListArgument(output *[]string) func(*Value) error
- type ArgumentTransmuter
- type Context
- type ControlStructure
- type ControlStructureSet
- func (c *ControlStructureSet) Exists(name string) bool
- func (c *ControlStructureSet) Get(name string) (parser.ControlStructureParser, bool)
- func (c *ControlStructureSet) Register(name string, parser parser.ControlStructureParser) error
- func (c *ControlStructureSet) Replace(name string, parser parser.ControlStructureParser) error
- func (c *ControlStructureSet) Update(other *ControlStructureSet) *ControlStructureSet
- type Dict
- type Environment
- type ErrInvalidCall
- type Evaluator
- func (e *Evaluator) Eval(node nodes.Expression) *Value
- func (e *Evaluator) EvalTest(expr *nodes.TestExpression) *Value
- func (e *Evaluator) EvaluateFiltered(expr *nodes.FilteredExpression) *Value
- func (e *Evaluator) ExecuteFilter(fc *nodes.FilterCall, v *Value) *Value
- func (e *Evaluator) ExecuteFilterByName(name string, in *Value, params *VarArgs) *Value
- func (e *Evaluator) ExecuteTest(tc *nodes.TestCall, v *Value) *Value
- func (e *Evaluator) ExecuteTestByName(name string, in *Value, params *VarArgs) *Value
- type FilterFunction
- type FilterSet
- type KwArg
- type Macro
- type MacroSet
- type Method
- type MethodSet
- type Methods
- type Pair
- type ReducedVarArgs
- type Renderer
- type Template
- type TestFunction
- type TestSet
- type Value
- func (v *Value) Bool() bool
- func (v *Value) CanSlice() bool
- func (v *Value) Contains(other *Value) bool
- func (v *Value) EqualValueTo(other *Value) bool
- func (v *Value) Error() string
- func (v *Value) Escaped() string
- func (v *Value) Float() float64
- func (v *Value) Get(key string) (*Value, bool)
- func (v *Value) GetAttribute(name string) (*Value, bool)
- func (v *Value) GetItem(key interface{}) (*Value, bool)
- func (v *Value) Index(i int) *Value
- func (v *Value) Integer() int
- func (v *Value) Interface() interface{}
- func (v *Value) IsBool() bool
- func (v *Value) IsCallable() bool
- func (v *Value) IsDict() bool
- func (v *Value) IsError() bool
- func (v *Value) IsFloat() bool
- func (v *Value) IsInteger() bool
- func (v *Value) IsIterable() bool
- func (v *Value) IsList() bool
- func (v *Value) IsNil() bool
- func (v *Value) IsNumber() bool
- func (v *Value) IsString() bool
- func (v *Value) IsTrue() bool
- func (v *Value) Items() []*Pair
- func (v *Value) Iterate(fn func(idx, count int, key, value *Value) bool, empty func())
- func (v *Value) IterateOrder(fn func(idx, count int, key, value *Value) bool, empty func(), reverse bool, ...)
- func (v *Value) Keys() ValuesList
- func (v *Value) Len() int
- func (v *Value) Negate() *Value
- func (v *Value) Set(key *Value, value interface{}) error
- func (v *Value) Slice(i, j int) *Value
- func (v *Value) String() string
- func (v *Value) ToGoSimpleType(allowInterfaceKeys bool) interface{}
- type ValuesList
- type VarArgs
- func (v *VarArgs) Expect(arguments int, keywordArguments []*KwArg) *ReducedVarArgs
- func (va *VarArgs) ExpectArgs(args int) *ReducedVarArgs
- func (va *VarArgs) ExpectKwArgs(kwargs []*KwArg) *ReducedVarArgs
- func (va *VarArgs) ExpectNothing() *ReducedVarArgs
- func (va *VarArgs) First() *Value
- func (va *VarArgs) GetKeywordArgument(key string, fallback interface{}) *Value
- func (v *VarArgs) Take(arguments ...*argument) error
Constants ¶
This section is empty.
Variables ¶
var TypeDict = reflect.TypeOf(Dict{})
Functions ¶
func AnyArgument ¶
func BoolArgument ¶
func CaseInsensitive ¶
CaseInsensitive returns the the data sorted in a case insensitive way (if string).
func FloatArgument ¶
func IntArgument ¶
func KeywordArgument ¶
func KeywordArgument(name string, defaultValue *Value, transmuters ...ArgumentTransmuter) *argument
func NumberArgument ¶
func OrArgument ¶
func OrArgument(transmuters ...ArgumentTransmuter) func(*Value) error
func PositionalArgument ¶
func PositionalArgument(name string, fallback *Value, transmuters ...ArgumentTransmuter) *argument
func StringArgument ¶
func StringEnumArgument ¶
func StringListArgument ¶
Types ¶
type ArgumentTransmuter ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func EmptyContext ¶
func EmptyContext() *Context
func NewContext ¶
type ControlStructure ¶
type ControlStructure interface {
nodes.ControlStructure
Execute(*Renderer, *nodes.ControlStructureBlock) error
}
type ControlStructureSet ¶
type ControlStructureSet struct {
// contains filtered or unexported fields
}
func NewControlStructureSet ¶
func NewControlStructureSet(statements map[string]parser.ControlStructureParser) *ControlStructureSet
func (*ControlStructureSet) Exists ¶
func (c *ControlStructureSet) Exists(name string) bool
Exists returns true if the given test is already registered
func (*ControlStructureSet) Get ¶
func (c *ControlStructureSet) Get(name string) (parser.ControlStructureParser, bool)
func (*ControlStructureSet) Register ¶
func (c *ControlStructureSet) Register(name string, parser parser.ControlStructureParser) 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
func (*ControlStructureSet) Replace ¶
func (c *ControlStructureSet) Replace(name string, parser parser.ControlStructureParser) 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 (*ControlStructureSet) Update ¶
func (c *ControlStructureSet) Update(other *ControlStructureSet) *ControlStructureSet
type Environment ¶
type Environment struct {
Filters *FilterSet
ControlStructures *ControlStructureSet
Tests *TestSet
Context *Context
Methods Methods
}
type ErrInvalidCall ¶
type ErrInvalidCall error
type Evaluator ¶
type Evaluator struct {
Config *config.Config
Environment *Environment
Loader loaders.Loader
}
func (*Evaluator) EvaluateFiltered ¶
func (e *Evaluator) EvaluateFiltered(expr *nodes.FilteredExpression) *Value
EvaluateFiltered evaluate a filtered expression
func (*Evaluator) ExecuteFilter ¶
func (e *Evaluator) ExecuteFilter(fc *nodes.FilterCall, v *Value) *Value
ExecuteFilter execute a filter node
func (*Evaluator) ExecuteFilterByName ¶
ExecuteFilterByName execute a filter given its name
func (*Evaluator) ExecuteTest ¶
type FilterFunction ¶
FilterFunction is the type filter functions must fulfil
type FilterSet ¶
type FilterSet struct {
// contains filtered or unexported fields
}
func NewFilterSet ¶
func NewFilterSet(filters map[string]FilterFunction) *FilterSet
func (*FilterSet) Get ¶
func (f *FilterSet) Get(name string) (FilterFunction, bool)
Exists returns true if the given filter is already registered
func (*FilterSet) Register ¶
func (f *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
type MacroSet ¶
func (*MacroSet) Register ¶
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.john-doe.de/post/gonja/ for more about writing filters and tags.
type MethodSet ¶
type MethodSet[I interface{}] struct {
// contains filtered or unexported fields
}
func NewMethodSet ¶
type ReducedVarArgs ¶
type ReducedVarArgs struct {
*VarArgs
// contains filtered or unexported fields
}
ReducedVarArgs represents python variadic arguments / keyword arguments but values are reduced (ie. keyword arguments given as arguments are accessible by name)
func (*ReducedVarArgs) Error ¶
func (r *ReducedVarArgs) Error() string
func (*ReducedVarArgs) IsError ¶
func (r *ReducedVarArgs) IsError() bool
IsError returns true if there was an error on Expect call
type Renderer ¶
type Renderer struct {
Config *config.Config
Environment *Environment
Loader loaders.Loader
Template *Template
RootNode *nodes.Template
Output io.Writer
}
Renderer is a node visitor in charge of rendering
func NewRenderer ¶
func NewRenderer(environment *Environment, wr io.Writer, config *config.Config, loader loaders.Loader, template *Template) *Renderer
NewRenderer initialize a new renderer
func (*Renderer) ExecuteWrapper ¶
ExecuteWrapper wraps the nodes.Wrapper execution logic
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
func NewTemplate ¶
func NewTemplate(identifier string, config *config.Config, loader loaders.Loader, environment *Environment) (*Template, error)
Create a gonja template instance that can be executed with a given context later on
func (*Template) Execute ¶
Executes the template and return the rendered content in the provided writer
func (*Template) ExecuteToBytes ¶
Executes the template and return the rendered content as bytes
func (*Template) ExecuteToString ¶
Executes the template and return the rendered content as a string
type TestFunction ¶
TestFunction is the type test functions must fulfil
type TestSet ¶
type TestSet struct {
// contains filtered or unexported fields
}
TestSet maps test names to their TestFunction handler
func NewTestSet ¶
func NewTestSet(tests map[string]TestFunction) *TestSet
func (*TestSet) Register ¶
func (t *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
type Value ¶
type Value struct {
Val reflect.Value
Safe bool // used to indicate whether a Value needs explicit escaping in the template
}
func AsSafeValue ¶
func AsSafeValue(i interface{}) *Value
AsSafeValue works like AsValue, but does not apply the 'escape' filter.
func AsValue ¶
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 ValueError ¶
func (*Value) 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 (*Value) CanSlice ¶
CanSlice checks whether the underlying value is of type array, slice or string. You normally would use CanSlice() before using the Slice() operation.
func (*Value) Contains ¶
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 (*Value) EqualValueTo ¶
EqualValueTo checks whether two values are containing the same value or object.
func (*Value) Float ¶
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 (*Value) Index ¶
Index gets the i-th item of an array, slice or string. Otherwise it will return NIL.
func (*Value) Integer ¶
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 (*Value) Interface ¶
func (v *Value) Interface() interface{}
Interface gives you access to the underlying value.
func (*Value) IsCallable ¶
func (*Value) IsIterable ¶
func (*Value) IsNumber ¶
IsNumber checks whether the underlying value is either an integer or a float.
func (*Value) IsTrue ¶
IsTrue tries to evaluate the underlying value the Pythonic-way:
Returns TRUE in one the following cases:
- int != 0
- uint != 0
- float != 0.0
- len(array/chan/map/slice/string) > 0
- bool == true
- underlying value is a struct
Otherwise returns always FALSE.
func (*Value) Iterate ¶
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 (*Value) IterateOrder ¶
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 (*Value) Keys ¶
func (v *Value) Keys() ValuesList
func (*Value) Len ¶
Len returns the length for an array, chan, map, slice or string. Otherwise it will return 0.
func (*Value) Negate ¶
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 (*Value) Slice ¶
Slice slices an array, slice or string. Otherwise it will return an empty []int.
func (*Value) 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:
- string
- int/uint (any size)
- float (any precision)
- bool
- time.Time
- String() will be called on the underlying value if provided
NIL values will lead to an empty string. Unsupported types are leading to their respective type name.
func (*Value) ToGoSimpleType ¶
type ValuesList ¶
type ValuesList []*Value
func (ValuesList) Contains ¶
func (vl ValuesList) Contains(value *Value) bool
func (ValuesList) Len ¶
func (vl ValuesList) Len() int
func (ValuesList) Less ¶
func (vl ValuesList) Less(i, j int) bool
func (ValuesList) String ¶
func (vl ValuesList) String() string
func (ValuesList) Swap ¶
func (vl ValuesList) Swap(i, j int)
type VarArgs ¶
VarArgs represents pythonic variadic args/kwargs
func NewVarArgs ¶
func NewVarArgs() *VarArgs
func (*VarArgs) Expect ¶
func (v *VarArgs) Expect(arguments int, keywordArguments []*KwArg) *ReducedVarArgs
Expect validates VarArgs against an expected signature
func (*VarArgs) ExpectArgs ¶
func (va *VarArgs) ExpectArgs(args int) *ReducedVarArgs
ExpectArgs ensures VarArgs receive only arguments
func (*VarArgs) ExpectKwArgs ¶
func (va *VarArgs) ExpectKwArgs(kwargs []*KwArg) *ReducedVarArgs
ExpectKwArgs allow to specify optionnaly expected KwArgs
func (*VarArgs) ExpectNothing ¶
func (va *VarArgs) ExpectNothing() *ReducedVarArgs
ExpectNothing ensures VarArgs does not receive any argument
func (*VarArgs) GetKeywordArgument ¶
GetKeywordArgument gets a keyword arguments with fallback on default value