Class: Article

Inherits:
Content 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=, #cache_key, #category_titles, #cells_updated_at, #draft?, #just_published?, #owner, #owners, #pending?, primary, #published?, #published_at=, #published_at?, #published_month, #published_year, #state, #to_param

Class Method Details

.localeObject



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

def locale
  "en"
end

Instance Method Details

#default_meta_descriptionObject



43
44
45
46
47
48
# File 'app/models/article.rb', line 43

def default_meta_description
  sanitizer = defined?(Rails::Html::FullSanitizer) ? Rails::Html::FullSanitizer.new : HTML::FullSanitizer.new
  sanitized_excerpt = sanitizer.sanitize(excerpt || "").gsub(/\s+/, " ").strip.truncate(160)
  sanitized_body = sanitizer.sanitize(body || "").gsub(/\s+/, " ").strip.truncate(160)
  sanitized_excerpt.present? ? sanitized_excerpt : sanitized_body
end


36
37
38
39
40
41
# File 'app/models/article.rb', line 36

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)


31
32
33
34
# File 'app/models/article.rb', line 31

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

#nextObject Also known as: next_article



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

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



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

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

#primary?Boolean

Returns:

  • (Boolean)


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

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