lib/schnitzelpress/post.rb in schnitzelpress-0.0.11 vs lib/schnitzelpress/post.rb in schnitzelpress-0.0.12

- old
+ new

@@ -11,48 +11,48 @@ class Post include Mongoid::Document store_in :posts # basic data - field :title, type: String - field :body, type: String - field :slugs, type: Array, default: [] + field :title, :type => String + field :body, :type => String + field :slugs, :type => Array, :default => [] # optional fields - field :summary, type: String - field :link, type: String - field :read_more, type: String + field :summary, :type => String + field :link, :type => String + field :read_more, :type => String # times & status - field :published_at, type: DateTime - field :status, type: Symbol, default: :draft + field :published_at, :type => DateTime + field :status, :type => Symbol, :default => :draft # flags - field :disqus, type: Boolean, default: false + field :disqus, :type => Boolean, :default => false # extra - field :body_html, type: String + field :body_html, :type => String # indices index :slugs index :published_at index :status # validations validates_presence_of :status, :slug - validates_inclusion_of :status, in: [:draft, :published] + validates_inclusion_of :status, :in => [:draft, :published] scope :published, where(:status => :published) scope :drafts, where(:status => :draft) scope :pages, where(:published_at => nil) scope :posts, where(:published_at.ne => nil) - scope :article_posts, -> { posts.where(:link => nil) } - scope :link_posts, -> { posts.where(:link.ne => nil) } - scope :for_year, ->(year) { d = Date.new(year) ; where(published_at: (d.beginning_of_year)..(d.end_of_year)) } - scope :for_month, ->(year, month) { d = Date.new(year, month) ; where(published_at: (d.beginning_of_month)..(d.end_of_month)) } - scope :for_day, ->(year, month, day) { d = Date.new(year, month, day) ; where(published_at: (d.beginning_of_day)..(d.end_of_day)) } - scope :latest, -> { published.posts.desc(:published_at) } + scope :article_posts, lambda { posts.where(:link => nil) } + scope :link_posts, lambda { posts.where(:link.ne => nil) } + scope :for_year, lambda { |year| d = Date.new(year) ; where(:published_at => (d.beginning_of_year)..(d.end_of_year)) } + scope :for_month, lambda { |year, month| d = Date.new(year, month) ; where(:published_at => (d.beginning_of_month)..(d.end_of_month)) } + scope :for_day, lambda { |year, month, day| d = Date.new(year, month, day) ; where(:published_at => (d.beginning_of_day)..(d.end_of_day)) } + scope :latest, lambda { published.posts.desc(:published_at) } before_validation :nil_if_blank before_validation :set_defaults validate :validate_slug before_save :update_body_html @@ -81,16 +81,16 @@ end end def set_defaults if slug.blank? - self.slug = (title || body.truncate(40, separator: ' ')).parameterize + self.slug = (title || body.truncate(40, :separator => ' ')).parameterize end end def validate_slug - conflicting_posts = Post.where(slugs: slug) + conflicting_posts = Post.where(:slugs => slug) if published_at.present? conflicting_posts = conflicting_posts.for_day(published_at.year, published_at.month, published_at.day) end if conflicting_posts.any? && conflicting_posts.first != self @@ -118,10 +118,10 @@ body_html end def render @@markdown ||= Redcarpet::Markdown.new(MarkdownRenderer, - autolink: true, space_after_headers: true, fenced_code_blocks: true) + :autolink => true, :space_after_headers => true, :fenced_code_blocks => true) @@markdown.render(body) end def post?