Class: Kms::Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Kms::Page
- Includes:
- CompileTemplates, Positioned, Liquor::Dropable
- Defined in:
- app/models/kms/page.rb
Constant Summary collapse
- INDEX_SLUG =
'index'.freeze
- INDEX_FULLPATH =
''
- NOT_FOUND_SLUG =
'404'.freeze
Class Method Summary collapse
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
- #not_found? ⇒ Boolean
Methods included from Positioned
Methods included from CompileTemplates
Class Method Details
.not_found_page ⇒ Object
23 24 25 |
# File 'app/models/kms/page.rb', line 23 def self.not_found_page where(slug: NOT_FOUND_SLUG).first end |
Instance Method Details
#build_fullpath ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'app/models/kms/page.rb', line 35 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
51 52 53 54 |
# File 'app/models/kms/page.rb', line 51 def fetch_item(slug) return nil unless templatable? templatable_type.constantize.find_by_slug(slug) end |
#fetch_items ⇒ Object
fetch items for templatable page
46 47 48 |
# File 'app/models/kms/page.rb', line 46 def fetch_items templatable_type.constantize.all end |
#index? ⇒ Boolean
27 28 29 |
# File 'app/models/kms/page.rb', line 27 def index? slug == INDEX_SLUG end |
#not_found? ⇒ Boolean
31 32 33 |
# File 'app/models/kms/page.rb', line 31 def not_found? slug == NOT_FOUND_SLUG end |