Class: Spina::Page

Inherits:
ApplicationRecord show all
Extended by:
Mobility
Includes:
AttrJson::NestedAttributes, AttrJson::Record, Partable, TranslatedContent
Defined in:
app/models/spina/page.rb

Instance Attribute Summary collapse

Attributes included from Partable

#view_context

Instance Method Summary collapse

Methods included from TranslatedContent

#find_part

Methods inherited from ApplicationRecord

#to_partial_path

Instance Attribute Details

#old_pathObject

Stores the old path when generating a new materialized_path



10
11
12
# File 'app/models/spina/page.rb', line 10

def old_path
  @old_path
end

Instance Method Details

#cache_keyObject



99
100
101
# File 'app/models/spina/page.rb', line 99

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

#custom_page?Boolean

Returns:

  • (Boolean)


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

def custom_page?
  !deletable
end

#homepage?Boolean

Returns:

  • (Boolean)


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

def homepage?
  name == "homepage"
end

#live?Boolean

Returns:

  • (Boolean)


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

def live?
  !draft? && active?
end

#next_siblingObject



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

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

#page_idObject



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

def page_id
  id
end

#previous_siblingObject



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

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

#save_childrenObject



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

def save_children
  children.each(&:save)
end

#set_materialized_pathObject



87
88
89
90
91
92
93
94
95
96
97
# File 'app/models/spina/page.rb', line 87

def set_materialized_path
  self.old_path = materialized_path
  self.materialized_path = localized_materialized_path

  # Append counter to duplicate materialized_path
  i = 0
  while duplicate_materialized_path?
    i += 1
    self.materialized_path = localized_materialized_path.concat("-#{i}")
  end
end

#slugObject



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

def slug
  url_title.to_s.to_slug.transliterate(*Spina.config.transliterations).normalize.to_s
end

#to_sObject



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

def to_s
  title
end