Refactor data/[] fetching of item property.
This commit is contained in:
parent
381ab4e71b
commit
063111737c
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue