Class: Kms::Page

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
CompileTemplates, Liquor::Dropable
Defined in:
app/models/kms/page.rb

Constant Summary collapse

INDEX_SLUG =
"index"
INDEX_FULLPATH =
""

Instance Method Summary collapse

Methods included from CompileTemplates

#register_id

Instance Method Details

#build_fullpathObject



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_itemsObject

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

Returns:

  • (Boolean)


23
24
25
# File 'app/models/kms/page.rb', line 23

def index?
  slug == INDEX_SLUG
end

#set_positionObject



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