lib/schnitzelpress/post.rb in schnitzelpress-0.0.5 vs lib/schnitzelpress/post.rb in schnitzelpress-0.0.6
- old
+ new
@@ -6,10 +6,19 @@
include Redcarpet::Render::SmartyPants
def block_code(code, language)
CodeRay.highlight(code, language)
end
+
+ def autolink(link, type)
+ if link =~ %r{youtube.com\/watch\?v=(.+)$}
+ youtube_id = $1
+ %q(<iframe width="600" height="335" src="http://www.youtube.com/embed/%s"></iframe>) % youtube_id
+ else
+ %q(<a href="%s">%s</a>) % [link, link]
+ end
+ end
end
class Post
include Mongoid::Document
store_in :posts
@@ -37,11 +46,11 @@
validates_presence_of :status, :slug
validates_inclusion_of :status, in: [:draft, :published]
scope :published, where(:status => :published)
scope :drafts, where(:status => :draft)
- scope :pages, where(:published_at.exists => false)
- scope :posts, where(:published_at.exists => true)
+ 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)) }