Sha256: a6b46049ef4e23d4e1d6ed7901c4c72a16b8f9868a4bc143dafa9ba9a37a4ff0

Contents?: true

Size: 1.94 KB

Versions: 11

Compression:

Stored size: 1.94 KB

Contents

module Locomotive
  module CarrierWave
    module Uploader
      module Asset

        extend ActiveSupport::Concern

        included do

          process :set_content_type
          process :set_size
          process :set_width_and_height

        end

        module ClassMethods

          def content_types
            {
              :image      => ['image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png', 'image/jpg', 'image/x-icon'],
              :media      => [/^video/, 'application/x-shockwave-flash', 'application/x-flash-video', 'application/x-swf', /^audio/, 'application/ogg', 'application/x-mp3'],
              :pdf        => ['application/pdf', 'application/x-pdf'],
              :stylesheet => ['text/css'],
              :javascript => ['text/javascript', 'text/js', 'application/x-javascript', 'application/javascript', 'text/x-component'],
              :font       => ['application/x-font-ttf', 'application/vnd.ms-fontobject', 'image/svg+xml', 'application/x-woff']
            }
          end

        end

        def set_content_type(*args)
          value = :other

          content_type = file.content_type == 'application/octet-stream' ? File.mime_type?(original_filename) : file.content_type

          self.class.content_types.each_pair do |type, rules|
            rules.each do |rule|
              case rule
              when String then value = type if content_type == rule
              when Regexp then value = type if (content_type =~ rule) == 0
              end
            end
          end

          model.content_type = value
        end

        def set_size(*args)
          model.size = file.size
        end

        def set_width_and_height
          if model.image?
            magick = ::Magick::Image.read(current_path).first
            model.width, model.height = magick.columns, magick.rows
          end
        end

        def image?(file)
          model.image?
        end

      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
locomotive_cms-2.0.0.rc12 lib/locomotive/carrierwave/asset.rb
locomotive_cms-2.0.0.rc11 lib/locomotive/carrierwave/asset.rb
locomotive_cms-2.0.0.rc10 lib/locomotive/carrierwave/asset.rb
locomotive_cms-2.0.0.rc9 lib/locomotive/carrierwave/asset.rb
locomotive_cms-2.0.0.rc8 lib/locomotive/carrierwave/asset.rb
locomotive_cms-2.0.0.rc7 lib/locomotive/carrierwave/asset.rb
locomotive_cms-2.0.0.rc6 lib/locomotive/carrierwave/asset.rb
locomotive_cms-2.0.0.rc5 lib/locomotive/carrierwave/asset.rb
locomotive_cms-2.0.0.rc4 lib/locomotive/carrierwave/asset.rb
locomotive_cms-2.0.0.rc2 lib/locomotive/carrierwave/asset.rb
locomotive_cms-2.0.0.rc1 lib/locomotive/carrierwave/asset.rb