Sha256: 10b066d380f95204dfceca895a119a57448b80c1ae9aefc0641c2ba18d3fa702
Contents?: true
Size: 1.77 KB
Versions: 5
Compression:
Stored size: 1.77 KB
Contents
class Article < Content # default_scope :order => "#{self.table_name}.published_at DESC" filters_attributes :except => [:excerpt, :excerpt_html, :body, :body_html, :cached_tag_list] validates_presence_of :title, :body validates_uniqueness_of :permalink, scope: :section_id, case_sensitive: true class_attribute :meta_fields, default: %w(keywords description author copyright geourl) class << self def locale "en" end end def primary? self == section.articles.primary end def previous section.articles.published.where(["#{self.class.table_name}.published_at < ?", published_at]).reorder(published_at: :desc).first end alias_method :previous_article, :previous def next section.articles.published.where(["#{self.class.table_name}.published_at > ?", published_at]).reorder(published_at: :asc).first end alias_method :next_article, :next def has_excerpt? return false if excerpt == "<p> </p>" # empty excerpt with fckeditor excerpt.present? end 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 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 end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
adva-0.1.4 | app/models/article.rb |
adva-0.1.3 | app/models/article.rb |
adva-0.1.2 | app/models/article.rb |
adva-0.1.1 | app/models/article.rb |
adva-0.1.0 | app/models/article.rb |