Class: BlogPost

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TextHelper, Mongoid::Document, Mongoid::Search, Mongoid::Slug, Mongoid::Timestamps
Defined in:
lib/generators/active_admin/blog/templates/models/blog_post.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.archiveObject



73
74
75
76
77
# 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

.blog_search(query) ⇒ Object



69
70
71
# File 'lib/generators/active_admin/blog/templates/models/blog_post.rb', line 69

def self.blog_search(query)
  self.search(query).published
end

.published_in_category(category_slug) ⇒ Object

Class methods



54
55
56
57
# 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) ⇒ Object



59
60
61
62
63
64
65
66
67
# 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

Instance Method Details

#excerptObject



40
41
42
43
44
45
46
47
# 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

Helpers

Returns:

  • (Boolean)


36
37
38
# File 'lib/generators/active_admin/blog/templates/models/blog_post.rb', line 36

def has_featured_image?
  not featured_image.to_s.empty?
end

#page_descriptionObject



49
50
51
# File 'lib/generators/active_admin/blog/templates/models/blog_post.rb', line 49

def page_description
  Nokogiri::HTML(excerpt).text
end