2013-05-21 19:53:36 +00:00
|
|
|
module PostHelper
|
|
|
|
def articles_by_year(articles)
|
|
|
|
hash = Hash.new { |h, k| h[k] = [] }
|
|
|
|
articles.inject(hash) do |output, article|
|
|
|
|
year = attribute_to_time(article[:created_at]).year
|
|
|
|
output[year] << article
|
|
|
|
output
|
2013-03-24 16:05:11 +00:00
|
|
|
end
|
2013-05-21 19:53:36 +00:00
|
|
|
end
|
2013-03-24 16:05:11 +00:00
|
|
|
|
2013-05-21 19:53:36 +00:00
|
|
|
def get_short_date(post)
|
|
|
|
attribute_to_time(post[:created_at]).strftime('%Y-%m-%d')
|
|
|
|
end
|
2013-03-24 22:01:15 +00:00
|
|
|
|
2013-05-21 19:53:36 +00:00
|
|
|
def get_pretty_date(post)
|
|
|
|
attribute_to_time(post[:created_at]).strftime('%-d %B, %Y')
|
|
|
|
end
|
2013-03-24 16:05:11 +00:00
|
|
|
|
2013-05-21 19:53:36 +00:00
|
|
|
def get_tags(post)
|
|
|
|
if post[:tags].nil? || post[:tags].empty?
|
|
|
|
"(not tagged)"
|
|
|
|
else
|
|
|
|
post[:tags].compact.map { |tag| tag.downcase }.sort.join(", ")
|
2013-03-24 16:05:11 +00:00
|
|
|
end
|
2013-05-21 19:53:36 +00:00
|
|
|
end
|
|
|
|
end
|