Sha256: ebc464fc68028d37368311538746897eb9b45296e02e0a6e0ed72618393ed3fd

Contents?: true

Size: 1.21 KB

Versions: 7

Compression:

Stored size: 1.21 KB

Contents

require 'dm-timestamps'
class OrangeBlogPost < Orange::Carton
  id
  front do
    title :title, :length => 255
    fulltext :body
  end
  admin do
    fulltext :summary
  end
  orange do
    boolean :published, :default => false
    text :slug, :length => 255
    text :author
  end
  
  property :created_at, DateTime
  property :published_at, DateTime
  property :updated_at, DateTime
  belongs_to :blog, "OrangeBlog"
  
  def title=(t)
    self.attribute_set('title', t)
    self.attribute_set('slug', t.downcase.gsub(/<\/?[^>]*>/, "").gsub(/[']+/, "").gsub(/[^a-z0-9]+/, "_"))
  end
  
  def published=(val)
    if val == '1' || val === true
      self.publish
    else
      self.attribute_set('published', false)
    end
  end
  
  def publish
    self.published_at = Time.now if self.published_at.blank?
    self.attribute_set('published', true)
  end
  
  def publish!
    self.publish
    self.save
  end
  
  def self.year_and_month(yr, mnth)
    all(:published_at.gte => DateTime.new(yr, mnth, 1), :published_at.lt => DateTime.new(yr, mnth + 1, 1))
  end
  
  def self.slug(slug)
    first(:slug => slug)
  end
  
  def self.published
    all(:published => true)
  end
  
  def self.draft
    all(:published => false)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
orange-more-0.7.2 lib/orange-more/blog/cartons/blog_post.rb
orange-more-0.7.1 lib/orange-more/blog/cartons/blog_post.rb
orange-more-0.6.5 lib/orange-more/blog/cartons/blog_post.rb
orange-more-0.6.4 lib/orange-more/blog/cartons/blog_post.rb
orange-more-0.6.3 lib/orange-more/blog/cartons/blog_post.rb
orange-more-0.6.2 lib/orange-more/blog/cartons/blog_post.rb
orange-more-0.6.0 lib/orange-more/blog/cartons/blog_post.rb