Class: Spud::SpudPostModel
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Spud::SpudPostModel
- Defined in:
- app/models/spud/spud_post_model.rb
Direct Known Subclasses
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_posts ⇒ Object
Returns an array of Date objects for months with public posts.
- .recent_blog_posts(limit = 5) ⇒ Object
- .recent_news_posts(limit = 5) ⇒ Object
- .recent_posts(limit = 5) ⇒ Object
Instance Method Summary collapse
- #category_names ⇒ Object
- #content_processed ⇒ Object
- #content_processed=(content) ⇒ Object
- #display_date ⇒ Object
- #is_news ⇒ 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/spud_post_model.rb', line 136 def spud_site_ids @spud_site_ids end |
Class Method Details
.for_spud_site(spud_site_id) ⇒ Object
43 44 45 |
# File 'app/models/spud/spud_post_model.rb', line 43 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
59 60 61 62 63 64 65 66 67 |
# File 'app/models/spud/spud_post_model.rb', line 59 def self.from_archive(date_string) begin date = Date.strptime(date_string, "%Y-%b") return where(:published_at => date..date.end_of_month) rescue logger.debug 'fallback' return where('') end end |
.months_with_public_posts ⇒ Object
Returns an array of Date objects for months with public posts
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/models/spud/spud_post_model.rb', line 77 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 |
.recent_blog_posts(limit = 5) ⇒ Object
51 52 53 |
# File 'app/models/spud/spud_post_model.rb', line 51 def self.recent_blog_posts(limit=5) return self.blog_posts.recent_posts(limit) end |
.recent_news_posts(limit = 5) ⇒ Object
55 56 57 |
# File 'app/models/spud/spud_post_model.rb', line 55 def self.recent_news_posts(limit=5) return self.news_posts.recent_posts(limit) end |
.recent_posts(limit = 5) ⇒ Object
47 48 49 |
# File 'app/models/spud/spud_post_model.rb', line 47 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
#category_names ⇒ Object
131 132 133 |
# File 'app/models/spud/spud_post_model.rb', line 131 def category_names return self.categories.collect{ |c| c.name }.join(', ') end |
#content_processed ⇒ Object
108 109 110 111 112 113 |
# File 'app/models/spud/spud_post_model.rb', line 108 def content_processed if read_attribute(:content_processed).blank? postprocess_content end read_attribute(:content_processed) end |
#content_processed=(content) ⇒ Object
115 116 117 |
# File 'app/models/spud/spud_post_model.rb', line 115 def content_processed=(content) write_attribute(:content_processed,content) end |
#display_date ⇒ Object
119 120 121 |
# File 'app/models/spud/spud_post_model.rb', line 119 def display_date return published_at.strftime("%b %d, %Y") end |
#is_news ⇒ Object
69 70 71 72 |
# File 'app/models/spud/spud_post_model.rb', line 69 def is_news ActiveSupport::Deprecation.warn ":is_news is deprecated. Please rely on the :blog_key column stead.", caller return self.read_attribute(:is_news) end |
#is_private? ⇒ Boolean
127 128 129 |
# File 'app/models/spud/spud_post_model.rb', line 127 def is_private? return !is_public? end |
#is_public? ⇒ Boolean
123 124 125 |
# File 'app/models/spud/spud_post_model.rb', line 123 def is_public? return (published_at < DateTime.now) && visible end |
#postprocess_content ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/models/spud/spud_post_model.rb', line 95 def postprocess_content # if self.content_format == 'Markdown' # require 'redcarpet' # renderer = Redcarpet::Render::HTML.new # extensions = {fenced_code_blocks: true} # redcarpet = Redcarpet::Markdown.new(renderer, extensions) # self.content_processed = redcarpet.render self.content # else template = Liquid::Template.parse(self.content) self.content_processed = template.render() # end end |