Class: Spotlight::Page

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
FriendlyId
Defined in:
app/models/spotlight/page.rb

Overview

Base page class. See AboutPage, FeaturePage, HomePage

Direct Known Subclasses

AboutPage, FeaturePage, HomePage

Constant Summary collapse

MAX_PAGES =
50

Instance Method Summary collapse

Instance Method Details

#about_page?Boolean



68
69
70
# File 'app/models/spotlight/page.rb', line 68

def about_page?
  is_a? AboutPage
end

#content=(content) ⇒ Object



36
37
38
39
40
41
42
43
# File 'app/models/spotlight/page.rb', line 36

def content=(content)
  if content.is_a? Array
    super content.to_json
  else
    super
  end
  content_changed!
end

#content?Boolean Also known as: has_content?



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

def content?
  self[:content].present? && content.present?
end

#content_changed!Object



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

def content_changed!
  @content = nil
end

#display_sidebar?Boolean



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

def display_sidebar?
  true
end

#feature_page?Boolean



64
65
66
# File 'app/models/spotlight/page.rb', line 64

def feature_page?
  is_a? FeaturePage
end


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

def featured_image
  nil
end

#lock!(user) ⇒ Object



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

def lock!(user)
  create_lock(by: user).tap(&:current_session!) unless lock.present?
end

#should_display_title?Boolean



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

def should_display_title?
  title.present?
end

#should_generate_new_friendly_id?Boolean



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

def should_generate_new_friendly_id?
  super || (title_changed? && persisted?)
end

#to_partial_pathObject

explicitly set the partial path so that we don’t have to duplicate view logic.



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

def to_partial_path
  'spotlight/pages/page'
end

#top_level_page?Boolean



72
73
74
# File 'app/models/spotlight/page.rb', line 72

def top_level_page?
  try(:parent_page).blank?
end

#top_level_page_or_selfObject



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

def top_level_page_or_self
  parent_page || self
end