-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Presentation 3.0 Alpha Support (#19)
* WIP Tests running * viewingHint -> behavior, @id -> id, @type -> type * Move rendering from sequence to manifest * WIP Builds Canvases * WIP ranges and sub-ranges * WIP Rewrite id attribute of rendering hash * WIP actually put canvases in manifest items * WIP use deep canvas builder always * WIP All tests passing * Appease rubocop * Add AnnotationPage * Test with real labels * Refactor and prepare for choice builder * WIP add support for choice * Appease rubocop * Test body and choice * Appease rubocop * Transform metadata into prezi 3 style * Fix more rubocop issues * Set image service the prezi3 way
- Loading branch information
Showing
21 changed files
with
1,542 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,5 @@ module IIIFManifest | |
autoload :DisplayImage | ||
autoload :IIIFCollection | ||
autoload :IIIFEndpoint | ||
autoload :V3 | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
class IIIFCollection < SimpleDelegator | ||
def viewing_hint | ||
return super if __getobj__.respond_to?(:viewing_hint) | ||
'multi-part' | ||
module IIIFManifest | ||
class IIIFCollection < SimpleDelegator | ||
def viewing_hint | ||
return super if __getobj__.respond_to?(:viewing_hint) | ||
'multi-part' | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'active_support' | ||
require 'active_support/core_ext/module' | ||
require 'active_support/core_ext/object' | ||
|
||
module IIIFManifest | ||
module V3 | ||
extend ActiveSupport::Autoload | ||
autoload :ManifestBuilder | ||
autoload :ManifestFactory | ||
autoload :ManifestServiceLocator | ||
autoload :DisplayContent | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module IIIFManifest | ||
module V3 | ||
class DisplayContent | ||
attr_reader :url, :width, :height, :duration, :iiif_endpoint, :format, :type, :label | ||
def initialize(url, type:, width: nil, height: nil, duration: nil, label: nil, format: nil, iiif_endpoint: nil) | ||
@url = url | ||
@type = type | ||
@width = width | ||
@height = height | ||
@duration = duration | ||
@label = label | ||
@format = format | ||
@iiif_endpoint = iiif_endpoint | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require_relative 'manifest_builder/iiif_service' | ||
require_relative 'manifest_builder/canvas_builder' | ||
require_relative 'manifest_builder/record_property_builder' | ||
require_relative 'manifest_builder/choice_builder' | ||
require_relative 'manifest_builder/content_builder' | ||
require_relative 'manifest_builder/body_builder' | ||
require_relative 'manifest_builder/structure_builder' | ||
require_relative 'manifest_builder/image_service_builder' | ||
|
||
module IIIFManifest | ||
module V3 | ||
class ManifestBuilder | ||
attr_reader :work, | ||
:builders, | ||
:top_record_factory | ||
def initialize(work, builders:, top_record_factory:) | ||
@work = work | ||
@builders = builders | ||
@top_record_factory = top_record_factory | ||
end | ||
|
||
def apply(collection) | ||
collection['manifests'] ||= [] | ||
collection['manifests'] << to_h | ||
collection | ||
end | ||
|
||
def to_h | ||
@to_h ||= builders.new(work).apply(top_record) | ||
end | ||
|
||
private | ||
|
||
def top_record | ||
top_record_factory.new | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module IIIFManifest | ||
module V3 | ||
class ManifestBuilder | ||
class BodyBuilder | ||
attr_reader :display_content, :iiif_body_factory, :image_service_builder_factory | ||
def initialize(display_content, iiif_body_factory:, image_service_builder_factory:) | ||
@display_content = display_content | ||
@iiif_body_factory = iiif_body_factory | ||
@image_service_builder_factory = image_service_builder_factory | ||
end | ||
|
||
def apply(annotation) | ||
build_body | ||
image_service_builder.apply(body) if iiif_endpoint | ||
annotation.body = body | ||
end | ||
|
||
private | ||
|
||
def build_body | ||
body['id'] = display_content.url | ||
body['type'] = body_type | ||
body['height'] = display_content.height if display_content.try(:height) | ||
body['width'] = display_content.width if display_content.try(:width) | ||
body['duration'] = display_content.duration if display_content.try(:duration) | ||
body['format'] = display_content.format if display_content.format | ||
body['label'] = display_content.label if display_content.try(:label) | ||
end | ||
|
||
def body | ||
@body ||= iiif_body_factory.new | ||
end | ||
|
||
def body_type | ||
display_content.try(:type) || 'Image' | ||
end | ||
|
||
def iiif_endpoint | ||
display_content.try(:iiif_endpoint) | ||
end | ||
|
||
def image_service_builder | ||
image_service_builder_factory.new(iiif_endpoint) | ||
end | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
module IIIFManifest | ||
module V3 | ||
class ManifestBuilder | ||
class CanvasBuilder | ||
attr_reader :record, :parent, :iiif_canvas_factory, :content_builder, | ||
:choice_builder, :iiif_annotation_page_factory | ||
|
||
def initialize(record, | ||
parent, | ||
iiif_canvas_factory:, | ||
content_builder:, | ||
choice_builder:, | ||
iiif_annotation_page_factory:) | ||
@record = record | ||
@parent = parent | ||
@iiif_canvas_factory = iiif_canvas_factory | ||
@content_builder = content_builder | ||
@choice_builder = choice_builder | ||
@iiif_annotation_page_factory = iiif_annotation_page_factory | ||
apply_record_properties | ||
# Presentation 2.x approach | ||
attach_image if display_image | ||
# Presentation 3.0 approach | ||
attach_content if display_content | ||
end | ||
|
||
def canvas | ||
@canvas ||= iiif_canvas_factory.new | ||
end | ||
|
||
def path | ||
"#{parent.manifest_url}/canvas/#{record.id}" | ||
end | ||
|
||
def apply(items) | ||
return items if canvas.items.blank? | ||
items << canvas | ||
end | ||
|
||
private | ||
|
||
def display_image | ||
record.display_image if record.respond_to?(:display_image) | ||
end | ||
|
||
def display_content | ||
Array.wrap(record.display_content) if record.respond_to?(:display_content) | ||
end | ||
|
||
def apply_record_properties | ||
canvas['id'] = path | ||
canvas.label = record.to_s | ||
annotation_page['id'] = "#{path}/annotation_page/#{annotation_page.index}" | ||
canvas.items = [annotation_page] | ||
end | ||
|
||
def annotation_page | ||
@annotation_page ||= iiif_annotation_page_factory.new | ||
end | ||
|
||
def attach_image | ||
content_builder.new(display_image).apply(canvas) | ||
end | ||
|
||
def attach_content | ||
if display_content.size == 1 | ||
content_builder.new(display_content.first).apply(canvas) | ||
else | ||
choice_builder.new(display_content).apply(canvas) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module IIIFManifest | ||
module V3 | ||
class ManifestBuilder | ||
class ChoiceBuilder | ||
attr_reader :display_content, :iiif_annotation_factory, :body_builder_factory, :iiif_choice_factory | ||
def initialize(display_content, iiif_annotation_factory:, body_builder_factory:, iiif_choice_factory:) | ||
@display_content = display_content | ||
@iiif_annotation_factory = iiif_annotation_factory | ||
@body_builder_factory = body_builder_factory | ||
@iiif_choice_factory = iiif_choice_factory | ||
build_choice | ||
end | ||
|
||
def apply(canvas) | ||
annotation['target'] = canvas['id'] | ||
canvas['width'] = choice.items.first['width'] | ||
canvas['height'] = choice.items.first['height'] | ||
canvas['duration'] = choice.items.first['duration'] | ||
annotation.body = choice | ||
# Assume first item in canvas is an annotation page | ||
canvas.items.first.items += [annotation] | ||
end | ||
|
||
private | ||
|
||
def build_choice | ||
display_content.each do |content| | ||
content_body = body_builder(content).apply(iiif_annotation_factory.new) | ||
choice.items += [content_body] | ||
end | ||
end | ||
|
||
def body_builder(content) | ||
body_builder_factory.new(content) | ||
end | ||
|
||
def annotation | ||
@annotation ||= iiif_annotation_factory.new | ||
end | ||
|
||
def choice | ||
@choice ||= iiif_choice_factory.new | ||
end | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module IIIFManifest | ||
module V3 | ||
class ManifestBuilder | ||
class ContentBuilder | ||
attr_reader :display_content, :iiif_annotation_factory, :body_builder_factory | ||
def initialize(display_content, iiif_annotation_factory:, body_builder_factory:) | ||
@display_content = display_content | ||
@iiif_annotation_factory = iiif_annotation_factory | ||
@body_builder_factory = body_builder_factory | ||
build_resource | ||
end | ||
|
||
def apply(canvas) | ||
annotation['target'] = canvas['id'] | ||
canvas['width'] = annotation.body['width'] | ||
canvas['height'] = annotation.body['height'] | ||
canvas['duration'] = annotation.body['duration'] | ||
# Assume first item in canvas is an annotation page | ||
canvas.items.first.items += [annotation] | ||
end | ||
|
||
private | ||
|
||
def build_resource | ||
body_builder.apply(annotation) | ||
end | ||
|
||
def body_builder | ||
body_builder_factory.new(display_content) | ||
end | ||
|
||
def annotation | ||
@annotation ||= iiif_annotation_factory.new | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.