From 4776b27ff363fe2e7406be77f5f2f061ee8ecb8f Mon Sep 17 00:00:00 2001 From: Aidan Feldman Date: Thu, 27 Nov 2014 04:20:05 -0600 Subject: [PATCH] reduce nesting of #as_liquid --- lib/jekyll/filters.rb | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/jekyll/filters.rb b/lib/jekyll/filters.rb index fc0907a9..e147c93e 100644 --- a/lib/jekyll/filters.rb +++ b/lib/jekyll/filters.rb @@ -327,24 +327,21 @@ module Jekyll end def as_liquid(item) - case item - when Hash + if item.class == Hash pairs = item.map { |k, v| as_liquid([k, v]) } Hash[pairs] - when Array + elsif item.class == Array item.map{ |i| as_liquid(i) } - else # simple type - if item.respond_to?(:to_liquid) - liquidated = item.to_liquid - # prevent infinite recursion - if liquidated == item - item - else - as_liquid(liquidated) - end - else + elsif item.respond_to?(:to_liquid) + liquidated = item.to_liquid + # prevent infinite recursion for simple types (which return `self`) + if liquidated == item item + else + as_liquid(liquidated) end + else + item end end end