Class: Skyline::Article Abstract
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Skyline::Article
- Extended by:
- ActiveSupport::Memoizable
- Defined in:
- app/models/skyline/article.rb
Overview
Subclass and implement the Article interface
Articles are container objects that contain Sections, have history and can (optional) be previewed and published.
Direct Known Subclasses
Defined Under Namespace
Classes: Data
Class Method Summary collapse
-
.publishable? ⇒ true, false
abstract
Is this type of article publishable?.
-
.right_prefix ⇒ String
abstract
The prefix to use when determining rights.
- .to_param ⇒ Object
Instance Method Summary collapse
-
#data_class ⇒ Class, false
The class that provides our custom data fields.
-
#depublish ⇒ void
Depublish an article, removes the published_publication if keep_history? is false.
-
#depublishable? ⇒ true, false
Can this article be depublished?.
-
#destroy ⇒ false, true
Depublish this article and destroy it.
-
#destroyable? ⇒ true, false
Can this article be destroyed? Only works if the article isn’t persisntent and does not have a publication (isn’t published).
-
#editable_by?(user) ⇒ true, false
Checks if the page can be edited by a certain user Currently only checks on page locks.
- #enable_locking? ⇒ Boolean
- #enable_multiple_variants? ⇒ Boolean
- #enable_publishing? ⇒ Boolean
- #keep_history? ⇒ Boolean
-
#preview_wrapper_page ⇒ Skyline::Page?
abstract
A subclass can return a Page in which the article (ie: NewsItem) will be rendered for previewing.
-
#previewable? ⇒ true, false
Can this article be previewed? Delegates to Skyline::Article#renderable?.
-
#published? ⇒ true, false
Has this article been puslished?.
-
#renderable? ⇒ true, false
Can this article be rendered.
- #renderable_scope ⇒ Object
- #right_prefix ⇒ Object
- #rollbackable? ⇒ Boolean
- #set_default_variant(variant) ⇒ Object
- #set_default_variant!(variant) ⇒ Object
- #site ⇒ Object
- #sites ⇒ Object
- #title ⇒ Object
Class Method Details
.publishable? ⇒ true, false
Implement in subclass if needed, true is a sensible default.
Is this type of article publishable?
90 91 92 |
# File 'app/models/skyline/article.rb', line 90 def publishable? true end |
.right_prefix ⇒ String
Implement the value correct value in your subclass, defaults to ‘article’
The prefix to use when determining rights. User#allow? uses this method when called with 2 parameters.
82 83 84 |
# File 'app/models/skyline/article.rb', line 82 def right_prefix "article" end |
.to_param ⇒ Object
73 74 75 |
# File 'app/models/skyline/article.rb', line 73 def to_param self.name.underscore end |
Instance Method Details
#data_class ⇒ Class, false
The class that provides our custom data fields.
208 209 210 211 212 213 214 |
# File 'app/models/skyline/article.rb', line 208 def data_class # Note: We can't use memoize here, because it freezes the class return @_data_class unless @_data_class.nil? @_data_class = (self.class.name + "::" + "Data").constantize rescue NameError @_data_class = false end |
#depublish ⇒ void
This method returns an undefined value.
Depublish an article, removes the published_publication if keep_history? is false
108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'app/models/skyline/article.rb', line 108 def depublish raise StandardError, "can't be depublished because this page is persistent" if self.persistent? if self.published_publication self.published_publication.destroy unless self.keep_history? self.published_publication = nil end self.published_publication_data = nil self.url_part = "page-#{self.position}" self.save end |
#depublishable? ⇒ true, false
Can this article be depublished?
134 135 136 |
# File 'app/models/skyline/article.rb', line 134 def depublishable? !self.persistent? end |
#destroy ⇒ false, true
Depublish this article and destroy it.
126 127 128 129 |
# File 'app/models/skyline/article.rb', line 126 def destroy depublish super end |
#destroyable? ⇒ true, false
Can this article be destroyed? Only works if the article isn’t persisntent and does not have a publication (isn’t published).
142 143 144 |
# File 'app/models/skyline/article.rb', line 142 def destroyable? !self.persistent? && self.published_publication == nil end |
#editable_by?(user) ⇒ true, false
Checks if the page can be edited by a certain user Currently only checks on page locks.
189 190 191 192 |
# File 'app/models/skyline/article.rb', line 189 def editable_by?(user) user = user.kind_of?(Skyline::User) ? user : Skyline::User.find_by_id(user) self.locked? && user.allow?(:page_lock) || !self.locked? end |
#enable_locking? ⇒ Boolean
179 180 181 |
# File 'app/models/skyline/article.rb', line 179 def enable_locking? true end |
#enable_multiple_variants? ⇒ Boolean
175 176 177 |
# File 'app/models/skyline/article.rb', line 175 def enable_multiple_variants? true end |
#enable_publishing? ⇒ Boolean
171 172 173 |
# File 'app/models/skyline/article.rb', line 171 def enable_publishing? true end |
#keep_history? ⇒ Boolean
167 168 169 |
# File 'app/models/skyline/article.rb', line 167 def keep_history? false end |
#preview_wrapper_page ⇒ Skyline::Page?
Implement this in a subclass to get the Page from Settings or from somewhere else.
A subclass can return a Page in which the article (ie: NewsItem) will be rendered for previewing
229 230 231 |
# File 'app/models/skyline/article.rb', line 229 def preview_wrapper_page nil end |
#previewable? ⇒ true, false
Can this article be previewed? Delegates to Skyline::Article#renderable?
158 159 160 |
# File 'app/models/skyline/article.rb', line 158 def previewable? self.renderable? end |
#published? ⇒ true, false
Has this article been puslished?
98 99 100 101 102 |
# File 'app/models/skyline/article.rb', line 98 def published? # Don't use only "self.published_publication" here, it causes way too many lookups # If the next test is wrong, than maybe you should wonder why it is wrong? Foreign key left behind? self.published_publication_id.present? end |
#renderable? ⇒ true, false
Can this article be rendered. This basically means wether or not there are any templates for this article.
150 151 152 |
# File 'app/models/skyline/article.rb', line 150 def renderable? self.renderable_scope.renderer.templates_for(self).any? end |
#renderable_scope ⇒ Object
241 242 243 |
# File 'app/models/skyline/article.rb', line 241 def renderable_scope Skyline::Rendering::Scopes::Wildcard.new end |
#right_prefix ⇒ Object
217 218 219 |
# File 'app/models/skyline/article.rb', line 217 def right_prefix self.class.right_prefix end |
#rollbackable? ⇒ Boolean
163 164 165 |
# File 'app/models/skyline/article.rb', line 163 def rollbackable? true end |
#set_default_variant(variant) ⇒ Object
200 201 202 203 |
# File 'app/models/skyline/article.rb', line 200 def set_default_variant(variant) return if variant.id == self.default_variant_id && variant.data_id == self.default_variant_data_id self.attributes = {:default_variant_id => variant.id, :default_variant_data_id => variant.data_id} end |
#set_default_variant!(variant) ⇒ Object
195 196 197 198 |
# File 'app/models/skyline/article.rb', line 195 def set_default_variant!(variant) return if variant.id == self.default_variant_id && variant.data_id == self.default_variant_data_id self.update_attributes(:default_variant_id => variant.id, :default_variant_data_id => variant.data_id) end |
#site ⇒ Object
237 238 239 |
# File 'app/models/skyline/article.rb', line 237 def site Skyline::Site.new end |
#sites ⇒ Object
233 234 235 |
# File 'app/models/skyline/article.rb', line 233 def sites [Skyline::Site.new] end |
#title ⇒ Object
221 222 223 |
# File 'app/models/skyline/article.rb', line 221 def title self.id end |