Reorganize helpers

This commit is contained in:
Ariejan de Vroom 2013-03-24 17:05:11 +01:00
parent a2f9aa7d77
commit 1e0d2cec59
3 changed files with 27 additions and 29 deletions

View File

@ -22,33 +22,4 @@ unless defined? LOADED_DEFAULT_CONFIG
# javascript concatenation
require 'nanoc/filters/javascript_concatenator'
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
module PostHelper
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
include PostHelper
end

26
lib/helpers/post.rb Normal file
View File

@ -0,0 +1,26 @@
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

1
lib/helpers_.rb Normal file
View File

@ -0,0 +1 @@
include PostHelper