Class: ActiveadminBlog::BlogPost
- Inherits:
-
Object
- Object
- ActiveadminBlog::BlogPost
- 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
- .archive ⇒ Object
- .blog_search(query) ⇒ Object
-
.published_in_category(category_slug) ⇒ Object
Class methods.
- .published_in_month(month, year) ⇒ Object
- .tagged_with(tag) ⇒ Object
Instance Method Summary collapse
Class Method Details
.archive ⇒ Object
72 73 74 75 76 |
# File 'app/models/activeadmin_blog/blog_post.rb', line 72 def self.archive self.all.collect do |p| [p.date.month, p.date.year] end.uniq end |
.blog_search(query) ⇒ Object
68 69 70 |
# File 'app/models/activeadmin_blog/blog_post.rb', line 68 def self.blog_search(query) self.search(query).published end |
.published_in_category(category_slug) ⇒ Object
Class methods
53 54 55 56 |
# File 'app/models/activeadmin_blog/blog_post.rb', line 53 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
58 59 60 61 62 63 64 65 66 |
# File 'app/models/activeadmin_blog/blog_post.rb', line 58 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
78 79 80 |
# File 'app/models/activeadmin_blog/blog_post.rb', line 78 def self.tagged_with(tag) self.published end |
Instance Method Details
#excerpt ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'app/models/activeadmin_blog/blog_post.rb', line 39 def excerpt html = Nokogiri::HTML(content) begin html.css('p').select{|p| not p.content.empty? }.first.content rescue "" end end |
#has_featured_image? ⇒ Boolean
Helpers
35 36 37 |
# File 'app/models/activeadmin_blog/blog_post.rb', line 35 def has_featured_image? not featured_image.to_s.empty? end |
#page_description ⇒ Object
48 49 50 |
# File 'app/models/activeadmin_blog/blog_post.rb', line 48 def page_description Nokogiri::HTML(excerpt).text end |