Sha256: d8594c0cbec7fd8b4bdba47f52406e425885f3b5296300b40c660fd3d48966f9

Contents?: true

Size: 931 Bytes

Versions: 3

Compression:

Stored size: 931 Bytes

Contents

module Smithy
  class Image < ActiveRecord::Base
    include Smithy::ContentBlocks::Model

    validates_presence_of :asset

    belongs_to :asset
    has_many :page_contents, :as => :content_block, :dependent => :destroy

    class << self
      def content_block_description
        "Images are primarily used for adding image-based content to your pages"
      end

      def image_scaling_options
        [
          ['Keep to Scale', ''],
          ['Force Exact Dimensions (this may crop the image)', '#']
        ]
      end
    end

    def formatted_content
      @formatted_content ||= markdown_formatter.render
    end

    def to_liquid
      attributes.tap do |a|
        a['asset'] = asset.to_liquid if asset.present?
        a['formatted_content'] = formatted_content
      end
    end

    private
      def markdown_formatter
        @markdown_formatter ||= Smithy::Formatter.new(self.content)
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
smithycms-0.4.2 app/models/smithy/image.rb
smithycms-0.4.1 app/models/smithy/image.rb
smithycms-0.4.0 app/models/smithy/image.rb