app/models/spud_post.rb in spud_blog-0.9.11 vs app/models/spud_post.rb in spud_blog-1.0.0.rc1

- old
+ new

@@ -5,25 +5,24 @@ :class_name => 'SpudPostCategory', :join_table => 'spud_post_categories_posts', :foreign_key => 'spud_post_id' belongs_to :author, :class_name => 'SpudUser', :foreign_key => 'spud_user_id' has_many :comments, :class_name => 'SpudPostComment' - has_many :visible_comments, :class_name => 'SpudPostComment',:conditions => {:spam => [nil,false]} - has_many :spam_comments, :class_name => "SpudPostComment", :conditions => {:spam => true} + has_many :visible_comments, -> { where spam: [nil,false]}, :class_name => 'SpudPostComment' + has_many :spam_comments, -> { where spam: true }, :class_name => "SpudPostComment" has_many :spud_permalinks,:as => :attachment has_many :spud_post_sites, :dependent => :destroy - scope :publicly, where('visible = true AND published_at <= ?', Time.now.utc).order('published_at desc') - scope :future_posts, where('visible = true AND published_at > ?', Time.now.utc) + scope :publicly, -> { where('visible = true AND published_at <= ?', Time.now.utc).order('published_at desc') } + scope :future_posts, -> { where('visible = true AND published_at > ?', Time.now.utc) } validates_presence_of :title, :content, :published_at, :spud_user_id, :url_name validates_uniqueness_of :url_name before_validation :set_url_name before_save :postprocess_content after_save :set_spud_site_ids - attr_accessible :is_news,:published_at,:title,:content,:spud_user_id,:url_name,:visible,:comments_enabled,:meta_keywords,:meta_description,:category_ids, :spud_site_ids, :content_format attr_accessor :spud_site_ids def self.for_spud_site(spud_site_id) return joins(:spud_post_sites).where(:spud_post_sites => {:spud_site_id => spud_site_id}) end @@ -99,15 +98,13 @@ logger.fatal "Exception occurred while fetching post archive dates:\n #{e.to_s}" end end def postprocess_content - if self.content_format == 'Markdown' - require 'redcarpet' - renderer = Redcarpet::Render::HTML.new - extensions = {fenced_code_blocks: true} - redcarpet = Redcarpet::Markdown.new(renderer, extensions) - self.content_processed = redcarpet.render self.content + rendererClass = Spud::Core.renderer(self.content_format) + if rendererClass + renderer = rendererClass.new() + self.content_processed = renderer.render self.content else self.content_processed = content end end