class BlogPost

Public Class Methods

archive() click to toggle source
# File lib/generators/active_admin/blog/templates/models/blog_post.rb, line 73
def self.archive
  BlogPost.all.collect do |p|
    [p.date.month, p.date.year]
  end.uniq
end
published_in_category(category_slug) click to toggle source

Class methods

# File lib/generators/active_admin/blog/templates/models/blog_post.rb, line 54
def self.published_in_category(category_slug)
  category = BlogCategory.find_by_permalink!(category_slug)
  category.blog_posts.published
end
published_in_month(month, year) click to toggle source
# File lib/generators/active_admin/blog/templates/models/blog_post.rb, line 59
def self.published_in_month(month, year)
  begin
    start_date = Date.new(year, month, 1)
    end_date   = start_date + 1.month
  rescue
    BlogPost.published
  end
  BlogPost.published.where(:date=>{'$gte' => start_date,'$lt' => end_date})
end

Public Instance Methods

excerpt() click to toggle source
# File lib/generators/active_admin/blog/templates/models/blog_post.rb, line 40
def excerpt
  html = Nokogiri::HTML(content)
  begin
    html.css('p').select{|p| not p.content.empty? }.first.content
  rescue
    ""
  end
end
page_description() click to toggle source
# File lib/generators/active_admin/blog/templates/models/blog_post.rb, line 49
def page_description
  Nokogiri::HTML(excerpt).text
end