Refactor data/[] fetching of item property.

This commit is contained in:
Parker Moore 2013-12-09 12:59:43 -05:00
parent 381ab4e71b
commit 063111737c
1 changed files with 9 additions and 5 deletions

View File

@ -170,11 +170,7 @@ module Jekyll
def group_by(input, property)
if groupable?(input)
input.group_by do |item|
if item.respond_to?(:data)
item.data[property.to_s].to_s
else
item[property.to_s].to_s
end
item_property(item, property).to_s
end.inject([]) do |memo, i|
memo << {"name" => i.first, "items" => i.last}
end
@ -199,5 +195,13 @@ module Jekyll
def groupable?(element)
element.respond_to?(:group_by)
end
def item_property(item, property)
if item.respond_to?(:data)
item.data[property.to_s]
else
item[property.to_s]
end
end
end
end