From df3c163eebbb23a10c32266da9ae653b4d5a604d Mon Sep 17 00:00:00 2001 From: Anatol Broder Date: Thu, 8 May 2014 07:47:43 +0200 Subject: [PATCH] Use item_property --- lib/jekyll/filters.rb | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/lib/jekyll/filters.rb b/lib/jekyll/filters.rb index 50cfea48..67c8f264 100644 --- a/lib/jekyll/filters.rb +++ b/lib/jekyll/filters.rb @@ -193,12 +193,12 @@ module Jekyll # Sort an array of objects # # input - the object array - # key - key within each object to filter by + # property - property within each object to filter by # nils ('first' | 'last') - nils appear before or after non-nil values # # Returns the filtered array of objects - def sort(input, key = nil, nils = "first") - if key.nil? + def sort(input, property = nil, nils = "first") + if property.nil? input.sort else case @@ -213,12 +213,15 @@ module Jekyll end input.sort { |a, b| - if !hash_property(a, key).nil? && hash_property(b, key).nil? + a_p = item_property(a, property) + b_p = item_property(b, property) + + if !a_p.nil? && b_p.nil? - order - elsif hash_property(a, key).nil? && !hash_property(b, key).nil? + elsif a_p.nil? && !b_p.nil? + order else - hash_property(a, key) <=> hash_property(b, key) + a_p <=> b_p end } end @@ -250,16 +253,5 @@ module Jekyll item[property.to_s] end end - - def hash_property(hash, property) - return item_property(hash, property) - if hash.respond_to?('[]'.freeze) - hash[property] - elsif hash.respond_to?(property) - hash.send(property) - else - nil - end - end end end