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, value ...any) any
- func (sr *StdRegistry) Empty(value 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.
For an example of this function in a Go template, refer to Sprout Documentation: all.
func (*StdRegistry) Any ¶
func (sr *StdRegistry) Any(values ...any) bool
Any checks if any of the provided values are non-empty. It returns true if at least one value is non-empty.
Parameters:
values ...any - a variadic parameter list of values to be checked.
Returns:
bool - true if any value is non-empty, false if all are empty.
For an example of this function in a Go template, refer to Sprout Documentation: any.
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.
For an example of this function in a Go template, refer to Sprout Documentation: cat.
func (*StdRegistry) Coalesce ¶
func (sr *StdRegistry) Coalesce(values ...any) any
Coalesce returns the first non-empty value from the given list. If all values are empty, it returns nil.
Parameters:
values ...any - a variadic parameter list of values from which the first non-empty value should be selected.
Returns:
any - the first non-empty value, or nil if all values are empty.
For an example of this function in a Go template, refer to Sprout Documentation: coalesce.
func (*StdRegistry) Default ¶
func (sr *StdRegistry) Default(defaultValue any, value ...any) any
Default returns the first non-empty value from the value 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 `value` of any type. If `value` is not provided or the first element in `value` is empty, it returns `defaultValue`. Otherwise, it returns the first element of `value`. 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. value ...any - a variadic slice of any type to check the first element of it for emptiness.
Returns:
any - the first element of `value`, or `defaultValue` if `value` is empty or all values are empty.
For an example of this function in a Go template, refer to Sprout Documentation: default.
func (*StdRegistry) Empty ¶
func (sr *StdRegistry) Empty(value any) bool
Empty evaluates the emptiness of the provided value 'value'. It returns true if 'value' is considered empty based on its type. This method is essential for determining the presence or absence of meaningful value across various data types.
This method utilizes the reflect package to inspect the type and value of 'value'. 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.
Parameters:
value any - the value to be evaluated for emptiness.
Returns:
bool - true if 'value' is empty, false otherwise.
For an example of this function in a Go template, refer to Sprout Documentation: empty.
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.
For an example of this function in a Go template, refer to Sprout Documentation: ternary.
func (*StdRegistry) UID ¶
func (sr *StdRegistry) UID() string
UID returns the unique identifier of the registry.