refactor(gallery): extract gallery_link method
This commit is contained in:
parent
2882af43aa
commit
664ef63e74
2 changed files with 14 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -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 }
|
||||
|
|
Loading…
Reference in a new issue