refactor(gallery): extract gallery_link method

This commit is contained in:
Eric Leroy-Terquem 2024-09-09 09:48:45 +02:00
parent 2882af43aa
commit 664ef63e74
No known key found for this signature in database
GPG key ID: 53D8FAECEF207605
2 changed files with 14 additions and 12 deletions

View file

@ -19,4 +19,16 @@ class Attachment::GalleryItemComponent < ApplicationComponent
def title
"#{libelle} -- #{sanitize(blob.filename.to_s)}"
end
def gallery_link(blob, &block)
if displayable_image?(blob)
link_to image_url(blob_url(attachment)), title: title, data: { src: blob.url }, class: 'gallery-link' do
yield
end
elsif displayable_pdf?(blob)
link_to blob.url, id: blob.id, data: { iframe: true, src: blob.url }, class: 'gallery-link', type: blob.content_type, title: title do
yield
end
end
end
end

View file

@ -1,16 +1,6 @@
.gallery-item
- if displayable_pdf?(blob)
= link_to blob.url, id: blob.id, data: { iframe: true, src: blob.url }, class: 'gallery-link', type: blob.content_type, title: title do
.thumbnail
= image_tag(representation_url_for(attachment), loading: :lazy)
.fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button }
Visualiser
.champ-libelle
= libelle.truncate(25)
= render Attachment::ShowComponent.new(attachment: attachment, truncate: true)
- elsif displayable_image?(blob)
= link_to image_url(blob_url(attachment)), title: title, data: { src: blob.url }, class: 'gallery-link' do
- if displayable_pdf?(blob) || displayable_image?(blob)
= gallery_link(blob) do
.thumbnail
= image_tag(representation_url_for(attachment), loading: :lazy)
.fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button }