Class: ActiveadminSettings::RedactorPictureUploader
- Inherits:
-
CarrierWave::Uploader::Base
- Object
- CarrierWave::Uploader::Base
- ActiveadminSettings::RedactorPictureUploader
- Includes:
- CarrierWave::MiniMagick
- Defined in:
- app/uploaders/activeadmin_settings/redactor_picture_uploader.rb
Class Method Summary collapse
-
.extended(base) ⇒ Object
Class.
Instance Method Summary collapse
-
#extension_white_list ⇒ Object
Add a white list of extensions which are allowed to be uploaded.
- #extract_content_type ⇒ Object
-
#quality(percentage) ⇒ Object
process :quality => 85.
- #read_dimensions ⇒ Object
- #set_size ⇒ Object
-
#store_dir ⇒ Object
Override the directory where uploaded files will be stored.
-
#strip ⇒ Object
Instance.
Class Method Details
.extended(base) ⇒ Object
Class
91 92 93 94 95 96 |
# File 'app/uploaders/activeadmin_settings/redactor_picture_uploader.rb', line 91 def self.extended(base) base.class_eval do process :extract_content_type process :set_size end end |
Instance Method Details
#extension_white_list ⇒ Object
Add a white list of extensions which are allowed to be uploaded. For images you might use something like this:
79 80 81 |
# File 'app/uploaders/activeadmin_settings/redactor_picture_uploader.rb', line 79 def extension_white_list ActiveadminSettings.image_file_types end |
#extract_content_type ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'app/uploaders/activeadmin_settings/redactor_picture_uploader.rb', line 27 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 |
#quality(percentage) ⇒ Object
process :quality => 85
19 20 21 22 23 24 25 |
# File 'app/uploaders/activeadmin_settings/redactor_picture_uploader.rb', line 19 def quality(percentage) manipulate! do |img| img.quality(percentage) img = yield(img) if block_given? img end end |
#read_dimensions ⇒ Object
41 42 43 44 45 46 |
# File 'app/uploaders/activeadmin_settings/redactor_picture_uploader.rb', line 41 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 |
#set_size ⇒ Object
37 38 39 |
# File 'app/uploaders/activeadmin_settings/redactor_picture_uploader.rb', line 37 def set_size model.data_file_size = file.size end |
#store_dir ⇒ Object
Override the directory where uploaded files will be stored. This is a sensible default for uploaders that are meant to be mounted:
50 51 52 |
# File 'app/uploaders/activeadmin_settings/redactor_picture_uploader.rb', line 50 def store_dir "system/settings/redactor/pictures/#{model.id}" end |
#strip ⇒ Object
Instance
10 11 12 13 14 15 16 |
# File 'app/uploaders/activeadmin_settings/redactor_picture_uploader.rb', line 10 def strip manipulate! do |img| img.strip img = yield(img) if block_given? img end end |