Class: Decidim::Cw::NewsletterTemplateImageUploader

Inherits:
ImageUploader show all
Defined in:
app/uploaders/decidim/cw/newsletter_template_image_uploader.rb

Overview

This class deals with uploading images to newsletters.

Instance Attribute Summary

Attributes inherited from ApplicationUploader

#validable_dimensions

Instance Method Summary collapse

Methods inherited from ImageUploader

#content_type_allowlist, #dimensions_info, #extension_allowlist, #strip, #validable_dimensions, #validate_dimensions, #validate_size

Methods inherited from ApplicationUploader

#downloader, #provider, set_variants, #store_dir, #variant, variants

Instance Method Details

#in_preview?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/uploaders/decidim/cw/newsletter_template_image_uploader.rb', line 34

def in_preview?
  model.content_block.in_preview
end

#max_image_height_or_widthObject



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

def max_image_height_or_width
  8000
end

#preview_url(*_args) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'app/uploaders/decidim/cw/newsletter_template_image_uploader.rb', line 22

def preview_url(*_args)
  manifest_images = model.content_block.manifest.images
  image = manifest_images.find { |manifest_image| manifest_image[:name] == mounted_as } || {}
  preview = image[:preview]

  if preview && preview.respond_to?(:call)
    preview.call
  else
    preview
  end
end

#url(*args) ⇒ Object

Overwrite: If the content block is in preview mode, then we show the preview image. Otherwise, we use the default behavior.



16
17
18
19
20
# File 'app/uploaders/decidim/cw/newsletter_template_image_uploader.rb', line 16

def url(*args)
  return preview_url if in_preview?

  super
end