Sha256: d841feb5eb4aff3444222bfad79256f028d6b67191c6faaf7f6d53e3809ea533
Contents?: true
Size: 1.2 KB
Versions: 1
Compression:
Stored size: 1.2 KB
Contents
class Content < ActiveRecord::Base abstract_class = true belongs_to :site belongs_to :author, :class_name => 'User' scope :recent, order("published_at DESC") scope :published, lambda{ where("published_at is NOT null").where("published_at <= ?", Time.now).recent } scope :draft, where(:published_at => nil).recent before_save :update_published_at def body self[:body] end def body_html if self.body_source markdown = RDiscount.new(self.body_source) @body_html ||= markdown.to_html end end alias_method :body_source, :body alias_method :body, :body_html def author_name author.display_name if author end def status published? ? 'published' : 'draft' end def status=(status) if status == 'draft' self[:published_at] = nil else self[:published_at] = Time.now unless published? end end def published=(flag) @mark_published = flag end def published? published_at != nil end def publish! self.published = true self.send(:update_published_at) save end private def update_published_at self[:published_at] = Time.now if @mark_published and not published? end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
content_engine-0.1.0 | app/models/content.rb |