-
-
Save jenlindner/9bc2162e95f30f7f1cd8281e0dc165a1 to your computer and use it in GitHub Desktop.
want to add media sequences to iiif manifest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'iiif_manifest' | |
# how do i override or extend classes I would like to in iiif_manifest? for example these two methods in manifest_builder should be added to or extend the class locally. I think the better design would be to have them in the gem, they should be their own builder class like sequence_builder, and autoloaded, and used in the optional case of pdfs or other sequenced media and the universal viewer. | |
module PDFManifestBuilder | |
def add_media_sequences(access_path, manifest) | |
json_manifest = JSON.parse(manifest.to_json) | |
json_manifest["mediaSequences"] = [media_sequence(access_path)] | |
json_manifest["@context"] = ["http://iiif.io/api/image/2/context.json","http://wellcomelibrary.org/ld/ixif/0/context.json"] | |
json_manifest | |
end | |
def media_sequence(access_path) | |
@elements ||= | |
begin | |
elements = {} | |
elements["@id"] = access_path | |
elements["format"] = "application/pdf" | |
elements["@type"] = "foaf:Document" | |
elements["label"] = "Test Label" | |
elements["rendering"] = [{ | |
"@id": access_path, | |
"format": "application/pdf", | |
"label": "Test Label" | |
}] | |
elements["thumbnail"] = "http://test_path_to_thumbnail.jpg" | |
end | |
@mediaSequence ||= | |
begin | |
mediaSequence = {} | |
mediaSequence["@type"] ||= "ixif:MediaSequence" | |
mediaSequence["label"] ||= "Contents" | |
mediaSequence["rendering"] = [] | |
mediaSequence["elements"] = [elements] | |
mediaSequence | |
end | |
end | |
end | |
module ManifestBehavior | |
def manifest | |
id = presenter.solr_document[:file_set_ids_ssim].first | |
# access_url = DerivativePath.access_path(id) | |
access_url = "/test.pdf" | |
headers['Access-Control-Allow-Origin'] = '*' | |
respond_to do |format| | |
format.json { render json: | |
# PDFManifestBuilder | |
# only in case of pdf (so need to get that from presenter), add_media_sequences | |
# this returns instance of ManifestBuilder | |
# manifest_builder.add_media_sequences(access_url) | |
manifest_builder(access_url) } | |
end | |
end | |
private | |
def manifest_builder(access_url) | |
builder = IIIFManifest::ManifestFactory.new(presenter) | |
builder.extend PDFManifestBuilder | |
manifest = builder.to_h | |
builder.add_media_sequences(access_url, manifest) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment