Class: SpudPost
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- SpudPost
- Defined in:
- app/models/spud_post.rb
Instance Attribute Summary collapse
-
#spud_site_ids ⇒ Object
Spud site ids getter.
Class Method Summary collapse
- .for_spud_site(spud_site_id) ⇒ Object
- .from_archive(date_string) ⇒ Object
- .months_with_public_blog_posts ⇒ Object
- .months_with_public_news_posts ⇒ Object
-
.months_with_public_posts ⇒ Object
Returns an array of Date objects for months with public posts.
- .public_blog_posts(page, per_page) ⇒ Object
- .public_news_posts(page, per_page) ⇒ Object
- .public_posts(page, per_page) ⇒ Object
- .recent_blog_posts(limit = 5) ⇒ Object
- .recent_news_posts(limit = 5) ⇒ Object
- .recent_posts(limit = 5) ⇒ Object
Instance Method Summary collapse
- #content_processed ⇒ Object
- #content_processed=(content) ⇒ Object
- #display_date ⇒ Object
- #is_private? ⇒ Boolean
- #is_public? ⇒ Boolean
- #postprocess_content ⇒ Object
Instance Attribute Details
#spud_site_ids ⇒ Object
Spud site ids getter
136 137 138 |
# File 'app/models/spud_post.rb', line 136 def spud_site_ids @spud_site_ids end |
Class Method Details
.for_spud_site(spud_site_id) ⇒ Object
26 27 28 |
# File 'app/models/spud_post.rb', line 26 def self.for_spud_site(spud_site_id) return joins(:spud_post_sites).where(:spud_post_sites => {:spud_site_id => spud_site_id}) end |
.from_archive(date_string) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'app/models/spud_post.rb', line 54 def self.from_archive(date_string) begin date = Date.strptime(date_string, "%Y-%b") return where(:published_at => date..date.end_of_month) rescue return all end end |
.months_with_public_blog_posts ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'app/models/spud_post.rb', line 93 def self.months_with_public_blog_posts records = SpudPost.select('Extract(Month from published_at) as published_month, Extract(Year from published_at) as published_year').where('visible = ? AND published_at < ? AND is_news = ?', true, DateTime.now, false).group('published_month, published_year').order('published_year desc, published_month desc') begin return records.collect{ |r| Date.new(r[:published_year].to_i, r[:published_month].to_i) } rescue Exception => e logger.fatal "Exception occurred while fetching post archive dates:\n #{e.to_s}" end end |
.months_with_public_news_posts ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'app/models/spud_post.rb', line 84 def self.months_with_public_news_posts records = SpudPost.select('Extract(Month from published_at) as published_month, Extract(Year from published_at) as published_year').where('visible = ? AND published_at < ? AND is_news = ?', true, DateTime.now, true).group('published_month, published_year').order('published_year desc, published_month desc') begin return records.collect{ |r| Date.new(r[:published_year].to_i, r[:published_month].to_i) } rescue Exception => e logger.fatal "Exception occurred while fetching post archive dates:\n #{e.to_s}" end end |
.months_with_public_posts ⇒ Object
Returns an array of Date objects for months with public posts
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/models/spud_post.rb', line 66 def self.months_with_public_posts # Select # Month(published_at) as published_month, # Year(published_at) as published_year # From spud_posts # Where visible = 1 # And published_at < '2012-01-30' # Group By published_month, published_year # Order By published_year desc, published_month desc records = SpudPost.select('Extract(Month from published_at) as published_month, Extract(Year from published_at) as published_year').where('visible = ? AND published_at < ?', true, DateTime.now).group('published_month, published_year').order('published_year desc, published_month desc') begin return records.collect{ |r| Date.new(r[:published_year].to_i, r[:published_month].to_i) } rescue Exception => e logger.fatal "Exception occurred while fetching post archive dates:\n #{e.to_s}" return [] end end |
.public_blog_posts(page, per_page) ⇒ Object
34 35 36 |
# File 'app/models/spud_post.rb', line 34 def self.public_blog_posts(page, per_page) return self.public_posts(page, per_page).where(:is_news => false) end |
.public_news_posts(page, per_page) ⇒ Object
38 39 40 |
# File 'app/models/spud_post.rb', line 38 def self.public_news_posts(page, per_page) return self.public_posts(page, per_page).where(:is_news => true) end |
.public_posts(page, per_page) ⇒ Object
30 31 32 |
# File 'app/models/spud_post.rb', line 30 def self.public_posts(page, per_page) return where('visible = ? AND published_at <= ?', true,Time.now.utc).order('published_at desc').includes(:categories).paginate(:page => page, :per_page => per_page) end |
.recent_blog_posts(limit = 5) ⇒ Object
46 47 48 |
# File 'app/models/spud_post.rb', line 46 def self.recent_blog_posts(limit=5) return self.recent_posts(limit).where(:is_news => false) end |
.recent_news_posts(limit = 5) ⇒ Object
50 51 52 |
# File 'app/models/spud_post.rb', line 50 def self.recent_news_posts(limit=5) return self.recent_posts(limit).where(:is_news => true) end |
.recent_posts(limit = 5) ⇒ Object
42 43 44 |
# File 'app/models/spud_post.rb', line 42 def self.recent_posts(limit=5) return where('visible = ? AND published_at <= ?', true, Time.now.utc).order('published_at desc').limit(limit) end |
Instance Method Details
#content_processed ⇒ Object
112 113 114 115 116 117 |
# File 'app/models/spud_post.rb', line 112 def content_processed if read_attribute(:content_processed).blank? postprocess_content end read_attribute(:content_processed) end |
#content_processed=(content) ⇒ Object
119 120 121 |
# File 'app/models/spud_post.rb', line 119 def content_processed=(content) write_attribute(:content_processed,content) end |
#display_date ⇒ Object
123 124 125 |
# File 'app/models/spud_post.rb', line 123 def display_date return published_at.strftime("%b %d, %Y") end |
#is_private? ⇒ Boolean
131 132 133 |
# File 'app/models/spud_post.rb', line 131 def is_private? return !is_public? end |
#is_public? ⇒ Boolean
127 128 129 |
# File 'app/models/spud_post.rb', line 127 def is_public? return (published_at < DateTime.now) && visible end |
#postprocess_content ⇒ Object
102 103 104 105 106 107 108 109 110 |
# File 'app/models/spud_post.rb', line 102 def postprocess_content rendererClass = Spud::Core.renderer(self.content_format) if rendererClass renderer = rendererClass.new() self.content_processed = renderer.render self.content else self.content_processed = content end end |