The jsonify filter should deep-convert to Liquid when given an Array.
Fixes https://github.com/github/choosealicense.com/issues/225
This commit is contained in:
parent
4e8ebd999a
commit
3fb1356593
|
@ -327,7 +327,12 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
def as_liquid(item)
|
def as_liquid(item)
|
||||||
|
case item
|
||||||
|
when Array
|
||||||
|
item.map{ |i| as_liquid(i) }
|
||||||
|
else
|
||||||
item.respond_to?(:to_liquid) ? item.to_liquid : item
|
item.respond_to?(:to_liquid) ? item.to_liquid : item
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -147,6 +147,15 @@ class TestFilters < Test::Unit::TestCase
|
||||||
assert_equal "[1,2]", @filter.jsonify([1, 2])
|
assert_equal "[1,2]", @filter.jsonify([1, 2])
|
||||||
assert_equal "[{\"name\":\"Jack\"},{\"name\":\"Smith\"}]", @filter.jsonify([{:name => 'Jack'}, {:name => 'Smith'}])
|
assert_equal "[{\"name\":\"Jack\"},{\"name\":\"Smith\"}]", @filter.jsonify([{:name => 'Jack'}, {:name => 'Smith'}])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "call #to_liquid " do
|
||||||
|
class AThing < Struct.new(:name)
|
||||||
|
def to_liquid
|
||||||
|
{ "name" => name, :v => 1 }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert_equal "[{\"name\":\"Jeremiah\",\"v\":1},{\"name\":\"Smathers\",\"v\":1}]", @filter.jsonify([AThing.new("Jeremiah"), AThing.new("Smathers")])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "group_by filter" do
|
context "group_by filter" do
|
||||||
|
|
Loading…
Reference in New Issue