Class: OCms::Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- OCms::Page
- Defined in:
- app/models/o_cms/page.rb
Constant Summary collapse
- DRAFT_STATUS =
"draft"
- PUBLISHED_STATUS =
"published"
- SCHEDULED_STATUS =
"scheduled"
- STATUSES =
[['Draft', DRAFT_STATUS], ['Publish', PUBLISHED_STATUS], ['Schedule', SCHEDULED_STATUS]]
Instance Method Summary collapse
- #assign_attributes(new_attributes) ⇒ Object
- #create_meta_description ⇒ Object
- #create_meta_title ⇒ Object
- #create_slug ⇒ Object
- #draft? ⇒ Boolean
- #published? ⇒ Boolean
- #remove_subpage_relationships ⇒ Object
- #scheduled? ⇒ Boolean
- #status ⇒ Object
Instance Method Details
#assign_attributes(new_attributes) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/models/o_cms/page.rb', line 69 def assign_attributes(new_attributes) if new_attributes[:status] status = new_attributes[:status] published_at = new_attributes[:published_at] if DRAFT_STATUS == status published_at = nil elsif PUBLISHED_STATUS == status && published_at.blank? published_at = Time.current end new_attributes.delete(:status) new_attributes[:published_at] = published_at end super end |
#create_meta_description ⇒ Object
42 43 44 45 |
# File 'app/models/o_cms/page.rb', line 42 def sanitized_body = ActionView::Base.full_sanitizer.sanitize(self.body) self. = "#{sanitized_body.first(156) + ' ...'}" if self..blank? && self.body.present? end |
#create_meta_title ⇒ Object
38 39 40 |
# File 'app/models/o_cms/page.rb', line 38 def self. = "#{title}" if self..blank? && self.title.present? end |
#create_slug ⇒ Object
34 35 36 |
# File 'app/models/o_cms/page.rb', line 34 def create_slug self.slug = "#{title.parameterize}" if self.slug.blank? && self.title.present? end |
#draft? ⇒ Boolean
47 48 49 |
# File 'app/models/o_cms/page.rb', line 47 def draft? self.published_at.nil? end |
#published? ⇒ Boolean
51 52 53 |
# File 'app/models/o_cms/page.rb', line 51 def published? self.published_at.nil? ? false : self.published_at <= Time.current end |
#remove_subpage_relationships ⇒ Object
87 88 89 |
# File 'app/models/o_cms/page.rb', line 87 def remove_subpage_relationships self.subpages.clear end |
#scheduled? ⇒ Boolean
55 56 57 |
# File 'app/models/o_cms/page.rb', line 55 def scheduled? self.published_at.nil? ? false : self.published_at > Time.current end |
#status ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'app/models/o_cms/page.rb', line 59 def status if self.draft? return DRAFT_STATUS elsif self.published? return PUBLISHED_STATUS elsif self.scheduled? return SCHEDULED_STATUS end end |