Class: ActiveadminBlog::BlogPost

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TextHelper, Mongoid::Document, Mongoid::Search, Mongoid::Slug, Mongoid::Timestamps
Defined in:
app/models/activeadmin_blog/blog_post.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.archiveObject



71
72
73
74
75
# File 'app/models/activeadmin_blog/blog_post.rb', line 71

def self.archive
  self.all.collect do |p|
    [p.date.month, p.date.year]
  end.uniq
end

.blog_search(query) ⇒ Object



67
68
69
# File 'app/models/activeadmin_blog/blog_post.rb', line 67

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

.published_in_category(category_slug) ⇒ Object

Class methods



52
53
54
55
# File 'app/models/activeadmin_blog/blog_post.rb', line 52

def self.published_in_category(category_slug)
  category = ActiveadminBlog::BlogCategory.find_by_permalink!(category_slug)
  category.blog_posts.published
end

.published_in_month(month, year) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'app/models/activeadmin_blog/blog_post.rb', line 57

def self.published_in_month(month, year)
  begin
    start_date = Date.new(year, month, 1)
    end_date   = start_date + 1.month
  rescue
    self.published
  end
  self.published.where(:date=>{'$gte' => start_date,'$lt' => end_date})
end

.tagged_with(tag) ⇒ Object



77
78
79
# File 'app/models/activeadmin_blog/blog_post.rb', line 77

def self.tagged_with(tag)
  self.published
end

Instance Method Details

#excerptObject



38
39
40
41
42
43
44
45
# File 'app/models/activeadmin_blog/blog_post.rb', line 38

def excerpt
  html = Nokogiri::HTML(content)
  begin
    html.css('p').select{|p| not p.content.empty? }.first.content
  rescue
    ""
  end
end

Helpers

Returns:

  • (Boolean)


34
35
36
# File 'app/models/activeadmin_blog/blog_post.rb', line 34

def has_featured_image?
  not featured_image.to_s.empty?
end

#page_descriptionObject



47
48
49
# File 'app/models/activeadmin_blog/blog_post.rb', line 47

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