Class: Spotlight::Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Spotlight::Page
show all
- Extended by:
- FriendlyId
- Defined in:
- app/models/spotlight/page.rb
Overview
Constant Summary
collapse
- MAX_PAGES =
1000
Instance Method Summary
collapse
Instance Method Details
#about_page? ⇒ Boolean
100
101
102
|
# File 'app/models/spotlight/page.rb', line 100
def about_page?
is_a? AboutPage
end
|
#clone_for_locale(locale) ⇒ Object
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'app/models/spotlight/page.rb', line 140
def clone_for_locale(locale)
dup.tap do |np|
np.locale = locale
np.default_locale_page = self
np.published = false
np.slug = slug
if !top_level_page? && (parent_translation = parent_page.translated_page_for(locale)).present?
np.parent_page = parent_translation
end
child_pages.for_locale(locale).update(parent_page: np) if top_level_page? && respond_to?(:child_pages)
end
end
|
#content ⇒ Object
52
53
54
55
56
|
# File 'app/models/spotlight/page.rb', line 52
def content
@content ||= begin
Spotlight::PageContent.for(self, :content)
end
end
|
#content=(content) ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'app/models/spotlight/page.rb', line 62
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?
71
72
73
|
# File 'app/models/spotlight/page.rb', line 71
def content?
self[:content].present? && content.present?
end
|
#content_changed! ⇒ Object
48
49
50
|
# File 'app/models/spotlight/page.rb', line 48
def content_changed!
@content = nil
end
|
#content_type ⇒ Object
58
59
60
|
# File 'app/models/spotlight/page.rb', line 58
def content_type
self[:content_type] || Spotlight::Engine.config.default_page_content_type
end
|
76
77
78
|
# File 'app/models/spotlight/page.rb', line 76
def
true
end
|
#feature_page? ⇒ Boolean
96
97
98
|
# File 'app/models/spotlight/page.rb', line 96
def feature_page?
is_a? FeaturePage
end
|
#featured_image ⇒ Object
80
81
82
|
# File 'app/models/spotlight/page.rb', line 80
def featured_image
nil
end
|
#home_page? ⇒ Boolean
104
105
106
|
# File 'app/models/spotlight/page.rb', line 104
def home_page?
is_a? HomePage
end
|
#lock!(user) ⇒ Object
126
127
128
|
# File 'app/models/spotlight/page.rb', line 126
def lock!(user)
create_lock(by: user).tap(&:current_session!) unless lock.present?
end
|
#should_display_title? ⇒ Boolean
122
123
124
|
# File 'app/models/spotlight/page.rb', line 122
def should_display_title?
title.present?
end
|
#should_generate_new_friendly_id? ⇒ Boolean
116
117
118
119
120
|
# File 'app/models/spotlight/page.rb', line 116
def should_generate_new_friendly_id?
return false if new_record? && slug.present?
super || (title_changed? && persisted?)
end
|
#thumbnail_image_url ⇒ Object
84
85
86
87
88
|
# File 'app/models/spotlight/page.rb', line 84
def thumbnail_image_url
return unless thumbnail && thumbnail.iiif_url
thumbnail.iiif_url
end
|
#to_partial_path ⇒ Object
explicitly set the partial path so that we don’t have to duplicate view logic.
92
93
94
|
# File 'app/models/spotlight/page.rb', line 92
def to_partial_path
'spotlight/pages/page'
end
|
#top_level_page? ⇒ Boolean
108
109
110
|
# File 'app/models/spotlight/page.rb', line 108
def top_level_page?
try(:parent_page).blank?
end
|
#top_level_page_or_self ⇒ Object
112
113
114
|
# File 'app/models/spotlight/page.rb', line 112
def top_level_page_or_self
parent_page || self
end
|
#translated_page_for(locale) ⇒ Object
136
137
138
|
# File 'app/models/spotlight/page.rb', line 136
def translated_page_for(locale)
translated_pages.for_locale(locale).first
end
|
#updated_after?(other_page) ⇒ Boolean
130
131
132
133
134
|
# File 'app/models/spotlight/page.rb', line 130
def updated_after?(other_page)
return false unless other_page
updated_at > other_page.updated_at
end
|