Skip to content

Commit

Permalink
Merge pull request #3 from samvera-labs/hyku_1372_rendering
Browse files Browse the repository at this point in the history
Support for a 'sequence_rendering' method
  • Loading branch information
jcoyne authored Aug 2, 2017
2 parents 717ec35 + 003989e commit 1e2167d
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
```

Expand Down
9 changes: 9 additions & 0 deletions lib/iiif_manifest/manifest_builder/sequence_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(&:to_h)
else
[]
end
end
end
end
end
53 changes: 53 additions & 0 deletions spec/lib/iiif_manifest/manifest_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,59 @@ 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') }

Expand Down

0 comments on commit 1e2167d

Please sign in to comment.