26 lines
673 B
Ruby
26 lines
673 B
Ruby
|
module PostHelper
|
||
|
def articles_by_year
|
||
|
hash = Hash.new { |h, k| h[k] = [] }
|
||
|
sorted_articles.inject(hash) do |output, article|
|
||
|
year = attribute_to_time(article[:created_at]).year
|
||
|
output[year] << article
|
||
|
output
|
||
|
end
|
||
|
end
|
||
|
|
||
|
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
|