Documentation ¶
Index ¶
- type StdRegistry
- func (sr *StdRegistry) All(values ...any) bool
- func (sr *StdRegistry) Any(values ...any) bool
- func (sr *StdRegistry) Cat(values ...any) string
- func (sr *StdRegistry) Coalesce(values ...any) any
- func (sr *StdRegistry) Default(defaultValue any, given ...any) any
- func (sr *StdRegistry) Empty(given any) bool
- func (sr *StdRegistry) Hello() string
- func (sr *StdRegistry) LinkHandler(fh sprout.Handler) error
- func (sr *StdRegistry) RegisterFunctions(funcsMap sprout.FunctionMap) error
- func (sr *StdRegistry) Ternary(trueValue any, falseValue any, condition bool) any
- func (sr *StdRegistry) Uid() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type StdRegistry ¶
type StdRegistry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
func NewRegistry() *StdRegistry
NewRegistry creates a new instance of your registry with the embedded Handler.
func (*StdRegistry) All ¶
func (sr *StdRegistry) All(values ...any) bool
All checks if all values in the provided variadic slice are non-empty. It returns true only if none of the values are considered empty by the Empty method.
Parameters:
values ...any - a variadic parameter list of values to be checked.
Returns:
bool - true if all values are non-empty, false otherwise.
Example:
{{ 1, "hello", true | all }} // Output: true {{ 1, "", true | all }} // Output: false
func (*StdRegistry) Any ¶
func (sr *StdRegistry) Any(values ...any) bool
func (*StdRegistry) Cat ¶
func (sr *StdRegistry) Cat(values ...any) string
Cat concatenates a series of values into a single string. Each value is converted to its string representation and separated by a space. Nil values are skipped, and no trailing spaces are added.
Parameters:
values ...any - a variadic parameter list of values to be concatenated.
Returns:
string - a single string composed of all non-nil input values separated by spaces.
Example:
{{ "Hello", nil, 123, true | cat }} // Output: "Hello 123 true"
func (*StdRegistry) Coalesce ¶
func (sr *StdRegistry) Coalesce(values ...any) any
func (*StdRegistry) Default ¶
func (sr *StdRegistry) Default(defaultValue any, given ...any) any
Default returns the first non-empty value from the given arguments or a default value if the argument list is empty or the first element is empty. It accepts a default value `defaultValue` of any type and a variadic slice `given` of any type. If `given` is not provided or the first element in `given` is empty, it returns `defaultValue`. Otherwise, it returns the first element of `given`. If you want to catch the first non-empty value from a list of values, use the `Coalesce` function instead.
Parameters:
defaultValue any - the default value to return if no valid argument is provided or if the first argument is empty. given ...any - a variadic slice of any type to check the first element of it for emptiness.
Returns:
any - the first element of `given`, or `defaultValue` if `given` is empty or all values are empty.
Example:
{{ nil | default "default" }} // Output: "default" {{ "" | default "default" }} // Output: "default" {{ "first" | default "default" }} // Output: "first" {{ "first" | default "default" "second" }} // Output: "second"
func (*StdRegistry) Empty ¶
func (sr *StdRegistry) Empty(given any) bool
Empty evaluates the emptiness of the provided value 'given'. It returns true if 'given' is considered empty based on its type. This method is essential for determining the presence or absence of meaningful value across various data types.
Parameters:
given any - the value to be evaluated for emptiness.
Returns:
bool - true if 'given' is empty, false otherwise.
This method utilizes the reflect package to inspect the type and value of 'given'. Depending on the type, it checks for nil pointers, zero-length collections (arrays, slices, maps, and strings), zero values of numeric types (integers, floats, complex numbers, unsigned ints), and false for booleans.
Example:
{{ nil | empty }} // Output: true {{ "" | empty }} // Output: true {{ 0 | empty }} // Output: true {{ false | empty }} // Output: true {{ struct{}{} | empty }} // Output: false
func (*StdRegistry) Hello ¶
func (sr *StdRegistry) Hello() string
Hello returns a greeting string. It simply returns the string "Hello!" to be used as a test function.
func (*StdRegistry) LinkHandler ¶
func (sr *StdRegistry) LinkHandler(fh sprout.Handler) error
LinkHandler links the handler to the registry at runtime.
func (*StdRegistry) RegisterFunctions ¶
func (sr *StdRegistry) RegisterFunctions(funcsMap sprout.FunctionMap) error
RegisterFunctions registers all functions of the registry.
func (*StdRegistry) Ternary ¶
func (sr *StdRegistry) Ternary(trueValue any, falseValue any, condition bool) any
Ternary mimics the ternary conditional operator found in many programming languages. It returns 'trueValue' if 'condition' is true, otherwise 'falseValue'.
Parameters:
trueValue any - the value to return if 'condition' is true. falseValue any - the value to return if 'condition' is false. condition bool - the condition to evaluate.
Returns:
any - the result based on the evaluated condition.
Example:
{{ "yes", "no", true | ternary }} // Output: "yes" {{ "yes", "no", false | ternary }} // Output: "no"
func (*StdRegistry) Uid ¶
func (sr *StdRegistry) Uid() string
Uid returns the unique identifier of the registry.