From 664ef63e74b4793bb9f225288bfc30ab4c77205d Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Mon, 9 Sep 2024 09:48:45 +0200 Subject: [PATCH] refactor(gallery): extract gallery_link method --- .../attachment/gallery_item_component.rb | 12 ++++++++++++ .../gallery_item_component.html.haml | 14 ++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/app/components/attachment/gallery_item_component.rb b/app/components/attachment/gallery_item_component.rb index e32ae942f..0de346602 100644 --- a/app/components/attachment/gallery_item_component.rb +++ b/app/components/attachment/gallery_item_component.rb @@ -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 diff --git a/app/components/attachment/gallery_item_component/gallery_item_component.html.haml b/app/components/attachment/gallery_item_component/gallery_item_component.html.haml index d59ade805..50aeecd71 100644 --- a/app/components/attachment/gallery_item_component/gallery_item_component.html.haml +++ b/app/components/attachment/gallery_item_component/gallery_item_component.html.haml @@ -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 }