Class: Spina::Page
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Spina::Page
- Extended by:
- Mobility
- Includes:
- AttrJson::NestedAttributes, AttrJson::Record, Partable, TranslatedContent
- Defined in:
- app/models/spina/page.rb
Instance Attribute Summary collapse
-
#old_path ⇒ Object
Stores the old path when generating a new materialized_path.
Attributes included from Partable
Instance Method Summary collapse
- #cache_key ⇒ Object
- #custom_page? ⇒ Boolean
- #homepage? ⇒ Boolean
- #live? ⇒ Boolean
- #next_sibling ⇒ Object
- #page_id ⇒ Object
- #previous_sibling ⇒ Object
- #save_children ⇒ Object
- #set_materialized_path ⇒ Object
- #slug ⇒ Object
- #to_s ⇒ Object
Methods included from TranslatedContent
Methods inherited from ApplicationRecord
Instance Attribute Details
#old_path ⇒ Object
Stores the old path when generating a new materialized_path
10 11 12 |
# File 'app/models/spina/page.rb', line 10 def old_path @old_path end |
Instance Method Details
#cache_key ⇒ Object
99 100 101 |
# File 'app/models/spina/page.rb', line 99 def cache_key super + "_" + Mobility.locale.to_s end |
#custom_page? ⇒ Boolean
67 68 69 |
# File 'app/models/spina/page.rb', line 67 def custom_page? !deletable end |
#homepage? ⇒ Boolean
63 64 65 |
# File 'app/models/spina/page.rb', line 63 def homepage? name == "homepage" end |
#live? ⇒ Boolean
75 76 77 |
# File 'app/models/spina/page.rb', line 75 def live? !draft? && active? end |
#next_sibling ⇒ Object
83 84 85 |
# File 'app/models/spina/page.rb', line 83 def next_sibling siblings.where("position > ?", position).sorted.first end |
#page_id ⇒ Object
55 56 57 |
# File 'app/models/spina/page.rb', line 55 def page_id id end |
#previous_sibling ⇒ Object
79 80 81 |
# File 'app/models/spina/page.rb', line 79 def previous_sibling siblings.where("position < ?", position).sorted.last end |
#save_children ⇒ Object
71 72 73 |
# File 'app/models/spina/page.rb', line 71 def save_children children.each(&:save) end |
#set_materialized_path ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/models/spina/page.rb', line 87 def set_materialized_path self.old_path = materialized_path self.materialized_path = localized_materialized_path # Append counter to duplicate materialized_path i = 0 while duplicate_materialized_path? i += 1 self.materialized_path = localized_materialized_path.concat("-#{i}") end end |
#slug ⇒ Object
59 60 61 |
# File 'app/models/spina/page.rb', line 59 def slug url_title.to_s.to_slug.transliterate(*Spina.config.transliterations).normalize.to_s end |
#to_s ⇒ Object
51 52 53 |
# File 'app/models/spina/page.rb', line 51 def to_s title end |