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



79
80
81
# File 'app/models/skyline/article.rb', line 79

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)



71
72
73
# File 'app/models/skyline/article.rb', line 71

def right_prefix
  "article"      
end

.to_paramObject



62
63
64
# File 'app/models/skyline/article.rb', line 62

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.



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

#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



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?

Returns:

  • (true, false)


123
124
125
# File 'app/models/skyline/article.rb', line 123

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


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

Returns:

  • (true, false)


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.

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



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

Returns:

  • (Boolean)


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

def enable_locking?
  true
end

#enable_multiple_variants?Boolean

Returns:

  • (Boolean)


164
165
166
# File 'app/models/skyline/article.rb', line 164

def enable_multiple_variants?
  true
end

#enable_publishing?Boolean

Returns:

  • (Boolean)


160
161
162
# File 'app/models/skyline/article.rb', line 160

def enable_publishing?
  true
end

#keep_history?Boolean

Returns:

  • (Boolean)


156
157
158
# File 'app/models/skyline/article.rb', line 156

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.



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?

Returns:

  • (true, false)

See Also:



147
148
149
# File 'app/models/skyline/article.rb', line 147

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



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.

Returns:

  • (true, false)


139
140
141
# File 'app/models/skyline/article.rb', line 139

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

#renderable_scopeObject



230
231
232
# File 'app/models/skyline/article.rb', line 230

def renderable_scope
  Skyline::WildcardRenderableScope.new
end

#right_prefixObject



206
207
208
# File 'app/models/skyline/article.rb', line 206

def right_prefix
  self.class.right_prefix
end

#rollbackable?Boolean

Returns:

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

#siteObject



226
227
228
# File 'app/models/skyline/article.rb', line 226

def site
  Skyline::Site.new
end

#sitesObject



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

def sites
  [Skyline::Site.new]
end

#titleObject



210
211
212
# File 'app/models/skyline/article.rb', line 210

def title
  self.id
end