demarches-normaliennes/app/helpers/gallery_helper.rb

38 lines
1.1 KiB
Ruby
Raw Permalink Normal View History

# frozen_string_literal: true
2024-05-29 10:54:38 +02:00
module GalleryHelper
def displayable_pdf?(blob)
blob.content_type.in?(AUTHORIZED_PDF_TYPES)
2024-05-29 10:54:38 +02:00
end
def displayable_image?(blob)
blob.variable? && blob.content_type.in?(AUTHORIZED_IMAGE_TYPES)
end
def representation_url_for(attachment)
return variant_url_for(attachment) if displayable_image?(attachment.blob)
preview_url_for(attachment) if displayable_pdf?(attachment.blob)
end
2024-05-29 10:54:38 +02:00
def preview_url_for(attachment)
attachment.blob.preview_image.url.presence || 'pdf-placeholder.png'
2024-06-10 11:29:50 +02:00
rescue StandardError
'pdf-placeholder.png'
2024-05-29 10:54:38 +02:00
end
def variant_url_for(attachment)
variant = attachment.variant(resize_to_limit: [400, 400])
variant.key.present? ? variant.processed.url : 'apercu-indisponible.png'
2024-06-10 11:29:50 +02:00
rescue StandardError
'apercu-indisponible.png'
2024-05-29 10:54:38 +02:00
end
def blob_url(attachment)
variant = attachment.variant(resize_to_limit: [2000, 2000])
attachment.blob.content_type.in?(RARE_IMAGE_TYPES) && variant.key.present? ? variant.processed.url : attachment.blob.url
2024-06-10 11:29:50 +02:00
rescue StandardError
attachment.blob.url
2024-05-29 10:54:38 +02:00
end
end