lib/schnitzelpress/post.rb in schnitzelpress-0.0.6 vs lib/schnitzelpress/post.rb in schnitzelpress-0.0.7

- old
+ new

@@ -1,26 +1,15 @@ require 'tilt' require 'coderay' +require 'oembed' -module SchnitzelPress - class MarkdownRenderer < Redcarpet::Render::HTML - include Redcarpet::Render::SmartyPants +OEmbed::Providers.register_all +SoundCloudProvider = OEmbed::Provider.new("http://soundcloud.com/oembed", :json) +SoundCloudProvider << "http://*.soundcloud.com/*" +OEmbed::Providers.register(SoundCloudProvider) - 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 - +module SchnitzelPress class Post include Mongoid::Document store_in :posts # basic data @@ -41,10 +30,16 @@ field :disqus, type: Boolean, default: false # extra 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] scope :published, where(:status => :published) scope :drafts, where(:status => :draft) @@ -85,11 +80,11 @@ slugs << v end end def set_defaults - if slug.blank? && title.present? - self.slug = title.parameterize + if slug.blank? + self.slug = (title || body.truncate(40, separator: ' ')).parameterize end end def validate_slug conflicting_posts = Post.where(slugs: slug)