Sha256: 6b3e475e77e80c4a4d40186f2f334f4b8698ae29a17f64dfa17fa94fc7d23206

Contents?: true

Size: 1.62 KB

Versions: 15

Compression:

Stored size: 1.62 KB

Contents

module Spree
  class Image < Asset
    validates_attachment_presence :attachment
    validate :no_attachment_errors

    has_attached_file :attachment,
                      styles: { mini: '48x48>', small: '100x100>', product: '240x240>', large: '600x600>' },
                      default_style: :product,
                      url: '/spree/products/:id/:style/:basename.:extension',
                      path: ':rails_root/public/spree/products/:id/:style/:basename.:extension',
                      convert_options: { all: '-strip -auto-orient -colorspace sRGB' }

    # save the w,h of the original image (from which others can be calculated)
    # we need to look at the write-queue for images which have not been saved yet
    after_post_process :find_dimensions

    #used by admin products autocomplete
    def mini_url
      attachment.url(:mini, false)
    end

    def find_dimensions
      temporary = attachment.queued_for_write[:original]
      filename = temporary.path unless temporary.nil?
      filename = attachment.path if filename.blank?
      geometry = Paperclip::Geometry.from_file(filename)
      self.attachment_width  = geometry.width
      self.attachment_height = geometry.height
    end

    # if there are errors from the plugin, then add a more meaningful message
    def no_attachment_errors
      unless attachment.errors.empty?
        # uncomment this to get rid of the less-than-useful interrim messages
        # errors.clear
        errors.add :attachment, "Paperclip returned errors for file '#{attachment_file_name}' - check ImageMagick installation or image source file."
        false
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
spree_core-2.2.14 app/models/spree/image.rb
spree_core-2.2.13 app/models/spree/image.rb
spree_core-2.2.12 app/models/spree/image.rb
spree_core-2.2.11 app/models/spree/image.rb
spree_core-2.2.10 app/models/spree/image.rb
spree_core-2.2.9 app/models/spree/image.rb
spree_core-2.2.8 app/models/spree/image.rb
spree_core-2.2.7 app/models/spree/image.rb
spree_core-2.2.6 app/models/spree/image.rb
spree_core-2.2.5 app/models/spree/image.rb
spree_core-2.2.4 app/models/spree/image.rb
spree_core-2.2.3 app/models/spree/image.rb
spree_core-2.2.2 app/models/spree/image.rb
spree_core-2.2.1 app/models/spree/image.rb
spree_core-2.2.0 app/models/spree/image.rb