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
93
94
95
|
# File 'app/models/spotlight/page.rb', line 93
def about_page?
is_a? AboutPage
end
|
#clone_for_locale(locale) ⇒ Object
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'app/models/spotlight/page.rb', line 133
def clone_for_locale(locale)
dup.tap do |np|
np.locale = locale
np.default_locale_page = self
np.published = false
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=(content) ⇒ Object
55
56
57
58
59
60
61
62
|
# File 'app/models/spotlight/page.rb', line 55
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?
64
65
66
|
# File 'app/models/spotlight/page.rb', line 64
def content?
self[:content].present? && content.present?
end
|
#content_changed! ⇒ Object
51
52
53
|
# File 'app/models/spotlight/page.rb', line 51
def content_changed!
@content = nil
end
|
69
70
71
|
# File 'app/models/spotlight/page.rb', line 69
def
true
end
|
#feature_page? ⇒ Boolean
89
90
91
|
# File 'app/models/spotlight/page.rb', line 89
def feature_page?
is_a? FeaturePage
end
|
#featured_image ⇒ Object
73
74
75
|
# File 'app/models/spotlight/page.rb', line 73
def featured_image
nil
end
|
#home_page? ⇒ Boolean
97
98
99
|
# File 'app/models/spotlight/page.rb', line 97
def home_page?
is_a? HomePage
end
|
#lock!(user) ⇒ Object
119
120
121
|
# File 'app/models/spotlight/page.rb', line 119
def lock!(user)
create_lock(by: user).tap(&:current_session!) unless lock.present?
end
|
#should_display_title? ⇒ Boolean
115
116
117
|
# File 'app/models/spotlight/page.rb', line 115
def should_display_title?
title.present?
end
|
#should_generate_new_friendly_id? ⇒ Boolean
109
110
111
112
113
|
# File 'app/models/spotlight/page.rb', line 109
def should_generate_new_friendly_id?
return false if new_record? && slug.present?
super || (title_changed? && persisted?)
end
|
#thumbnail_image_url ⇒ Object
77
78
79
80
81
|
# File 'app/models/spotlight/page.rb', line 77
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.
85
86
87
|
# File 'app/models/spotlight/page.rb', line 85
def to_partial_path
'spotlight/pages/page'
end
|
#top_level_page? ⇒ Boolean
101
102
103
|
# File 'app/models/spotlight/page.rb', line 101
def top_level_page?
try(:parent_page).blank?
end
|
#top_level_page_or_self ⇒ Object
105
106
107
|
# File 'app/models/spotlight/page.rb', line 105
def top_level_page_or_self
parent_page || self
end
|
#translated_page_for(locale) ⇒ Object
129
130
131
|
# File 'app/models/spotlight/page.rb', line 129
def translated_page_for(locale)
translated_pages.for_locale(locale).first
end
|
#updated_after?(other_page) ⇒ Boolean
123
124
125
126
127
|
# File 'app/models/spotlight/page.rb', line 123
def updated_after?(other_page)
return false unless other_page
updated_at > other_page.updated_at
end
|