Sha256: eb1f3bb80273402b03208105ef1d2996f6d8242a10ee3b8db1c133d9a7a73111

Contents?: true

Size: 1.5 KB

Versions: 6

Compression:

Stored size: 1.5 KB

Contents

require 'mime/types'
require 'mini_magick'

module Redactor3Rails
  module Backend
    module CarrierWave
      def self.included(base)
        base.send(:include, InstanceMethods)
        base.send(:extend, ClassMethods)
      end

      module ClassMethods
        def self.extended(base)
          base.class_eval do
            process :extract_content_type
            process :set_size
          end
        end
      end

      module InstanceMethods
        # process :strip
        def strip
          manipulate! do |img|
            img.strip
            img = yield(img) if block_given?
            img
          end
        end

        # process :quality => 85
        def quality(percentage)
          manipulate! do |img|
            img.quality(percentage)
            img = yield(img) if block_given?
            img
          end
        end

        def extract_content_type
          if file.content_type == 'application/octet-stream' || file.content_type.blank?
            content_type = MIME::Types.type_for(original_filename).first
          else
            content_type = file.content_type
          end

          model.data_content_type = content_type.to_s
        end

        def set_size
          model.data_file_size = file.size
        end

        def read_dimensions
          if model.image? && model.has_dimensions?
            magick = ::MiniMagick::Image.new(current_path)
            model.width, model.height = magick[:width], magick[:height]
          end
        end

      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
redactor3_rails-0.1.5 lib/redactor3_rails/backend/carrierwave.rb
redactor3_rails-0.1.4 lib/redactor3_rails/backend/carrierwave.rb
redactor3_rails-0.1.3 lib/redactor3_rails/backend/carrierwave.rb
redactor3_rails-0.1.2 lib/redactor3_rails/backend/carrierwave.rb
redactor3_rails-0.1.1 lib/redactor3_rails/backend/carrierwave.rb
redactor3_rails-0.1.0 lib/redactor3_rails/backend/carrierwave.rb