Sha256: f156e3e3ebabd89e6ad82249b7ef80e2b940b1f120ae33c76e9cdcde63fe6248

Contents?: true

Size: 1.76 KB

Versions: 6

Compression:

Stored size: 1.76 KB

Contents

module Fuel
  class Post < ActiveRecord::Base
    include ActionView::Helpers::OutputSafetyHelper

    extend FriendlyId
    friendly_id :title, use: :slugged

    belongs_to :author

    if Rails.version[0].to_i < 4
      attr_accessible :tag, :author_id, :content, :title, :teaser, :featured_image, :seo_title, :seo_description, :published_at
    end

    has_attached_file :featured_image, :styles => { :medium => Fuel.configuration.featured_image_settings[:styles][:medium], :thumb => Fuel.configuration.featured_image_settings[:styles][:thumb] }, :default_url => "fuel/default-img.jpg"
    validates_attachment_content_type :featured_image, :content_type => /\Aimage\/.*\Z/

    validates_presence_of :title, :content, :author_id, if: :is_published
    paginates_per Fuel.configuration.paginates_per.to_i

    scope :recent_published_posts, -> { where(published: true).order("created_at DESC") }
    scope :recent, -> { order("created_at DESC") }

    def next
      self.class.recent.where("created_at <= ? AND id != ?", created_at, id).first
    end

    def previous
      self.class.recent.where("created_at >= ? AND id != ?", created_at, id).last
    end

    def should_generate_new_friendly_id?
      new_record? #Don't generate new id on edit
    end

    def save_as_draft
      self.published = false
    end

    def is_published
      self.published
    end

    def prioritized_featured_image_url(type = :original)
      featured_image_file_name.present? ? featured_image.url(type) : featured_image_url
    end

    def teaser_content
      teaser.present? ? teaser : content
    end

    def to_html
      markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,
          :autolink => true, :space_after_headers => true)
      raw markdown.render(content)
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fuel-0.3.26 app/models/fuel/post.rb
fuel-0.3.25 app/models/fuel/post.rb
fuel-0.3.24 app/models/fuel/post.rb
fuel-0.3.23 app/models/fuel/post.rb
fuel-0.3.22 app/models/fuel/post.rb
fuel-0.3.21 app/models/fuel/post.rb