Class: Skyline::Article Abstract
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Skyline::Article
- 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
Instance Attribute Summary collapse
-
#becomes_default_variant_after_save ⇒ Object
Stores a variant that will become the default variant AFTER save.
Class Method Summary collapse
-
.can_have_multiple_variants? ⇒ true, false
abstract
Can this type of article have multiple variants?.
-
.lockable? ⇒ true, false
abstract
Can this type of article be locked?.
-
.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
-
#can_have_multiple_variants? ⇒ Boolean
Can this article instance have multiple variants?.
-
#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).
- #dup ⇒ Object
-
#editable_by?(user) ⇒ true, false
Checks if the page can be edited by a certain user Currently only checks on page locks.
-
#keep_history? ⇒ true, false
Do we need to keep the history of this article?.
-
#lockable? ⇒ Boolean
Can this article instance be locked? .
-
#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
Multisite interface.
- #right_prefix ⇒ Object
- #set_default_variant(variant) ⇒ Object
- #set_default_variant!(variant) ⇒ Object
-
#site ⇒ Object
Multisite interface.
-
#sites ⇒ Object
Multisite interface.
- #title ⇒ Object
Instance Attribute Details
#becomes_default_variant_after_save ⇒ Object
Stores a variant that will become the default variant AFTER save
78 79 80 |
# File 'app/models/skyline/article.rb', line 78 def becomes_default_variant_after_save @becomes_default_variant_after_save end |
Class Method Details
.can_have_multiple_variants? ⇒ true, false
Implement in subclass if needed, true is the default
Can this type of article have multiple variants?
114 115 116 |
# File 'app/models/skyline/article.rb', line 114 def can_have_multiple_variants? true end |
.lockable? ⇒ true, false
Implement in subclass if needed, true is the default
Can this type of article be locked?
106 107 108 |
# File 'app/models/skyline/article.rb', line 106 def lockable? true end |
.publishable? ⇒ true, false
Implement in subclass if needed, true is the default.
Is this type of article publishable?
98 99 100 |
# File 'app/models/skyline/article.rb', line 98 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.
90 91 92 |
# File 'app/models/skyline/article.rb', line 90 def right_prefix "article" end |
.to_param ⇒ Object
81 82 83 |
# File 'app/models/skyline/article.rb', line 81 def to_param self.name.underscore end |
Instance Method Details
#can_have_multiple_variants? ⇒ Boolean
Can this article instance have multiple variants?
Defaults to Skyline::Article.can_have_multiple_variants?
203 204 205 |
# File 'app/models/skyline/article.rb', line 203 def can_have_multiple_variants? self.class.can_have_multiple_variants? end |
#data_class ⇒ Class, false
The class that provides our custom data fields.
TODO : Dataleak waiting to happen (!!)
271 272 273 274 275 276 277 |
# File 'app/models/skyline/article.rb', line 271 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
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'app/models/skyline/article.rb', line 133 def depublish raise StandardError, "can't be depublished because this page is persistent" if self.persistent? if self.published_publication self.run_callbacks :depublication do self.published_publication.destroy unless self.keep_history? self.published_publication = nil end end self.published_publication_data = nil self.url_part = "page-#{self.position}" self.save end |
#depublishable? ⇒ true, false
Can this article be depublished?
161 162 163 |
# File 'app/models/skyline/article.rb', line 161 def depublishable? !self.persistent? end |
#destroy ⇒ false, true
Depublish this article and destroy it.
153 154 155 156 |
# File 'app/models/skyline/article.rb', line 153 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).
169 170 171 |
# File 'app/models/skyline/article.rb', line 169 def destroyable? !self.persistent? && self.published_publication == nil end |
#dup ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'app/models/skyline/article.rb', line 216 def dup s = super.tap do |dup| dup.created_at = nil dup.updated_at = nil dup.default_variant_id = nil dup.default_variant_data_id = nil dup.default_variant = nil dup.default_variant_data = nil dup.published_publication_id = nil dup.published_publication_data_id = nil dup.publications.clear dup.versions.clear dup.variants.clear self.variants.each do |variant| variant_dup = variant.dup dup.variants << variant_dup variant_dup.article = dup variant_dup.article_id = nil self.becomes_default_variant_after_save = variant_dup if variant == self.default_variant end dup end end |
#editable_by?(user) ⇒ true, false
Checks if the page can be edited by a certain user Currently only checks on page locks.
248 249 250 251 |
# File 'app/models/skyline/article.rb', line 248 def editable_by?(user) user = user.kind_of?(Skyline::Configuration.user_class) ? user : Skyline::Configuration.user_class.find_by_identification(user) self.locked? && user.allow?(:page_lock) || !self.locked? end |
#keep_history? ⇒ true, false
Do we need to keep the history of this article?
If true, this article will have multiple publications, if false, there is only one published publication.
212 213 214 |
# File 'app/models/skyline/article.rb', line 212 def keep_history? false end |
#lockable? ⇒ Boolean
Can this article instance be locked?
Defaults to the Skyline::Article.lockable?
194 195 196 |
# File 'app/models/skyline/article.rb', line 194 def lockable? self.class.lockable? 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
292 293 294 |
# File 'app/models/skyline/article.rb', line 292 def preview_wrapper_page nil end |
#previewable? ⇒ true, false
Can this article be previewed? Delegates to Skyline::Article#renderable?
185 186 187 |
# File 'app/models/skyline/article.rb', line 185 def previewable? self.renderable? end |
#published? ⇒ true, false
Has this article been puslished?
123 124 125 126 127 |
# File 'app/models/skyline/article.rb', line 123 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.
177 178 179 |
# File 'app/models/skyline/article.rb', line 177 def renderable? self.renderable_scope.renderer.templates_for(self).any? end |
#renderable_scope ⇒ Object
Multisite interface
307 308 309 |
# File 'app/models/skyline/article.rb', line 307 def renderable_scope Skyline::Rendering::Scopes::Wildcard.new end |
#right_prefix ⇒ Object
280 281 282 |
# File 'app/models/skyline/article.rb', line 280 def right_prefix self.class.right_prefix end |
#set_default_variant(variant) ⇒ Object
260 261 262 263 264 |
# File 'app/models/skyline/article.rb', line 260 def set_default_variant(variant) return false 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} true end |
#set_default_variant!(variant) ⇒ Object
254 255 256 257 258 |
# File 'app/models/skyline/article.rb', line 254 def set_default_variant!(variant) if set_default_variant(variant) self.save(:validate => false) end end |
#site ⇒ Object
Multisite interface
302 303 304 |
# File 'app/models/skyline/article.rb', line 302 def site Skyline::Site.new end |
#sites ⇒ Object
Multisite interface
297 298 299 |
# File 'app/models/skyline/article.rb', line 297 def sites [Skyline::Site.new] end |
#title ⇒ Object
284 285 286 |
# File 'app/models/skyline/article.rb', line 284 def title self.id end |