Class: PagesCms::Article
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- PagesCms::Article
- Defined in:
- app/models/pages_cms/article.rb
Class Method Summary collapse
Instance Method Summary collapse
- #article_status ⇒ Object
- #content? ⇒ Boolean
- #content_either ⇒ Object
- #content_md=(value) ⇒ Object
- #content_md? ⇒ Boolean
- #tags=(val) ⇒ Object
- #xor(a, b) ⇒ Object
Class Method Details
.published ⇒ Object
45 46 47 |
# File 'app/models/pages_cms/article.rb', line 45 def self.published self.where('archived != true AND draft != true') end |
Instance Method Details
#article_status ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/models/pages_cms/article.rb', line 49 def article_status if self.draft && !self.archived 'Draft' elsif self.archived && !self.draft 'Archived' elsif !self.draft && !self.archived 'Published' elsif self.draft && self.archived 'Archived' end end |
#content? ⇒ Boolean
12 13 14 |
# File 'app/models/pages_cms/article.rb', line 12 def content? content.present? end |
#content_either ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'app/models/pages_cms/article.rb', line 20 def content_either if content_md? self.content_md_rendered elsif content? self.content else 'Article not saved properly.' end end |
#content_md=(value) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'app/models/pages_cms/article.rb', line 30 def content_md=(value) old = value if value.nil? new = value else new = Redcarpet::Markdown.new(Redcarpet::Render::HTML).render(value) end self[:content_md_rendered] = new self[:content_md] = old end |
#content_md? ⇒ Boolean
16 17 18 |
# File 'app/models/pages_cms/article.rb', line 16 def content_md? content_md.present? end |
#tags=(val) ⇒ Object
41 42 43 |
# File 'app/models/pages_cms/article.rb', line 41 def (val) write_attribute(:tags, val.strip.gsub(/\s+/, '_').split(',') ) end |
#xor(a, b) ⇒ Object
75 76 77 |
# File 'app/models/pages_cms/article.rb', line 75 def xor(a,b) (a || b) && !(a && b) end |