Class: Spina::Page

Inherits:
ApplicationRecord show all
Extended by:
Mobility
Includes:
Partable
Defined in:
app/models/spina/page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#old_pathObject

Stores the old path when generating a new materialized_path



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

def old_path
  @old_path
end

Instance Method Details

#cache_keyObject



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

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

#custom_page?Boolean

Returns:

  • (Boolean)


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

def custom_page?
  !deletable
end

#live?Boolean

Returns:

  • (Boolean)


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

def live?
  !draft? && active?
end

#next_siblingObject



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

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

#previous_siblingObject



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

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

#save_childrenObject



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

def save_children
  self.children.each(&:save)
end

#set_materialized_pathObject



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

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

#to_sObject



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

def to_s
  name
end

#url_titleObject



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

def url_title
  title.try(:parameterize)
end

#view_template_config(theme) ⇒ Object



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

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

#view_template_page_parts(theme) ⇒ Object



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

def view_template_page_parts(theme)
  theme.page_parts.select { |page_part| page_part[:name].in? view_template_config(theme)[:page_parts] }
end