Class: Article

Inherits:
Content
  • Object
show all
Defined in:
app/models/article.rb

Instance Attribute Summary

Attributes inherited from Content

#draft

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Content

#author_id=, #category_titles, #draft?, find_sti_class, #just_published?, #owner, #owners, #pending?, primary, #published?, #published_at=, #published_at?, #published_month, #published_year, #state, #to_param

Methods included from Adva::BelongsToAuthor

included

Methods included from Adva::HasPermalink

included

Class Method Details

.localeObject



8
9
10
# File 'app/models/article.rb', line 8

def locale
  "en"
end

Instance Method Details



32
33
34
35
36
37
# File 'app/models/article.rb', line 32

def full_permalink
  raise "cannot create full_permalink for an article that belongs to a non-blog section" unless section.is_a?(Blog)
  # raise "can not create full_permalink for an unpublished article" unless published?
  date = [:year, :month, :day].map { |key| [key, (published? ? published_at : created_at).send(key)] }.flatten
  Hash[:permalink, permalink, *date]
end

#has_excerpt?Boolean

Returns:

  • (Boolean)


27
28
29
30
# File 'app/models/article.rb', line 27

def has_excerpt?
  return false if excerpt == "<p>&#160;</p>" # empty excerpt with fckeditor
  excerpt.present?
end

#nextObject Also known as: next_article



22
23
24
# File 'app/models/article.rb', line 22

def next
  section.articles.published.where(["#{self.class.table_name}.published_at > ?", published_at]).reorder(published_at: :asc).first
end

#previousObject Also known as: previous_article



17
18
19
# File 'app/models/article.rb', line 17

def previous
  section.articles.published.where(["#{self.class.table_name}.published_at < ?", published_at]).reorder(published_at: :desc).first
end

#primary?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'app/models/article.rb', line 13

def primary?
  self == section.articles.primary
end