2010-10-20 15:42:17 +02:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2011-05-26 12:10:16 +02:00
|
|
|
# The class represents all the tags, whereas
|
|
|
|
# the instance represents each single tag.
|
2010-10-20 15:42:17 +02:00
|
|
|
class Tag < Ace::Item
|
2011-05-26 08:24:31 +02:00
|
|
|
before Ace::TemplateFilter, layout: "tag.html"
|
2010-10-20 15:42:17 +02:00
|
|
|
|
2011-05-26 12:10:16 +02:00
|
|
|
def self.tags
|
2010-10-20 15:42:17 +02:00
|
|
|
Post.instances.inject(Hash.new) do |buffer, post|
|
|
|
|
if tags = post.metadata[:tags]
|
|
|
|
tags.each do |tag|
|
|
|
|
buffer[tag] ||= Array.new
|
|
|
|
buffer[tag] << post
|
|
|
|
end
|
|
|
|
end
|
|
|
|
buffer
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-26 12:10:16 +02:00
|
|
|
def self.generate
|
2010-10-20 15:42:17 +02:00
|
|
|
self.tags.each do |tag_title, items|
|
|
|
|
tag_name = tag_title.downcase.gsub(" ", "-")
|
|
|
|
metadata = {title: tag_title, timestamp: Time.now}
|
|
|
|
tag = Tag.create(metadata, items)
|
|
|
|
tag.output_path = "output/tags/#{tag_name}.html"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|