Class: Skyline::Article Abstract

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
ActiveSupport::Memoizable
Defined in:
app/models/skyline/article.rb

Overview

This class is abstract.

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

Page, PageFragment

Defined Under Namespace

Classes: Data

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.publishable?true, false

This method is abstract.

Implement in subclass if needed, true is a sensible default.

Is this type of article publishable?

Returns:

  • (true, false)

    Wether or not this article type can be published



90
91
92
# File 'app/models/skyline/article.rb', line 90

def publishable?
  true
end

.right_prefixString

This method is abstract.

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.

Returns:

  • (String)

    The string to prefix to the right (_create, _update, _delete)



82
83
84
# File 'app/models/skyline/article.rb', line 82

def right_prefix
  "article"      
end

.to_paramObject



73
74
75
# File 'app/models/skyline/article.rb', line 73

def to_param
  self.name.underscore
end

Instance Method Details

#data_classClass, false

The class that provides our custom data fields.

Returns:

  • (Class, false)

    False if we don’t have an inner Data class, the inner Data class if there is one.



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

#depublishvoid

This method returns an undefined value.

Depublish an article, removes the published_publication if keep_history? is false

Raises:

  • (StandardError)

    If page is persistent and cannot be depulished



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?

Returns:

  • (true, false)


134
135
136
# File 'app/models/skyline/article.rb', line 134

def depublishable?
  !self.persistent?
end

#destroyfalse, true

Depublish this article and destroy it.

Returns:

  • (false, true)

    True sucessfully destroyed, otherwise false

See Also:

  • Skylien::Article#depublish


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).

Returns:

  • (true, false)


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.

Parameters:

  • user (Skyline::User, Integer)

    The user or user id to check the access for.

Returns:

  • (true, false)

    True if the user can edit this page, false otherwise



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

Returns:

  • (Boolean)


179
180
181
# File 'app/models/skyline/article.rb', line 179

def enable_locking?
  true
end

#enable_multiple_variants?Boolean

Returns:

  • (Boolean)


175
176
177
# File 'app/models/skyline/article.rb', line 175

def enable_multiple_variants?
  true
end

#enable_publishing?Boolean

Returns:

  • (Boolean)


171
172
173
# File 'app/models/skyline/article.rb', line 171

def enable_publishing?
  true
end

#keep_history?Boolean

Returns:

  • (Boolean)


167
168
169
# File 'app/models/skyline/article.rb', line 167

def keep_history?
  false
end

#preview_wrapper_pageSkyline::Page?

This method is abstract.

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

Returns:

  • (Skyline::Page, nil)

    The page to wrap this article in when previewing. Nil if no wrapping is needed.



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?

Returns:

  • (true, false)

See Also:



158
159
160
# File 'app/models/skyline/article.rb', line 158

def previewable?
  self.renderable?
end

#published?true, false

Has this article been puslished?

Returns:

  • (true, false)

    True if it has a published_publication, meaning it’s currently published



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.

Returns:

  • (true, false)


150
151
152
# File 'app/models/skyline/article.rb', line 150

def renderable?
  self.renderable_scope.renderer.templates_for(self).any?
end

#renderable_scopeObject



241
242
243
# File 'app/models/skyline/article.rb', line 241

def renderable_scope
  Skyline::Rendering::Scopes::Wildcard.new
end

#right_prefixObject



217
218
219
# File 'app/models/skyline/article.rb', line 217

def right_prefix
  self.class.right_prefix
end

#rollbackable?Boolean

Returns:

  • (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

#siteObject



237
238
239
# File 'app/models/skyline/article.rb', line 237

def site
  Skyline::Site.new
end

#sitesObject



233
234
235
# File 'app/models/skyline/article.rb', line 233

def sites
  [Skyline::Site.new]
end

#titleObject



221
222
223
# File 'app/models/skyline/article.rb', line 221

def title
  self.id
end