Class: Spina::Page

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Partable
Defined in:
app/models/spina/page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Partable

#part

Instance Attribute Details

#old_pathObject

Returns the value of attribute old_path.



5
6
7
# File 'app/models/spina/page.rb', line 5

def old_path
  @old_path
end

Instance Method Details

#activate!Object



80
81
82
83
# File 'app/models/spina/page.rb', line 80

def activate!
  self.active = true
  self.save
end

#content(page_part) ⇒ Object



58
59
60
61
# File 'app/models/spina/page.rb', line 58

def content(page_part)
  page_part = page_parts.where(name: page_part).first
  page_part.try(:content)
end

#custom_page?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/models/spina/page.rb', line 38

def custom_page?
  !deletable
end

#deactivate!Object



75
76
77
78
# File 'app/models/spina/page.rb', line 75

def deactivate!
  self.active = false
  self.save
end

#has_content?(page_part) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'app/models/spina/page.rb', line 54

def has_content?(page_part)
  content(page_part).present?
end

#live?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'app/models/spina/page.rb', line 63

def live?
  !draft? && active?
end


46
47
48
# File 'app/models/spina/page.rb', line 46

def menu_title
  read_attribute(:menu_title).blank? ? title : read_attribute(:menu_title)
end

#next_siblingObject



71
72
73
# File 'app/models/spina/page.rb', line 71

def next_sibling
  self.siblings.where('position > ?', self.position).sorted.first
end

#previous_siblingObject



67
68
69
# File 'app/models/spina/page.rb', line 67

def previous_sibling
  self.siblings.where('position < ?', self.position).sorted.last
end

#save_childrenObject



42
43
44
# File 'app/models/spina/page.rb', line 42

def save_children
  self.children.each { |child| child.save }
end

#seo_titleObject



50
51
52
# File 'app/models/spina/page.rb', line 50

def seo_title
  read_attribute(:seo_title).blank? ? title : read_attribute(:seo_title)
end

#set_materialized_pathObject



85
86
87
88
89
90
# File 'app/models/spina/page.rb', line 85

def set_materialized_path
  self.old_path = materialized_path
  self.materialized_path = generate_materialized_path
  self.materialized_path += "-#{self.class.where(materialized_path: materialized_path).count}" if self.class.where(materialized_path: materialized_path).where.not(id: id).count > 0
  materialized_path
end

#to_sObject



30
31
32
# File 'app/models/spina/page.rb', line 30

def to_s
  name
end

#url_titleObject



34
35
36
# File 'app/models/spina/page.rb', line 34

def url_title
  title.try(:parameterize)
end