Fetch collection names agnostically regarding the data structure of config['collections']

This commit is contained in:
Parker Moore 2014-04-23 14:00:13 -04:00
parent 330005d932
commit fd98d5b1e6
1 changed files with 16 additions and 3 deletions

View File

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