Class: Hyrax::IiifManifestPresenter
- Inherits:
-
Draper::Decorator
- Object
- Draper::Decorator
- Hyrax::IiifManifestPresenter
show all
- Defined in:
- app/presenters/hyrax/iiif_manifest_presenter.rb
Overview
This presenter wraps objects in the interface required by IIIFManifiest.
It will accept either a Work-like resource or a SolrDocument.
Defined Under Namespace
Classes: DisplayImagePresenter, Factory, NullAbility
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#ability ⇒ #can?
40
41
42
|
# File 'app/presenters/hyrax/iiif_manifest_presenter.rb', line 40
def ability
@ability ||= NullAbility.new
end
|
#hostname ⇒ String
52
53
54
|
# File 'app/presenters/hyrax/iiif_manifest_presenter.rb', line 52
def hostname
@hostname || 'localhost'
end
|
Instance Method Details
#description ⇒ String
46
47
48
|
# File 'app/presenters/hyrax/iiif_manifest_presenter.rb', line 46
def description
Array(super).first || ''
end
|
65
66
67
|
# File 'app/presenters/hyrax/iiif_manifest_presenter.rb', line 65
def file_set_presenters
member_presenters.select { |p| p.file_set? && (p.display_image || p.display_content) }
end
|
#homepage ⇒ Array<Hash{String => String}>
138
139
140
141
142
143
144
145
|
# File 'app/presenters/hyrax/iiif_manifest_presenter.rb', line 138
def homepage
[{
'id' => Rails.application.routes.url_helpers.polymorphic_url(model, host: hostname),
'type' => 'Text',
'format' => 'text/html',
'label' => { 'none' => [Array(title).first || ''] }
}]
end
|
TODO:
should this use the simple_form i18n keys?! maybe the manifest
needs its own?
IIIF metadata for inclusion in the manifest
Called by the iiif_manifest gem to add metadata
77
78
79
80
81
82
83
84
|
# File 'app/presenters/hyrax/iiif_manifest_presenter.rb', line 77
def manifest_metadata
metadata_fields.map do |field_name|
{
'label' => I18n.t("simple_form.labels.defaults.#{field_name}"),
'value' => Array(send(field_name)).map { |value| scrub(value.to_s) }
}
end
end
|
#manifest_url ⇒ String
Returns the URL where the manifest can be found.
88
89
90
91
92
|
# File 'app/presenters/hyrax/iiif_manifest_presenter.rb', line 88
def manifest_url
return '' if id.blank?
Rails.application.routes.url_helpers.polymorphic_url([:manifest, model], host: hostname)
end
|
#member_ids ⇒ Array<#to_s>
96
97
98
99
|
# File 'app/presenters/hyrax/iiif_manifest_presenter.rb', line 96
def member_ids
m = model.is_a?(::SolrDocument) ? model.hydra_model : model.class
m < Hyrax::Resource ? Array(model.member_ids) : Hyrax::SolrDocument::OrderedMembers.decorate(model).ordered_member_ids
end
|
Note:
cache member presenters to avoid querying repeatedly; we expect this
presenter to live only as long as the request.
Note:
skips presenters for objects the current @ability cannot read.
the default ability has all permissions.
109
110
111
112
113
114
115
116
117
|
# File 'app/presenters/hyrax/iiif_manifest_presenter.rb', line 109
def member_presenters
@member_presenters_cache ||= Factory.build_for(ids: member_ids, presenter_class: self.class).map do |presenter|
next unless ability.can?(:read, presenter.model)
presenter.hostname = hostname
presenter.ability = ability
presenter
end.compact
end
|
#sequence_rendering ⇒ Array<Hash{String => String}>
121
122
123
124
125
126
127
128
129
130
|
# File 'app/presenters/hyrax/iiif_manifest_presenter.rb', line 121
def sequence_rendering
Array(try(:rendering_ids)).filter_map do |file_set_id|
rendering = member_presenters.find { |p| p.file_set? && p.id == file_set_id }
next unless rendering
{ '@id' => Hyrax::Engine.routes.url_helpers.download_url(rendering.id, host: hostname),
'format' => rendering.mime_type.presence || I18n.t("hyrax.manifest.unknown_mime_text"),
'label' => I18n.t("hyrax.manifest.download_text") + (rendering.label || '') }
end
end
|
#version ⇒ String
Note:
ideally, this value will be cheap to retrieve, and will reliably
change any time the manifest JSON will change. the current implementation
is more blunt than this, changing only when the work itself changes.
Returns a string tag suitable for cache keys for this manifiest.
165
166
167
|
# File 'app/presenters/hyrax/iiif_manifest_presenter.rb', line 165
def version
object.try(:modified_date)&.to_s || ''
end
|
#work? ⇒ Boolean
149
150
151
|
# File 'app/presenters/hyrax/iiif_manifest_presenter.rb', line 149
def work?
object.try(:work?) || !file_set?
end
|
155
156
157
|
# File 'app/presenters/hyrax/iiif_manifest_presenter.rb', line 155
def work_presenters
member_presenters.select(&:work?)
end
|