Class: Decidim::ImageUploader

Inherits:
ApplicationUploader show all
Defined in:
app/uploaders/decidim/image_uploader.rb

Overview

This class deals with uploading hero images to ParticipatoryProcesses.

Instance Attribute Summary

Attributes inherited from ApplicationUploader

#content_type_denylist, #model, #mounted_as

Instance Method Summary collapse

Methods inherited from ApplicationUploader

#attached?, #initialize, #path, #protocol_option, #remote_url=, set_variants, #store_dir, #url, #variant, #variant_path, #variant_url, variants

Constructor Details

This class inherits a constructor from Decidim::ApplicationUploader

Instance Method Details

#content_type_allowlistObject



10
11
12
# File 'app/uploaders/decidim/image_uploader.rb', line 10

def content_type_allowlist
  extension_allowlist.map { |ext| "image/#{ext}" }
end

#dimensions_infoObject

Fetches info about different variants, their processors and dimensions



15
16
17
18
19
20
21
22
23
24
# File 'app/uploaders/decidim/image_uploader.rb', line 15

def dimensions_info
  return if variants.blank?

  variants.transform_values do |variant|
    {
      processor: variant.keys.first,
      dimensions: variant.values.first
    }
  end
end

#extension_allowlistObject

Add a white list of extensions which are allowed to be uploaded. For images you might use something like this:



28
29
30
# File 'app/uploaders/decidim/image_uploader.rb', line 28

def extension_allowlist
  Decidim.organization_settings(model).upload_allowed_file_extensions_image
end

#max_image_height_or_widthObject



32
33
34
# File 'app/uploaders/decidim/image_uploader.rb', line 32

def max_image_height_or_width
  3840
end

#validable_dimensionsObject



6
7
8
# File 'app/uploaders/decidim/image_uploader.rb', line 6

def validable_dimensions
  true
end