feat: add named filter arguments and allow_false for default filter#143
Open
feat: add named filter arguments and allow_false for default filter#143
Conversation
Add support for keyword arguments in filter expressions (e.g.,
`{{ val | default: "fallback", allow_false: true }}`). Keyword
arguments are collected into a map[string]any and passed as a
variadic trailing parameter to the filter function.
The default filter now accepts an `allow_false` keyword argument
that, when true, preserves false values instead of replacing them
with the default.
Closes #42, closes #75
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
{{ val | default: "fallback", allow_false: true }})map[string]anypassed as a variadic trailing parameter to filter functionsdefaultfilter now acceptsallow_false: trueto preservefalsevalues instead of replacing them with the defaultCloses #42, closes #75
Changes
expressions/builders.go: AddedfilterArgsandkeywordArgtypesexpressions/expressions.y: Extendedfilter_paramsgrammar rule to acceptKEYWORD exprpairs; changed union type from[]valueFnto*filterArgsexpressions/y.go: Regenerated from expressions.yexpressions/context.go: UpdatedContextinterface signature forApplyFilterexpressions/filters.go: UpdatedApplyFilterto evaluate keyword args into amap[string]anyand append as trailing argumentexpressions/filters_test.go: Updated tests for newfilterArgstype; added keyword args testfilters/standard_filters.go: Updateddefaultfilter to accept variadickwargsand check forallow_falsefilters/standard_filters_test.go: Added test cases forallow_falsebehaviorTest plan
allow_false: truewith false, nil, empty string valuesApplyFilterfilterArgstype