Sha256: 2aa22a5af6ef07a81ea299ce29b46eacfe583779daf35c9030720f00dfd0829a

Contents?: true

Size: 1.5 KB

Versions: 33

Compression:

Stored size: 1.5 KB

Contents

require 'mime/types'
require 'mini_magick'

module RedactorRails
  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

33 entries across 33 versions & 6 rubygems

Version Path
redactor-rails-fixes-0.5.0.1 lib/redactor-rails/backend/carrierwave.rb
rdrails5-0.5.1 lib/redactor-rails/backend/carrierwave.rb
redactor-rails4-0.5.0 lib/redactor-rails/backend/carrierwave.rb
redactor-rails-0.5.0 lib/redactor-rails/backend/carrierwave.rb
redactor-rails-0.4.5 lib/redactor-rails/backend/carrierwave.rb
redactor-rails-0.4.4 lib/redactor-rails/backend/carrierwave.rb
th_simple_content_management-0.2.7 lib/redactor-rails/backend/carrierwave.rb
th_simple_content_management-0.2.6 lib/redactor-rails/backend/carrierwave.rb
th_simple_content_management-0.2.5 lib/redactor-rails/backend/carrierwave.rb
th_simple_content_management-0.2.4 lib/redactor-rails/backend/carrierwave.rb
th_simple_content_management-0.2.3 lib/redactor-rails/backend/carrierwave.rb
redactor-rails-0.4.3 lib/redactor-rails/backend/carrierwave.rb
redactor-rails-0.4.2 lib/redactor-rails/backend/carrierwave.rb
redactor-rails-0.4.1 lib/redactor-rails/backend/carrierwave.rb
redactor-rails-0.3.7 lib/redactor-rails/backend/carrierwave.rb
redactor-rails-0.3.6 lib/redactor-rails/backend/carrierwave.rb
redactor-rails-0.4 lib/redactor-rails/backend/carrierwave.rb
th_simple_content_management-0.2.2 lib/redactor-rails/backend/carrierwave.rb
redactor-rails-paperclip-0.4.3 lib/redactor-rails/backend/carrierwave.rb
redactor-rails-paperclip-0.4.2.1 lib/redactor-rails/backend/carrierwave.rb