Class: Kms::Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Kms::Page
- Includes:
- CompileTemplates, Liquor::Dropable
- Defined in:
- app/models/kms/page.rb
Constant Summary collapse
- INDEX_SLUG =
"index"- INDEX_FULLPATH =
""
Instance Method Summary collapse
- #build_fullpath ⇒ Object
-
#fetch_item!(slug) ⇒ Object
fetch item by slug.
-
#fetch_items ⇒ Object
fetch items for templatable page.
- #index? ⇒ Boolean
- #set_position ⇒ Object
Methods included from CompileTemplates
Instance Method Details
#build_fullpath ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'app/models/kms/page.rb', line 27 def build_fullpath if index? self.fullpath = INDEX_FULLPATH # self.slug else slugs = (ancestors + [self]).map(&:slug) slugs.shift unless slugs.size == 1 self.fullpath = File.join slugs.compact end end |
#fetch_item!(slug) ⇒ Object
fetch item by slug
52 53 54 55 |
# File 'app/models/kms/page.rb', line 52 def fetch_item!(slug) return nil unless templatable? templatable_type.constantize.find_by_slug!(slug) end |
#fetch_items ⇒ Object
fetch items for templatable page
47 48 49 |
# File 'app/models/kms/page.rb', line 47 def fetch_items templatable_type.constantize.all end |
#index? ⇒ Boolean
23 24 25 |
# File 'app/models/kms/page.rb', line 23 def index? slug == INDEX_SLUG end |
#set_position ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'app/models/kms/page.rb', line 37 def set_position if parent.present? max = parent.children.maximum(:position) else max = Page.where('ancestry IS ?', nil).maximum(:position) end self.position = max ? max + 1 : 0 end |