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?
79 80 81 |
# File 'app/models/skyline/article.rb', line 79 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.
71 72 73 |
# File 'app/models/skyline/article.rb', line 71 def right_prefix "article" end |
.to_param ⇒ Object
62 63 64 |
# File 'app/models/skyline/article.rb', line 62 def to_param self.name.underscore end |
Instance Method Details
#data_class ⇒ Class, false
The class that provides our custom data fields.
197 198 199 200 201 202 203 |
# File 'app/models/skyline/article.rb', line 197 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
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'app/models/skyline/article.rb', line 97 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?
123 124 125 |
# File 'app/models/skyline/article.rb', line 123 def depublishable? !self.persistent? end |
#destroy ⇒ false, true
Depublish this article and destroy it.
115 116 117 118 |
# File 'app/models/skyline/article.rb', line 115 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).
131 132 133 |
# File 'app/models/skyline/article.rb', line 131 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.
178 179 180 181 |
# File 'app/models/skyline/article.rb', line 178 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
168 169 170 |
# File 'app/models/skyline/article.rb', line 168 def enable_locking? true end |
#enable_multiple_variants? ⇒ Boolean
164 165 166 |
# File 'app/models/skyline/article.rb', line 164 def enable_multiple_variants? true end |
#enable_publishing? ⇒ Boolean
160 161 162 |
# File 'app/models/skyline/article.rb', line 160 def enable_publishing? true end |
#keep_history? ⇒ Boolean
156 157 158 |
# File 'app/models/skyline/article.rb', line 156 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
218 219 220 |
# File 'app/models/skyline/article.rb', line 218 def preview_wrapper_page nil end |
#previewable? ⇒ true, false
Can this article be previewed? Delegates to Skyline::Article#renderable?
147 148 149 |
# File 'app/models/skyline/article.rb', line 147 def previewable? self.renderable? end |
#published? ⇒ true, false
Has this article been puslished?
87 88 89 90 91 |
# File 'app/models/skyline/article.rb', line 87 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.
139 140 141 |
# File 'app/models/skyline/article.rb', line 139 def renderable? self.renderable_scope.renderer.templates_for(self).any? end |
#renderable_scope ⇒ Object
230 231 232 |
# File 'app/models/skyline/article.rb', line 230 def renderable_scope Skyline::WildcardRenderableScope.new end |
#right_prefix ⇒ Object
206 207 208 |
# File 'app/models/skyline/article.rb', line 206 def right_prefix self.class.right_prefix end |
#rollbackable? ⇒ Boolean
152 153 154 |
# File 'app/models/skyline/article.rb', line 152 def rollbackable? true end |
#set_default_variant(variant) ⇒ Object
189 190 191 192 |
# File 'app/models/skyline/article.rb', line 189 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
184 185 186 187 |
# File 'app/models/skyline/article.rb', line 184 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
226 227 228 |
# File 'app/models/skyline/article.rb', line 226 def site Skyline::Site.new end |
#sites ⇒ Object
222 223 224 |
# File 'app/models/skyline/article.rb', line 222 def sites [Skyline::Site.new] end |
#title ⇒ Object
210 211 212 |
# File 'app/models/skyline/article.rb', line 210 def title self.id end |