Class: Hyrax::IiifManifestPresenter
- Inherits:
-
Draper::Decorator
- Object
- Draper::Decorator
- Hyrax::IiifManifestPresenter
- 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
- #ability ⇒ #can?
-
#hostname ⇒ Object
writeonly
Sets the attribute hostname.
Class Method Summary collapse
Instance Method Summary collapse
- #description ⇒ String
- #file_set? ⇒ Boolean
- #file_set_presenters ⇒ Array<DisplayImagePresenter>
-
#manifest_metadata ⇒ Array<Hash{String => String}>
IIIF metadata for inclusion in the manifest Called by the ‘iiif_manifest` gem to add metadata.
-
#manifest_url ⇒ String
The URL where the manifest can be found.
- #member_ids ⇒ Array<#to_s>
- #member_presenters ⇒ Array<IiifManifestPresenter>
- #sequence_rendering ⇒ Array<Hash{String => String}>
-
#version ⇒ String
A string tag suitable for cache keys for this manifiest.
- #work? ⇒ Boolean
- #work_presenters ⇒ Array<IiifManifestPresenter>
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=(value) ⇒ Object
Sets the attribute hostname
26 |
# File 'app/presenters/hyrax/iiif_manifest_presenter.rb', line 26 attr_writer :ability, :hostname |
Class Method Details
.for(model) ⇒ Object
31 32 33 34 35 |
# File 'app/presenters/hyrax/iiif_manifest_presenter.rb', line 31 def for(model) klass = model.file_set? ? DisplayImagePresenter : IiifManifestPresenter klass.new(model) 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 |
#file_set? ⇒ Boolean
52 53 54 |
# File 'app/presenters/hyrax/iiif_manifest_presenter.rb', line 52 def file_set? model.try(:file_set?) || Array(model[:has_model_ssim]).include?('FileSet') end |
#file_set_presenters ⇒ Array<DisplayImagePresenter>
58 59 60 |
# File 'app/presenters/hyrax/iiif_manifest_presenter.rb', line 58 def file_set_presenters member_presenters.select(&:file_set?) end |
#manifest_metadata ⇒ Array<Hash{String => String}>
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
70 71 72 73 74 75 76 77 |
# File 'app/presenters/hyrax/iiif_manifest_presenter.rb', line 70 def .map do |field_name| { 'label' => I18n.t("simple_form.labels.defaults.#{field_name}"), 'value' => Array(self[field_name]).map { |value| scrub(value.to_s) } } end end |
#manifest_url ⇒ String
Returns the URL where the manifest can be found.
81 82 83 84 85 |
# File 'app/presenters/hyrax/iiif_manifest_presenter.rb', line 81 def manifest_url return '' if id.blank? Rails.application.routes.url_helpers.polymorphic_url([:manifest, model], host: hostname) end |
#member_ids ⇒ Array<#to_s>
89 90 91 |
# File 'app/presenters/hyrax/iiif_manifest_presenter.rb', line 89 def member_ids Hyrax::SolrDocument::OrderedMembers.decorate(model).ordered_member_ids end |
#member_presenters ⇒ Array<IiifManifestPresenter>
cache member presenters to avoid querying repeatedly; we expect this presenter to live only as long as the request.
skips presenters for objects the current ‘@ability` cannot read. the default ability has all permissions.
101 102 103 104 105 106 107 108 109 |
# File 'app/presenters/hyrax/iiif_manifest_presenter.rb', line 101 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}>
113 114 115 116 117 118 119 120 121 122 |
# File 'app/presenters/hyrax/iiif_manifest_presenter.rb', line 113 def sequence_rendering Array(try(:rendering_ids)).map do |file_set_id| rendering = file_set_presenters.find { |p| p.id == file_set_id } next unless rendering { '@id' => Hyrax::Engine.routes.url_helpers.download_url(rendering.id, host: hostname), 'format' => rendering.mime_type.present? ? rendering.mime_type : I18n.t("hyrax.manifest.unknown_mime_text"), 'label' => I18n.t("hyrax.manifest.download_text") + (rendering.label || '') } end.flatten end |
#version ⇒ String
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.
142 143 144 |
# File 'app/presenters/hyrax/iiif_manifest_presenter.rb', line 142 def version object.try(:modified_date)&.to_s || '' end |
#work? ⇒ Boolean
126 127 128 |
# File 'app/presenters/hyrax/iiif_manifest_presenter.rb', line 126 def work? object.try(:work?) || !file_set? end |
#work_presenters ⇒ Array<IiifManifestPresenter>
132 133 134 |
# File 'app/presenters/hyrax/iiif_manifest_presenter.rb', line 132 def work_presenters member_presenters.select(&:work?) end |