Skip to content

Commit

Permalink
Merge pull request #89 from samvera/canvas_rendering
Browse files Browse the repository at this point in the history
Add rendering property at Canvas level
  • Loading branch information
cjcolvar authored Jan 27, 2023
2 parents aef759f + f679a12 commit c32322f
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ For example:

The class that represents the leaf nodes, must implement `#id`. It must also implement `#display_image` which returns an instance of `IIIFManifest::DisplayImage`

Additionally it **_may_** implement `#sequence_rendering` to contain an array of hashes for file downloads to be offered at each leaf node. This follows a similar format as `#sequence_rendering` at sequences level.

```ruby
class Page
def initialize(id)
Expand All @@ -126,6 +128,10 @@ The class that represents the leaf nodes, must implement `#id`. It must also imp
)
end

def sequence_rendering
[{"@id" => "http://test.host/display_image/id/download", "format" => "application/pdf", "label" => "Download"}]
end

private

def endpoint
Expand Down
13 changes: 13 additions & 0 deletions lib/iiif_manifest/v3/manifest_builder/canvas_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def apply_record_properties
annotation_page['id'] = "#{path}/annotation_page/#{annotation_page.index}"
canvas.items = [annotation_page]
apply_thumbnail_to(canvas)
canvas.rendering = populate_rendering if populate_rendering.present?
end

def apply_thumbnail_to(canvas)
Expand All @@ -84,6 +85,18 @@ def attach_content
choice_builder.new(display_content).apply(canvas)
end
end

def populate_rendering
return unless record.respond_to?(:sequence_rendering)
record.sequence_rendering.collect do |rendering|
sequence_rendering = rendering.to_h.except('@id', 'label')
sequence_rendering['id'] = rendering['@id']
if rendering['label'].present?
sequence_rendering['label'] = ManifestBuilder.language_map(rendering['label'])
end
sequence_rendering
end
end
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/iiif_manifest/v3/manifest_builder/iiif_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ def initial_attributes
'type' => 'Canvas'
}
end

def rendering=(rendering)
inner_hash['rendering'] = rendering
end
end

class Range < IIIFService
Expand Down
18 changes: 18 additions & 0 deletions spec/lib/iiif_manifest/v3/manifest_builder/canvas_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,24 @@ def id
end
end

context 'when display content has no rendering sequence' do
let(:display_content) do
IIIFManifest::V3::DisplayContent.new(url,
width: 640,
height: 480,
type: 'Image',
format: 'image/jpeg',
label: 'full',
iiif_endpoint: iiif_endpoint)
end
it 'generates canvas without rendering property' do
canvas = builder.canvas
expect(canvas).to be_a IIIFManifest::V3::ManifestBuilder::IIIFManifest::Canvas
values = canvas.inner_hash
expect(values.key?('rendering')).to be false
end
end

context 'when the display content is empty for an item' do
before do
class MyWork
Expand Down
35 changes: 35 additions & 0 deletions spec/lib/iiif_manifest/v3/manifest_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,17 @@ def to_s
def display_content
content
end

def sequence_rendering
[
{
'@id' => 'http://example.com/file_to_download.json',
'format' => 'application/json',
'type' => 'Dataset',
'label' => 'index.json'
}
]
end
end

allow(book_presenter).to receive(:file_set_presenters).and_return([file_presenter])
Expand All @@ -525,6 +536,14 @@ def display_content
expect(content_annotation_body['width']).to eq 100
expect(content_annotation_body['format']).to eq 'image/jpeg'
end

it 'returns rendering' do
canvas = result['items'].first
expect(canvas.key?('rendering')).to eq true
expect(canvas['rendering'].first['type']).to eq "Dataset"
expect(canvas['rendering'].first['format']).to eq "application/json"
expect(canvas['rendering'].first['label']).to eq({ "none" => ["index.json"] })
end
end

context 'with a single file' do
Expand All @@ -547,6 +566,14 @@ def display_content
expect(content_annotation_body['label']).to eq('none' => ['High'])
end

it 'returns rendering' do
canvas = result['items'].first
expect(canvas.key?('rendering')).to eq true
expect(canvas['rendering'].first['type']).to eq "Dataset"
expect(canvas['rendering'].first['format']).to eq "application/json"
expect(canvas['rendering'].first['label']).to eq({ "none" => ["index.json"] })
end

context 'with audio file' do
let(:content) do
IIIFManifest::V3::DisplayContent.new(SecureRandom.uuid, duration: 100,
Expand Down Expand Up @@ -637,6 +664,14 @@ def display_content
expect(choice['label']['none']).not_to be_empty
end
end

it 'returns rendering' do
canvas = result['items'].first
expect(canvas.key?('rendering')).to eq true
expect(canvas['rendering'].first['type']).to eq "Dataset"
expect(canvas['rendering'].first['format']).to eq "application/json"
expect(canvas['rendering'].first['label']).to eq({ "none" => ["index.json"] })
end
end
end

Expand Down

0 comments on commit c32322f

Please sign in to comment.