Class: Geoblacklight::DownloadLinksComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/geoblacklight/download_links_component.rb

Overview

Display expandable file download links in sidebar

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document:) ⇒ DownloadLinksComponent

Returns a new instance of DownloadLinksComponent.



8
9
10
11
# File 'app/components/geoblacklight/download_links_component.rb', line 8

def initialize(document:)
  @document = document
  super()
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



6
7
8
# File 'app/components/geoblacklight/download_links_component.rb', line 6

def document
  @document
end

Instance Method Details



21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/components/geoblacklight/download_links_component.rb', line 21

def download_link_file(label, id, url)
  link_to(
    label,
    url,
    "contentUrl" => url,
    :data => {
      download: "trigger",
      download_type: "direct",
      download_id: id
    }
  )
end


47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/components/geoblacklight/download_links_component.rb', line 47

def download_link_generated(download_type, document)
  link_to(
    t("geoblacklight.download.export_link", download_format: export_format_label(download_type)),
    "",
    data: {
      download_path: download_path(document.id, type: download_type),
      download: "trigger",
      action: "downloads#download:once",
      download_type: download_type,
      download_id: document.id
    }
  )
end

Generates the link markup for the IIIF JPEG download

Returns:

  • (String)


36
37
38
39
40
41
42
43
44
45
# File 'app/components/geoblacklight/download_links_component.rb', line 36

def download_link_iiif
  link_to(
    download_text("JPG"),
    iiif_jpg_url,
    "contentUrl" => iiif_jpg_url,
    :data => {
      download: "trigger"
    }
  )
end

#download_text(format) ⇒ Object

Wraps download text with proper_case_format



64
65
66
67
68
# File 'app/components/geoblacklight/download_links_component.rb', line 64

def download_text(format)
  download_format = proper_case_format(format)
  value = t("geoblacklight.download.download_link", download_format: download_format)
  value.html_safe
end

#downloadable?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'app/components/geoblacklight/download_links_component.rb', line 17

def downloadable?
  helpers.document_available? && @document.downloadable?
end

#export_format_label(format) ⇒ Object

Format labels are customized for exports - look up the appropriate key.



71
72
73
# File 'app/components/geoblacklight/download_links_component.rb', line 71

def export_format_label(format)
  t("geoblacklight.download.export_#{format.to_s.parameterize(separator: "_")}_link")
end

#iiif_jpg_urlObject



80
81
82
# File 'app/components/geoblacklight/download_links_component.rb', line 80

def iiif_jpg_url
  @document.references.iiif.endpoint.sub! "info.json", "full/full/0/default.jpg"
end

#proper_case_format(format) ⇒ Object

Looks up properly formatted names for formats



76
77
78
# File 'app/components/geoblacklight/download_links_component.rb', line 76

def proper_case_format(format)
  t("geoblacklight.formats.#{format.to_s.parameterize(separator: "_")}")
end

#render?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'app/components/geoblacklight/download_links_component.rb', line 13

def render?
  downloadable? && (document.direct_download.present? || document.iiif_download.present? || document.download_types.present?)
end