2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-11-09 12:33:20 +01:00
|
|
|
class Dsfr::DownloadComponent < ApplicationComponent
|
|
|
|
attr_reader :attachment
|
|
|
|
attr_reader :html_class
|
|
|
|
attr_reader :name
|
2023-06-05 14:25:51 +02:00
|
|
|
attr_reader :ephemeral_link
|
2023-06-05 17:37:52 +02:00
|
|
|
attr_reader :virus_not_analyzed
|
2022-12-05 15:59:50 +01:00
|
|
|
attr_reader :new_tab
|
2024-04-08 10:13:05 +02:00
|
|
|
attr_reader :truncate
|
2022-11-09 12:33:20 +01:00
|
|
|
|
2024-04-08 10:13:05 +02:00
|
|
|
def initialize(attachment:, name: nil, url: nil, ephemeral_link: false, virus_not_analyzed: false, new_tab: false, truncate: false)
|
2022-11-09 12:33:20 +01:00
|
|
|
@attachment = attachment
|
|
|
|
@name = name || attachment.filename.to_s
|
2022-12-01 17:57:53 +01:00
|
|
|
@url = url
|
2023-06-05 14:25:51 +02:00
|
|
|
@ephemeral_link = ephemeral_link
|
2023-06-05 17:37:52 +02:00
|
|
|
@virus_not_analyzed = virus_not_analyzed
|
2022-12-05 15:59:50 +01:00
|
|
|
@new_tab = new_tab
|
2024-04-08 10:13:05 +02:00
|
|
|
@truncate = truncate
|
2022-11-09 12:33:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def title
|
2022-11-22 19:25:45 +01:00
|
|
|
t(".title", filename: attachment.filename.to_s)
|
2022-11-09 12:33:20 +01:00
|
|
|
end
|
2022-12-01 17:57:53 +01:00
|
|
|
|
|
|
|
def url
|
|
|
|
return @url if @url.present?
|
|
|
|
|
|
|
|
helpers.url_for(@attachment.blob)
|
|
|
|
end
|
2022-11-09 12:33:20 +01:00
|
|
|
end
|