Class: Spina::Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Spina::Page
- Includes:
- Partable
- Defined in:
- app/models/spina/page.rb
Instance Attribute Summary collapse
-
#old_path ⇒ Object
Returns the value of attribute old_path.
Instance Method Summary collapse
- #activate! ⇒ Object
- #content(page_part) ⇒ Object
- #custom_page? ⇒ Boolean
- #deactivate! ⇒ Object
- #has_content?(page_part) ⇒ Boolean
- #live? ⇒ Boolean
- #menu_title ⇒ Object
- #next_sibling ⇒ Object
- #previous_sibling ⇒ Object
- #save_children ⇒ Object
- #seo_title ⇒ Object
- #set_materialized_path ⇒ Object
- #to_s ⇒ Object
- #url_title ⇒ Object
Methods included from Partable
Instance Attribute Details
#old_path ⇒ Object
Returns the value of attribute old_path.
5 6 7 |
# File 'app/models/spina/page.rb', line 5 def old_path @old_path end |
Instance Method Details
#activate! ⇒ Object
80 81 82 83 |
# File 'app/models/spina/page.rb', line 80 def activate! self.active = true self.save end |
#content(page_part) ⇒ Object
58 59 60 61 |
# File 'app/models/spina/page.rb', line 58 def content(page_part) page_part = page_parts.where(name: page_part).first page_part.try(:content) end |
#custom_page? ⇒ Boolean
38 39 40 |
# File 'app/models/spina/page.rb', line 38 def custom_page? !deletable end |
#deactivate! ⇒ Object
75 76 77 78 |
# File 'app/models/spina/page.rb', line 75 def deactivate! self.active = false self.save end |
#has_content?(page_part) ⇒ Boolean
54 55 56 |
# File 'app/models/spina/page.rb', line 54 def has_content?(page_part) content(page_part).present? end |
#live? ⇒ Boolean
63 64 65 |
# File 'app/models/spina/page.rb', line 63 def live? !draft? && active? end |
#menu_title ⇒ Object
46 47 48 |
# File 'app/models/spina/page.rb', line 46 def read_attribute(:menu_title).blank? ? title : read_attribute(:menu_title) end |
#next_sibling ⇒ Object
71 72 73 |
# File 'app/models/spina/page.rb', line 71 def next_sibling self.siblings.where('position > ?', self.position).sorted.first end |
#previous_sibling ⇒ Object
67 68 69 |
# File 'app/models/spina/page.rb', line 67 def previous_sibling self.siblings.where('position < ?', self.position).sorted.last end |
#save_children ⇒ Object
42 43 44 |
# File 'app/models/spina/page.rb', line 42 def save_children self.children.each { |child| child.save } end |
#seo_title ⇒ Object
50 51 52 |
# File 'app/models/spina/page.rb', line 50 def seo_title read_attribute(:seo_title).blank? ? title : read_attribute(:seo_title) end |
#set_materialized_path ⇒ Object
85 86 87 88 89 90 |
# File 'app/models/spina/page.rb', line 85 def set_materialized_path self.old_path = materialized_path self.materialized_path = generate_materialized_path self.materialized_path += "-#{self.class.where(materialized_path: materialized_path).count}" if self.class.where(materialized_path: materialized_path).where.not(id: id).count > 0 materialized_path end |
#to_s ⇒ Object
30 31 32 |
# File 'app/models/spina/page.rb', line 30 def to_s name end |
#url_title ⇒ Object
34 35 36 |
# File 'app/models/spina/page.rb', line 34 def url_title title.try(:parameterize) end |