Class: Spina::Page
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Spina::Page
- Extended by:
- Mobility
- Includes:
- Partable
- Defined in:
- app/models/spina/page.rb
Instance Attribute Summary collapse
-
#old_path ⇒ Object
Stores the old path when generating a new materialized_path.
Instance Method Summary collapse
- #cache_key ⇒ Object
- #custom_page? ⇒ Boolean
- #live? ⇒ Boolean
- #next_sibling ⇒ Object
- #page_id ⇒ Object
- #previous_sibling ⇒ Object
- #save_children ⇒ Object
- #set_materialized_path ⇒ Object
- #to_s ⇒ Object
- #url_title ⇒ Object
- #view_template_config(theme) ⇒ Object
- #view_template_page_parts(theme) ⇒ Object
Instance Attribute Details
#old_path ⇒ Object
Stores the old path when generating a new materialized_path
7 8 9 |
# File 'app/models/spina/page.rb', line 7 def old_path @old_path end |
Instance Method Details
#cache_key ⇒ Object
85 86 87 |
# File 'app/models/spina/page.rb', line 85 def cache_key super + "_" + Mobility.locale.to_s end |
#custom_page? ⇒ Boolean
58 59 60 |
# File 'app/models/spina/page.rb', line 58 def custom_page? !deletable end |
#live? ⇒ Boolean
66 67 68 |
# File 'app/models/spina/page.rb', line 66 def live? !draft? && active? end |
#next_sibling ⇒ Object
74 75 76 |
# File 'app/models/spina/page.rb', line 74 def next_sibling siblings.where('position > ?', position).sorted.first end |
#page_id ⇒ Object
50 51 52 |
# File 'app/models/spina/page.rb', line 50 def page_id id end |
#previous_sibling ⇒ Object
70 71 72 |
# File 'app/models/spina/page.rb', line 70 def previous_sibling siblings.where('position < ?', position).sorted.last end |
#save_children ⇒ Object
62 63 64 |
# File 'app/models/spina/page.rb', line 62 def save_children children.each(&:save) end |
#set_materialized_path ⇒ Object
78 79 80 81 82 83 |
# File 'app/models/spina/page.rb', line 78 def set_materialized_path self.old_path = materialized_path self.materialized_path = localized_materialized_path self.materialized_path = localized_materialized_path + "-#{Page.i18n.where(materialized_path: materialized_path).count}" if Page.i18n.where(materialized_path: materialized_path).where.not(id: id).count > 0 materialized_path end |
#to_s ⇒ Object
46 47 48 |
# File 'app/models/spina/page.rb', line 46 def to_s name end |
#url_title ⇒ Object
54 55 56 |
# File 'app/models/spina/page.rb', line 54 def url_title title.try(:parameterize) end |
#view_template_config(theme) ⇒ Object
89 90 91 92 |
# File 'app/models/spina/page.rb', line 89 def view_template_config(theme) view_template_name = view_template.presence || 'show' theme.view_templates.find { |template| template[:name] == view_template_name } end |
#view_template_page_parts(theme) ⇒ Object
94 95 96 |
# File 'app/models/spina/page.rb', line 94 def view_template_page_parts(theme) theme.page_parts.select { |page_part| page_part[:name].in? view_template_config(theme)[:page_parts] } end |