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