Reorganize helpers
This commit is contained in:
parent
a2f9aa7d77
commit
1e0d2cec59
|
@ -22,33 +22,4 @@ unless defined? LOADED_DEFAULT_CONFIG
|
||||||
|
|
||||||
# javascript concatenation
|
# javascript concatenation
|
||||||
require 'nanoc/filters/javascript_concatenator'
|
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
|
end
|
26
lib/helpers/post.rb
Normal file
26
lib/helpers/post.rb
Normal 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
1
lib/helpers_.rb
Normal file
|
@ -0,0 +1 @@
|
||||||
|
include PostHelper
|
Loading…
Reference in New Issue
Block a user