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:
Parker Moore 2014-10-27 15:58:42 -07:00
parent 4e8ebd999a
commit 3fb1356593
2 changed files with 15 additions and 1 deletions

View File

@ -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

View File

@ -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