From 24899ac7502f470f2c963dcfbdd5e26a306ce0f1 Mon Sep 17 00:00:00 2001 From: Julie Allinson Date: Tue, 18 Jul 2017 18:57:31 +0100 Subject: [PATCH] support for an optional 'manifest_extras' method to initially support adding rendering to sequences --- README.md | 14 +++++- .../manifest_builder/sequence_builder.rb | 9 ++++ .../iiif_manifest/manifest_factory_spec.rb | 50 +++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b77227e..864a8b6 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,17 @@ IIIF http://iiif.io/ defines an API for presenting related images in a viewer. T ## Usage -You application must have an object that implements `#file_set_presenters` and `#work_presenters`. The former method should return as set of leaf nodes and the later any interstitial nodes. If none are found an empty array should be returned. Additionally it should implement `#manifest_url` that shows where the manifest can be found. Finally, it must have a `#description` method that returns a string. +Your application ***must*** have an object that implements `#file_set_presenters` and `#work_presenters`. The former method should return as set of leaf nodes and the later any interstitial nodes. If none are found an empty array should be returned. + +Additionally, it ***must*** have a `#description` method that returns a string. + +Additionally it ***should*** implement `#manifest_url` that shows where the manifest can be found. + +Finally, it ***may*** implement `#sequence_rendering` to contain an array of hashes for file downloads to be offered at sequences level. Each hash must contain "@id", "format" (mime type) and "label" (eg. `{ "@id" => "download url", "format" => "application/pdf", "label" => "user friendly label" }`). For example: -```ruby + ```ruby class Book def initialize(id, pages = []) @id = id @@ -31,6 +37,10 @@ For example: def description 'a brief description' end + + def sequence_rendering: + [{"@id" => "http://test.host/file_set/id/download", "format" => "application/pdf", "label" => "Download"}] + end end ``` diff --git a/lib/iiif_manifest/manifest_builder/sequence_builder.rb b/lib/iiif_manifest/manifest_builder/sequence_builder.rb index e564b1a..155c6ce 100644 --- a/lib/iiif_manifest/manifest_builder/sequence_builder.rb +++ b/lib/iiif_manifest/manifest_builder/sequence_builder.rb @@ -28,10 +28,19 @@ def sequence begin sequence = IIIF::Presentation::Sequence.new sequence["@id"] ||= work.manifest_url + "/sequence/normal" + sequence["rendering"] ||= populate_sequence_rendering canvas_builder.apply(sequence) sequence end end + + def populate_sequence_rendering + if work.respond_to?(:sequence_rendering) + work.sequence_rendering.each { | x | x.to_h } + else + [] + end + end end end end diff --git a/spec/lib/iiif_manifest/manifest_factory_spec.rb b/spec/lib/iiif_manifest/manifest_factory_spec.rb index 767da86..c5575ba 100644 --- a/spec/lib/iiif_manifest/manifest_factory_spec.rb +++ b/spec/lib/iiif_manifest/manifest_factory_spec.rb @@ -22,6 +22,7 @@ def file_set_presenters def work_presenters [] end + def manifest_url "http://test.host/books/#{@id}/manifest" end @@ -46,6 +47,7 @@ def display_image describe "#to_h" do let(:result) { subject.to_h } let(:json_result) { JSON.parse(subject.to_h.to_json) } + it "has a label" do expect(result.label).to eq book_presenter.to_s end @@ -73,6 +75,54 @@ def display_image end end + context "where there is a no sequence_rendering method" do + let(:file_presenter) { DisplayImagePresenter.new } + + it "does not have a rendering on the sequence" do + allow(IIIFManifest::ManifestBuilder::CanvasBuilder).to receive(:new).and_call_original + allow(book_presenter).to receive(:file_set_presenters).and_return([file_presenter]) + expect(result['sequences'][0]['rendering']).to eq [] + end + end + + context "where there is a sequence_rendering method" do + let(:file_presenter) { DisplayImagePresenter.new } + before do + class Book + def initialize(id) + @id = id + end + + def description + 'a brief description' + end + + def file_set_presenters + [] + end + + def work_presenters + [] + end + + def manifest_url + "http://test.host/books/#{@id}/manifest" + end + + def sequence_rendering + [{ "@id" => "http://test.host/file_set/id/download", "format" => "application/pdf", "label" => "Download" }] + end + end + end + + it "has a rendering on the sequence" do + allow(IIIFManifest::ManifestBuilder::CanvasBuilder).to receive(:new).and_call_original + allow(book_presenter).to receive(:file_set_presenters).and_return([file_presenter]) + + expect(result['sequences'][0]['rendering']).to eq [{ "@id" => "http://test.host/file_set/id/download", "format" => "application/pdf", "label" => "Download" }] + end + end + context "when there are child works" do let(:child_work_presenter) { presenter_class.new('test2') } before do