Repository URL to install this package:
|
Version:
0.4.0 ▾
|
module Neoteric
module NewsPost
def self.included(base)
base.table_name = 'news_posts'
base.pubdraft
base.send :include, ::Neoteric::Archiver
base.archive_fields :single => :published_at,
:scope => :published
base.extend FriendlyId
base.friendly_id :title, :use => :slugged
base.acts_as_taggable
base.attr_accessible :tag_list
base.send :include, ::Neoteric::Navigator
base.navigate :scope => :published,
:field => :published_at,
:order => 'published_at DESC, title'
base.send :before_save, :trigger_state_transition_callbacks
base.attr_accessible :body, :excerpt, :published_at, :title
base.send :default_scope, :order => ['published_at DESC', :title]
base.scope :published, lambda { base.where("published_at <= ? \
AND state = 'published'",
Date.today) }
base.scope :future, lambda { base.where("published_at > ?", Date.today) }
end
private
def date_and_title
[published_at.to_s, title].join(' ')
end
def set_published_at
self.published_at = Date.today if published_at.blank?
end
def clear_published_at
self.published_at = nil
end
def trigger_state_transition_callbacks
case self.state
when 'published'
set_published_at
else
clear_published_at
end
end
end
end