class Rollin::Blog

Public Class Methods

new(options = {}) click to toggle source
# File lib/rollin/blog.rb, line 2
def initialize(options = {})
  @articles_folder = options[:articles_folder] || 'articles'
end

Public Instance Methods

annual_archive() click to toggle source
# File lib/rollin/blog.rb, line 33
def annual_archive
  monthly_archive.map { |month_archive| month_archive.year }.uniq.map do |year|
    Rollin::YearArchive.new(year, monthly_archive.select { |aMonth| aMonth.year == year })
  end
end
article(search = {}) click to toggle source
# File lib/rollin/blog.rb, line 6
def article(search = {})
  unfiltered_articles.find { |article| article.matches?(search) }
end
articles(search = {}) click to toggle source
# File lib/rollin/blog.rb, line 10
def articles(search = {})
  unfiltered_articles.select { |article| article.matches?(search) }
end
metatags() click to toggle source
# File lib/rollin/blog.rb, line 18
def metatags
  metatag_labels = unfiltered_articles.map do |article|
    article.metatags.keys
  end.flatten.uniq

  metatag_labels.map do |metatag_label|
    values = unfiltered_articles.select { |article| article.metatags.has_key?(metatag_label) }.map do |article|
      article.metatags[metatag_label]
    end.flatten.uniq.map do |metatag_content|
      Rollin::MetatagValue.new(metatag_content, articles(metatag_label => metatag_content))
    end
    Rollin::MetatagKey.new(metatag_label, values)
  end
end
monthly_archive() click to toggle source
# File lib/rollin/blog.rb, line 39
def monthly_archive
  articles.map { |article| [article.year, article.month] }.uniq.map do |year_and_month|
    year = year_and_month[0]
    month = year_and_month[1]
    articles_for_month = articles.select { |anArticle| anArticle.year == year && anArticle.month == month }
    Rollin::MonthArchive.new(year, month, articles_for_month)
  end
end
unfiltered_articles() click to toggle source
# File lib/rollin/blog.rb, line 14
def unfiltered_articles
  read_articles.reverse
end

Private Instance Methods

read_articles() click to toggle source
# File lib/rollin/blog.rb, line 50
def read_articles
  extensions = %w{markdown mdown mkdn md mkd mdwn mdtxt mdtext text}
  Dir[*extensions.map { |ext| "#{@articles_folder}/**/*.#{ext}" }].sort.map do |article_source|
    Rollin::Article.new(article_source)
  end
end