Allow filters to sort & select based on subvalues (#5622)
Merge pull request 5622
This commit is contained in:
parent
158ab6ce93
commit
e031ac9b27
|
@ -361,7 +361,9 @@ module Jekyll
|
|||
private
|
||||
def item_property(item, property)
|
||||
if item.respond_to?(:to_liquid)
|
||||
item.to_liquid[property.to_s]
|
||||
property.to_s.split(".").reduce(item.to_liquid) do |subvalue, attribute|
|
||||
subvalue[attribute]
|
||||
end
|
||||
elsif item.respond_to?(:data)
|
||||
item.data[property.to_s]
|
||||
else
|
||||
|
|
|
@ -949,6 +949,12 @@ class TestFilters < JekyllUnitTest
|
|||
assert_equal [{ "a" => 1 }, { "a" => 2 }, { "b" => 1 }],
|
||||
@filter.sort([{ "a" => 2 }, { "b" => 1 }, { "a" => 1 }], "a", "last")
|
||||
end
|
||||
should "return sorted by subproperty array" do
|
||||
assert_equal [{ "a" => { "b" => 1 } }, { "a" => { "b" => 2 } },
|
||||
{ "a" => { "b" => 3 } }, ],
|
||||
@filter.sort([{ "a" => { "b" => 2 } }, { "a" => { "b" => 1 } },
|
||||
{ "a" => { "b" => 3 } }, ], "a.b")
|
||||
end
|
||||
end
|
||||
|
||||
context "to_integer filter" do
|
||||
|
|
Loading…
Reference in New Issue