commit
9e0ed00a59
|
@ -222,7 +222,7 @@ module Jekyll
|
|||
def where(input, property, value)
|
||||
return input unless input.is_a?(Enumerable)
|
||||
input = input.values if input.is_a?(Hash)
|
||||
input.select { |object| item_property(object, property).to_s == value.to_s }
|
||||
input.select { |object| Array(item_property(object, property)).map(&:to_s).include?(value.to_s) }
|
||||
end
|
||||
|
||||
# Sort an array of objects
|
||||
|
|
|
@ -321,6 +321,21 @@ class TestFilters < JekyllUnitTest
|
|||
assert_equal 2, @filter.where(@array_of_objects, "color", "red").length
|
||||
end
|
||||
|
||||
should "filter array properties appropriately" do
|
||||
hash = {"a"=>{"tags"=>["x","y"]}, "b"=>{"tags"=>["x"]}, "c"=>{"tags"=>["y","z"]}}
|
||||
assert_equal 2, @filter.where(hash, "tags", "x").length
|
||||
end
|
||||
|
||||
should "filter array properties alongside string properties" do
|
||||
hash = {"a"=>{"tags"=>["x","y"]}, "b"=>{"tags"=>"x"}, "c"=>{"tags"=>["y","z"]}}
|
||||
assert_equal 2, @filter.where(hash, "tags", "x").length
|
||||
end
|
||||
|
||||
should "not match substrings" do
|
||||
hash = {"a"=>{"category"=>"bear"}, "b"=>{"category"=>"wolf"}, "c"=>{"category"=>["bear","lion"]}}
|
||||
assert_equal 0, @filter.where(hash, "category", "ear").length
|
||||
end
|
||||
|
||||
should "stringify during comparison for compatibility with liquid parsing" do
|
||||
hash = {
|
||||
"The Words" => {"rating" => 1.2, "featured" => false},
|
||||
|
|
Loading…
Reference in New Issue