reduce nesting of #as_liquid
This commit is contained in:
parent
87d08ec827
commit
4776b27ff3
|
@ -327,24 +327,21 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
def as_liquid(item)
|
def as_liquid(item)
|
||||||
case item
|
if item.class == Hash
|
||||||
when Hash
|
|
||||||
pairs = item.map { |k, v| as_liquid([k, v]) }
|
pairs = item.map { |k, v| as_liquid([k, v]) }
|
||||||
Hash[pairs]
|
Hash[pairs]
|
||||||
when Array
|
elsif item.class == Array
|
||||||
item.map{ |i| as_liquid(i) }
|
item.map{ |i| as_liquid(i) }
|
||||||
else # simple type
|
elsif item.respond_to?(:to_liquid)
|
||||||
if item.respond_to?(:to_liquid)
|
liquidated = item.to_liquid
|
||||||
liquidated = item.to_liquid
|
# prevent infinite recursion for simple types (which return `self`)
|
||||||
# prevent infinite recursion
|
if liquidated == item
|
||||||
if liquidated == item
|
|
||||||
item
|
|
||||||
else
|
|
||||||
as_liquid(liquidated)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
item
|
item
|
||||||
|
else
|
||||||
|
as_liquid(liquidated)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
item
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue