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 =
Spotlight::Engine.config.max_pages
Instance Method Summary
collapse
Instance Method Details
#about_page? ⇒ Boolean
113
114
115
|
# File 'app/models/spotlight/page.rb', line 113
def about_page?
is_a? AboutPage
end
|
#clone_for_locale(clone_locale) ⇒ Object
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
# File 'app/models/spotlight/page.rb', line 155
def clone_for_locale(clone_locale)
dup.tap do |new_page|
new_page.locale = clone_locale
new_page.default_locale_page = self
new_page.published = false
new_page.slug = slug
new_page.parent_page = parent_page_for(clone_locale) unless top_level_page?
next unless respond_to?(:child_pages)
child_pages.find_each do |default_locale_child_page|
default_locale_child_page.translated_page_for(clone_locale)&.update(parent_page: new_page)
end
end
end
|
#content ⇒ Object
67
68
69
|
# File 'app/models/spotlight/page.rb', line 67
def content
@content ||= Spotlight::PageContent.for(self, :content)
end
|
#content=(content) ⇒ Object
75
76
77
78
79
80
81
82
|
# File 'app/models/spotlight/page.rb', line 75
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?
84
85
86
|
# File 'app/models/spotlight/page.rb', line 84
def content?
self[:content].present? && content.present?
end
|
#content_changed! ⇒ Object
63
64
65
|
# File 'app/models/spotlight/page.rb', line 63
def content_changed!
@content = nil
end
|
#content_type ⇒ Object
71
72
73
|
# File 'app/models/spotlight/page.rb', line 71
def content_type
self[:content_type] || Spotlight::Engine.config.default_page_content_type
end
|
#default_locale_title ⇒ Object
Returns the title of the page in the default locale regardless of the current locale.
57
58
59
60
61
|
# File 'app/models/spotlight/page.rb', line 57
def default_locale_title
return self[:title] if I18n.locale == I18n.default_locale || default_locale_page.blank?
default_locale_page[:title]
end
|
89
90
91
|
# File 'app/models/spotlight/page.rb', line 89
def
true
end
|
#feature_page? ⇒ Boolean
109
110
111
|
# File 'app/models/spotlight/page.rb', line 109
def feature_page?
is_a? FeaturePage
end
|
#featured_image ⇒ Object
93
94
95
|
# File 'app/models/spotlight/page.rb', line 93
def featured_image
nil
end
|
#home_page? ⇒ Boolean
117
118
119
|
# File 'app/models/spotlight/page.rb', line 117
def home_page?
is_a? HomePage
end
|
#lock!(user) ⇒ Object
139
140
141
|
# File 'app/models/spotlight/page.rb', line 139
def lock!(user)
create_lock(by: user).tap(&:current_session!) if lock.blank?
end
|
#should_display_title? ⇒ Boolean
135
136
137
|
# File 'app/models/spotlight/page.rb', line 135
def should_display_title?
title.present?
end
|
#should_generate_new_friendly_id? ⇒ Boolean
129
130
131
132
133
|
# File 'app/models/spotlight/page.rb', line 129
def should_generate_new_friendly_id?
return false if new_record? && slug.present?
super || (title_changed? && persisted?)
end
|
#thumbnail_image_url ⇒ Object
97
98
99
100
101
|
# File 'app/models/spotlight/page.rb', line 97
def thumbnail_image_url
return unless thumbnail&.iiif_url
thumbnail.iiif_url
end
|
#title ⇒ Object
50
51
52
53
54
|
# File 'app/models/spotlight/page.rb', line 50
def title
return super if I18n.locale == I18n.default_locale
translated_page_for(I18n.locale)&.title || super
end
|
#to_partial_path ⇒ Object
explicitly set the partial path so that we don’t have to duplicate view logic.
105
106
107
|
# File 'app/models/spotlight/page.rb', line 105
def to_partial_path
'spotlight/pages/page'
end
|
#top_level_page? ⇒ Boolean
121
122
123
|
# File 'app/models/spotlight/page.rb', line 121
def top_level_page?
try(:parent_page).blank?
end
|
#top_level_page_or_self ⇒ Object
125
126
127
|
# File 'app/models/spotlight/page.rb', line 125
def top_level_page_or_self
parent_page || self
end
|
#translated_page_for(locale) ⇒ Object
149
150
151
152
153
|
# File 'app/models/spotlight/page.rb', line 149
def translated_page_for(locale)
return self if locale == self.locale
translated_pages.for_locale(locale).first
end
|
#updated_after?(other_page) ⇒ Boolean
143
144
145
146
147
|
# File 'app/models/spotlight/page.rb', line 143
def updated_after?(other_page)
return false unless other_page
updated_at > other_page.updated_at
end
|