Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "remove apply thumbnail to manifest and fix specs" #81

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/iiif_manifest/manifest_builder/canvas_builder.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
module IIIFManifest
class ManifestBuilder
class CanvasBuilder
attr_reader :record, :parent, :manifest, :iiif_canvas_factory, :image_builder
attr_reader :record, :parent, :iiif_canvas_factory, :image_builder

def initialize(record, parent, manifest, iiif_canvas_factory:, image_builder:)
def initialize(record, parent, iiif_canvas_factory:, image_builder:)
@record = record
@parent = parent
@manifest = manifest
@iiif_canvas_factory = iiif_canvas_factory
@image_builder = image_builder
apply_record_properties
Expand Down
4 changes: 2 additions & 2 deletions lib/iiif_manifest/manifest_builder/canvas_builder_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ def initialize(composite_builder:, canvas_builder_factory:)
@canvas_builder_factory = canvas_builder_factory
end

def from(work, *manifest)
def from(work)
composite_builder.new(
*file_set_presenters(work).map do |presenter|
canvas_builder_factory.new(presenter, work, manifest.first)
canvas_builder_factory.new(presenter, work)
end
)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/iiif_manifest/manifest_builder/structure_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def sub_ranges

def canvas_builders
@canvas_builders ||= file_set_presenters.map do |file_set_presenter|
canvas_builder_factory.new(file_set_presenter, parent, nil)
canvas_builder_factory.new(file_set_presenter, parent)
end
end

Expand Down
29 changes: 3 additions & 26 deletions lib/iiif_manifest/v3/manifest_builder/canvas_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@ module IIIFManifest
module V3
class ManifestBuilder
class CanvasBuilder
attr_reader :record, :parent, :manifest, :iiif_canvas_factory, :content_builder,
attr_reader :record, :parent, :iiif_canvas_factory, :content_builder,
:choice_builder, :iiif_annotation_page_factory, :thumbnail_builder_factory

def initialize(record,
parent,
manifest,
iiif_canvas_factory:,
content_builder:,
choice_builder:,
iiif_annotation_page_factory:,
thumbnail_builder_factory:)
@record = record
@parent = parent
@manifest = manifest
@iiif_canvas_factory = iiif_canvas_factory
@content_builder = content_builder
@choice_builder = choice_builder
Expand Down Expand Up @@ -55,45 +53,24 @@ def display_content
Array.wrap(record.display_content) if record.respond_to?(:display_content) && record.display_content.present?
end

def manifest_can_have_thumbnail
manifest.respond_to?(:thumbnail)
end

def apply_record_properties
canvas['id'] = path
canvas.label = ManifestBuilder.language_map(record.to_s) if record.to_s.present?
annotation_page['id'] = "#{path}/annotation_page/#{annotation_page.index}"
canvas.items = [annotation_page]
apply_thumbnail_to(manifest, canvas)
apply_thumbnail_to(canvas)
end

def apply_thumbnail_to(manifest, canvas)
def apply_thumbnail_to(canvas)
return unless iiif_endpoint

if display_image
apply_manifest_thumbnail(manifest, display_image)
canvas.thumbnail = Array(thumbnail_builder_factory.new(display_image).build)
elsif display_content.try(:first)
apply_manifest_thumbnail(manifest, display_content.first)
canvas.thumbnail = Array(thumbnail_builder_factory.new(display_content.first).build)
end
end

def collection?
manifest.is_a? IIIFManifest::Collection
end

def apply_manifest_thumbnail(manifest, display_type)
return unless manifest_can_have_thumbnail

if collection?
# if manifest.thumbnail is nil, make it an Array, then add more thumbnails into it
(manifest.thumbnail ||= []) << Array(thumbnail_builder_factory.new(display_type).build)
else
manifest.thumbnail ||= Array(thumbnail_builder_factory.new(display_type).build)
end
end

def annotation_page
@annotation_page ||= iiif_annotation_page_factory.new
end
Expand Down
4 changes: 0 additions & 4 deletions lib/iiif_manifest/v3/manifest_builder/iiif_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ def homepage=(homepage)
inner_hash['homepage'] = homepage
end

def thumbnail
inner_hash['thumbnail']
end

def thumbnail=(thumbnail)
inner_hash['thumbnail'] = thumbnail
end
Expand Down
31 changes: 28 additions & 3 deletions lib/iiif_manifest/v3/manifest_builder/record_property_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(record,
def apply(manifest)
setup_manifest_from_record(manifest, record)
# Build the items array
canvas_builder(manifest).apply(manifest.items)
canvas_builder.apply(manifest.items)
manifest
end

Expand All @@ -36,8 +36,8 @@ def populate_rendering

private

def canvas_builder(manifest)
canvas_builder_factory.from(record, manifest)
def canvas_builder
canvas_builder_factory.from(record)
end

# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize, Metrics/MethodLength
Expand All @@ -56,6 +56,7 @@ def setup_manifest_from_record(manifest, record)
manifest.rendering = populate_rendering if populate_rendering.present?
homepage = ::IIIFManifest.config.manifest_value_for(record, property: :homepage)
manifest.homepage = homepage if homepage.present?
apply_thumbnail_to(manifest)
end
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize, Metrics/MethodLength

Expand Down Expand Up @@ -98,6 +99,30 @@ def transform_field(field)
metadata_field['value'] = ManifestBuilder.language_map(field['value'])
metadata_field
end

def apply_thumbnail_to(manifest)
return unless iiif_endpoint

if display_image
manifest.thumbnail = Array(thumbnail_builder_factory.new(display_image).build)
elsif display_content
manifest.thumbnail = Array(thumbnail_builder_factory.new(display_content).build)
end
end

def display_image
return @display_image if defined?(@display_image)
@display_image = record.try(:member_presenters)&.first&.display_image
end

def display_content
return @display_content if defined?(@display_content)
@display_content = record.try(:member_presenters)&.first&.display_content
end

def iiif_endpoint
display_image.try(:iiif_endpoint) || Array(display_content).first.try(:iiif_endpoint)
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/iiif_manifest/v3/manifest_builder/structure_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def build_range
def canvas_builders
@canvas_builders ||= [] unless record.respond_to?(:file_set_presenters)
@canvas_builders ||= file_set_presenters.map do |file_set_presenter|
canvas_builder_factory.new(file_set_presenter, parent, nil)
canvas_builder_factory.new(file_set_presenter, parent)
end
@canvas_builders
end
Expand Down Expand Up @@ -69,7 +69,7 @@ def range_items
end

def canvas_range_item(range_item)
canvas_builder = canvas_builder_factory.new(range_item, parent, nil)
canvas_builder = canvas_builder_factory.new(range_item, parent)
{ 'type' => 'Canvas', 'id' => canvas_builder.path }
end

Expand Down
17 changes: 0 additions & 17 deletions spec/lib/iiif_manifest/v3/manifest_builder/canvas_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
described_class.new(
record,
parent,
manifest,
iiif_canvas_factory: IIIFManifest::V3::ManifestBuilder::IIIFManifest::Canvas,
content_builder: content_builder,
choice_builder: IIIFManifest::V3::ManifestBuilder::ChoiceBuilder,
Expand Down Expand Up @@ -58,7 +57,6 @@ def id
allow(content_builder).to receive(:new).and_return(built_content)
allow(thumbnail_builder).to receive(:build).and_return(iiif_thumbnail)
allow(thumbnail_builder_factory).to receive(:new).and_return(thumbnail_builder)
# allow(manifest).to receive(:thumbnail).and_return(iiif_thumbnail)
end

let(:iiif_body) do
Expand Down Expand Up @@ -104,10 +102,6 @@ def id
double('Thumbnail Builder')
end

let(:manifest) do
IIIFManifest::V3::ManifestBuilder::IIIFManifest.new
end

let(:built_content) do
IIIFManifest::V3::ManifestBuilder::ContentBuilder.new(
record.display_content,
Expand Down Expand Up @@ -156,17 +150,6 @@ def id
expect(values).to include "height" => "100px"
expect(values).to include "duration" => nil
end

it 'sets the manifest thumbnail as well' do
builder.canvas
expect(manifest.thumbnail).to be_an Array
manifest_thumbnail = manifest.thumbnail.first
expect(manifest_thumbnail).to be_a IIIFManifest::V3::ManifestBuilder::IIIFManifest::Thumbnail
expect(manifest_thumbnail['type']).to eq 'Image'
expect(manifest_thumbnail['width']).to eq 200
expect(manifest_thumbnail['height']).to eq 150
expect(manifest_thumbnail['duration']).to be_nil
end
end

context 'when the display content is empty for an item' do
Expand Down
11 changes: 11 additions & 0 deletions spec/lib/iiif_manifest/v3/manifest_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ def display_content
expect(result['items'].first['items'].first['items'].first['body']['format']).to eq 'image/jpeg'
end

it 'has a thumbnail property' do
allow(book_presenter).to receive(:member_presenters).and_return([file_presenter])

thumbnail = result['thumbnail'].first
expect(thumbnail['id']).to eq 'test.host/images/image-77/full/!200,200/0/default.jpg'
expect(thumbnail['height']).to eq 150
expect(thumbnail['width']).to eq 200
expect(thumbnail['format']).to eq 'image/jpeg'
expect(thumbnail['service'].first).to be_kind_of IIIFManifest::V3::ManifestBuilder::IIIFService
end

it 'builds a structure if it can' do
allow(book_presenter).to receive(:file_set_presenters).and_return([file_presenter])
allow(book_presenter.ranges[0].ranges[0]).to receive(:file_set_presenters).and_return([file_presenter])
Expand Down