Class: Spina::Page
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- 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
- #cache_key ⇒ Object
- #content(page_part) ⇒ Object
- #custom_page? ⇒ Boolean
- #full_materialized_path ⇒ 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
- #view_template_config(theme) ⇒ Object
Methods included from Partable
Instance Attribute Details
#old_path ⇒ Object
Returns the value of attribute old_path.
7 8 9 |
# File 'app/models/spina/page.rb', line 7 def old_path @old_path end |
Instance Method Details
#cache_key ⇒ Object
88 89 90 |
# File 'app/models/spina/page.rb', line 88 def cache_key super + "_" + Globalize.locale.to_s end |
#content(page_part) ⇒ Object
64 65 66 67 |
# File 'app/models/spina/page.rb', line 64 def content(page_part) page_part = page_parts.where(name: page_part).first page_part.try(:content) end |
#custom_page? ⇒ Boolean
44 45 46 |
# File 'app/models/spina/page.rb', line 44 def custom_page? !deletable end |
#full_materialized_path ⇒ Object
97 98 99 |
# File 'app/models/spina/page.rb', line 97 def full_materialized_path File.join(Spina::Engine.routes.url_helpers.root_path, materialized_path) end |
#has_content?(page_part) ⇒ Boolean
60 61 62 |
# File 'app/models/spina/page.rb', line 60 def has_content?(page_part) content(page_part).present? end |
#live? ⇒ Boolean
69 70 71 |
# File 'app/models/spina/page.rb', line 69 def live? !draft? && active? end |
#menu_title ⇒ Object
52 53 54 |
# File 'app/models/spina/page.rb', line 52 def read_attribute(:menu_title).blank? ? title : read_attribute(:menu_title) end |
#next_sibling ⇒ Object
77 78 79 |
# File 'app/models/spina/page.rb', line 77 def next_sibling self.siblings.where('position > ?', self.position).sorted.first end |
#previous_sibling ⇒ Object
73 74 75 |
# File 'app/models/spina/page.rb', line 73 def previous_sibling self.siblings.where('position < ?', self.position).sorted.last end |
#save_children ⇒ Object
48 49 50 |
# File 'app/models/spina/page.rb', line 48 def save_children self.children.each { |child| child.save } end |
#seo_title ⇒ Object
56 57 58 |
# File 'app/models/spina/page.rb', line 56 def seo_title read_attribute(:seo_title).blank? ? title : read_attribute(:seo_title) end |
#set_materialized_path ⇒ Object
81 82 83 84 85 86 |
# File 'app/models/spina/page.rb', line 81 def set_materialized_path self.old_path = materialized_path self.materialized_path = localized_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
36 37 38 |
# File 'app/models/spina/page.rb', line 36 def to_s name end |
#url_title ⇒ Object
40 41 42 |
# File 'app/models/spina/page.rb', line 40 def url_title title.try(:parameterize) end |
#view_template_config(theme) ⇒ Object
92 93 94 95 |
# File 'app/models/spina/page.rb', line 92 def view_template_config(theme) view_template_name = view_template.presence || 'show' theme.view_templates.find { |template| template[:name] == view_template_name } end |