From fd98d5b1e694dfbbf2e8524ee3067ece8257a1ee Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 23 Apr 2014 14:00:13 -0400 Subject: [PATCH] Fetch collection names agnostically regarding the data structure of config['collections'] --- lib/jekyll/site.rb | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 1ca0349b..9a937220 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -91,10 +91,23 @@ module Jekyll # # Returns a Hash containing collection name-to-instance pairs. def collections - @collections ||= if config['collections'] - Hash[config['collections'].map { |coll| [coll, Jekyll::Collection.new(self, coll)] } ] + @collections ||= Hash[collection_names.map { |coll| [coll, Jekyll::Collection.new(self, coll)] } ] + end + + # The list of collection names. + # + # Returns an array of collection names from the configuration, + # or an empty array if the `collections` key is not set. + def collection_names + case config['collections'] + when Hash + config['collections'].keys + when Array + config['collections'] + when nil + [] else - Hash.new + raise ArgumentError, "Your `collections` key must be a hash or an array." end end