Allow multiple binary operator in where_exp filter (#8047)
Merge pull request 8047
This commit is contained in:
parent
ab6ef0b257
commit
0f4c8d2248
|
@ -432,10 +432,14 @@ module Jekyll
|
|||
#
|
||||
# Returns an instance of Liquid::Condition
|
||||
def parse_binary_comparison(parser)
|
||||
parse_comparison(parser).tap do |condition|
|
||||
binary_operator = parser.id?("and") || parser.id?("or")
|
||||
condition.send(binary_operator, parse_comparison(parser)) if binary_operator
|
||||
condition = parse_comparison(parser)
|
||||
first_condition = condition
|
||||
while (binary_operator = parser.id?("and") || parser.id?("or"))
|
||||
child_condition = parse_comparison(parser)
|
||||
condition.send(binary_operator, child_condition)
|
||||
condition = child_condition
|
||||
end
|
||||
first_condition
|
||||
end
|
||||
|
||||
# Generates a Liquid::Condition object from a Liquid::Parser object based on whether the parsed
|
||||
|
|
|
@ -997,6 +997,23 @@ class TestFilters < JekyllUnitTest
|
|||
)
|
||||
end
|
||||
|
||||
should "filter objects across multiple conditions" do
|
||||
sample = [
|
||||
{ "color" => "teal", "size" => "large", "type" => "variable" },
|
||||
{ "color" => "red", "size" => "large", "type" => "fixed" },
|
||||
{ "color" => "red", "size" => "medium", "type" => "variable" },
|
||||
{ "color" => "blue", "size" => "medium", "type" => "fixed" },
|
||||
]
|
||||
assert_equal(
|
||||
[
|
||||
{ "color" => "red", "size" => "large", "type" => "fixed" },
|
||||
],
|
||||
@filter.where_exp(
|
||||
sample, "item", "item.type == 'fixed' and item.color == 'red' or item.color == 'teal'"
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
should "stringify during comparison for compatibility with liquid parsing" do
|
||||
hash = {
|
||||
"The Words" => { "rating" => 1.2, "featured" => false },
|
||||
|
|
Loading…
Reference in New Issue