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.



7
8
9
# File 'app/models/spina/page.rb', line 7

def old_path
  @old_path
end

Instance Method Details

#cache_keyObject



84
85
86
# File 'app/models/spina/page.rb', line 84

def cache_key
  super + "_" + Globalize.locale.to_s
end

#content(page_part) ⇒ Object



60
61
62
63
# File 'app/models/spina/page.rb', line 60

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

#custom_page?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'app/models/spina/page.rb', line 40

def custom_page?
  !deletable
end

#has_content?(page_part) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'app/models/spina/page.rb', line 56

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

#live?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'app/models/spina/page.rb', line 65

def live?
  !draft? && active?
end


48
49
50
# File 'app/models/spina/page.rb', line 48

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

#next_siblingObject



73
74
75
# File 'app/models/spina/page.rb', line 73

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

#previous_siblingObject



69
70
71
# File 'app/models/spina/page.rb', line 69

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

#save_childrenObject



44
45
46
# File 'app/models/spina/page.rb', line 44

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

#seo_titleObject



52
53
54
# File 'app/models/spina/page.rb', line 52

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

#set_materialized_pathObject



77
78
79
80
81
82
# File 'app/models/spina/page.rb', line 77

def set_materialized_path
  self.old_path = materialized_path
  self.materialized_path = localized_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



32
33
34
# File 'app/models/spina/page.rb', line 32

def to_s
  name
end

#url_titleObject



36
37
38
# File 'app/models/spina/page.rb', line 36

def url_title
  title.try(:parameterize)
end

#view_template_config(theme) ⇒ Object



88
89
90
91
# File 'app/models/spina/page.rb', line 88

def view_template_config(theme)
  view_template_name = view_template.presence || 'show'
  theme.view_templates.find { |template| template[:name] == view_template_name }
end