Sha256: 1d116d3b2a59cc58e9857df37e84128584a10b95cb505704fd4e94a71e04dd9a

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

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

    attr_accessible :alternate_text, :asset_id, :height, :html_attributes, :image_scaling, :link_url, :width, :content

    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.0.3 app/models/smithy/image.rb
smithycms-0.0.2 app/models/smithy/image.rb
smithycms-0.0.1 app/models/smithy/image.rb