Class: Arclight::DocumentDownloadComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/arclight/document_download_component.rb

Overview

ViewComponent for rendering a single document download link

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(downloads:, **kwargs) ⇒ DocumentDownloadComponent

Returns a new instance of DocumentDownloadComponent.



6
7
8
9
10
11
# File 'app/components/arclight/document_download_component.rb', line 6

def initialize(downloads:, **kwargs)
  super

  @downloads = downloads
  @link_options = kwargs
end

Instance Attribute Details

#downloadsObject (readonly)

Returns the value of attribute downloads.



13
14
15
# File 'app/components/arclight/document_download_component.rb', line 13

def downloads
  @downloads
end

Instance Method Details

#download_iconObject



34
35
36
37
38
39
40
41
42
# File 'app/components/arclight/document_download_component.rb', line 34

def download_icon
  icon = <<~HTML
    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-download" viewBox="0 0 16 16">
      <path d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z"/>
      <path d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3z"/>
    </svg>
  HTML
  icon.html_safe # rubocop:disable Rails/OutputSafety
end

i18n-tasks-use t(‘arclight.views.show.download.multiple.pdf’) i18n-tasks-use t(‘arclight.views.show.download.multiple.ead’)



23
24
25
# File 'app/components/arclight/document_download_component.rb', line 23

def dropdown_label(file)
  t(file.type, scope: 'arclight.views.show.download.multiple')
end

#ead_iconObject



61
62
63
64
65
66
67
68
69
# File 'app/components/arclight/document_download_component.rb', line 61

def ead_icon
  icon = <<~HTML
    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-file-earmark-code" viewBox="0 0 16 16">
      <path d="M14 4.5V14a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2h5.5L14 4.5zm-3 0A1.5 1.5 0 0 1 9.5 3V1H4a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V4.5h-2z"/>
      <path d="M8.646 6.646a.5.5 0 0 1 .708 0l2 2a.5.5 0 0 1 0 .708l-2 2a.5.5 0 0 1-.708-.708L10.293 9 8.646 7.354a.5.5 0 0 1 0-.708zm-1.292 0a.5.5 0 0 0-.708 0l-2 2a.5.5 0 0 0 0 .708l2 2a.5.5 0 0 0 .708-.708L5.707 9l1.647-1.646a.5.5 0 0 0 0-.708z"/>
    </svg>
  HTML
  icon.html_safe # rubocop:disable Rails/OutputSafety
end

#icon_for(type) ⇒ Object

This is an extension point where one could configure a different icon per file type



45
46
47
# File 'app/components/arclight/document_download_component.rb', line 45

def icon_for(type)
  public_send("#{type}_icon")
end

#label(file) ⇒ Object

i18n-tasks-use t(‘arclight.views.show.download.single.pdf’) i18n-tasks-use t(‘arclight.views.show.download.single.ead’)



29
30
31
# File 'app/components/arclight/document_download_component.rb', line 29

def label(file)
  t(file.type, scope: 'arclight.views.show.download.single')
end

#pdf_iconObject



50
51
52
53
54
55
56
57
58
# File 'app/components/arclight/document_download_component.rb', line 50

def pdf_icon
  icon = <<~HTML
    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-file-earmark-pdf" viewBox="0 0 16 16">
      <path d="M14 14V4.5L9.5 0H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2zM9.5 3A1.5 1.5 0 0 0 11 4.5h2V14a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.5v2z"/>
      <path d="M4.603 14.087a.81.81 0 0 1-.438-.42c-.195-.388-.13-.776.08-1.102.198-.307.526-.568.897-.787a7.68 7.68 0 0 1 1.482-.645 19.697 19.697 0 0 0 1.062-2.227 7.269 7.269 0 0 1-.43-1.295c-.086-.4-.119-.796-.046-1.136.075-.354.274-.672.65-.823.192-.077.4-.12.602-.077a.7.7 0 0 1 .477.365c.088.164.12.356.127.538.007.188-.012.396-.047.614-.084.51-.27 1.134-.52 1.794a10.954 10.954 0 0 0 .98 1.686 5.753 5.753 0 0 1 1.334.05c.364.066.734.195.96.465.12.144.193.32.2.518.007.192-.047.382-.138.563a1.04 1.04 0 0 1-.354.416.856.856 0 0 1-.51.138c-.331-.014-.654-.196-.933-.417a5.712 5.712 0 0 1-.911-.95 11.651 11.651 0 0 0-1.997.406 11.307 11.307 0 0 1-1.02 1.51c-.292.35-.609.656-.927.787a.793.793 0 0 1-.58.029zm1.379-1.901c-.166.076-.32.156-.459.238-.328.194-.541.383-.647.547-.094.145-.096.25-.04.361.01.022.02.036.026.044a.266.266 0 0 0 .035-.012c.137-.056.355-.235.635-.572a8.18 8.18 0 0 0 .45-.606zm1.64-1.33a12.71 12.71 0 0 1 1.01-.193 11.744 11.744 0 0 1-.51-.858 20.801 20.801 0 0 1-.5 1.05zm2.446.45c.15.163.296.3.435.41.24.19.407.253.498.256a.107.107 0 0 0 .07-.015.307.307 0 0 0 .094-.125.436.436 0 0 0 .059-.2.095.095 0 0 0-.026-.063c-.052-.062-.2-.152-.518-.209a3.876 3.876 0 0 0-.612-.053zM8.078 7.8a6.7 6.7 0 0 0 .2-.828c.031-.188.043-.343.038-.465a.613.613 0 0 0-.032-.198.517.517 0 0 0-.145.04c-.087.035-.158.106-.196.283-.04.192-.03.469.046.822.024.111.054.227.09.346z"/>
    </svg>
  HTML
  icon.html_safe # rubocop:disable Rails/OutputSafety
end

#render?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'app/components/arclight/document_download_component.rb', line 17

def render?
  files.present?
end