Skip to content

Commit

Permalink
Presentation 3.0 Alpha Support (#19)
Browse files Browse the repository at this point in the history
* 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
cjcolvar authored Apr 26, 2018
1 parent 2aaaade commit 93fa3c2
Show file tree
Hide file tree
Showing 21 changed files with 1,542 additions and 6 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Metrics/BlockLength:
Naming/MethodName:
Exclude:
- 'lib/iiif_manifest/manifest_builder/iiif_service.rb'
- 'lib/iiif_manifest/v3/manifest_builder/iiif_service.rb'

RSpec/MultipleExpectations:
Enabled: false
32 changes: 32 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Metrics/AbcSize:
Exclude:
- 'lib/iiif_manifest/manifest_builder/resource_builder.rb'
- 'lib/iiif_manifest/manifest_factory.rb'
- 'lib/iiif_manifest/v3/manifest_builder/body_builder.rb'
- 'lib/iiif_manifest/v3/manifest_factory.rb'
- 'lib/iiif_manifest/v3/manifest_builder/content_builder.rb'
- 'lib/iiif_manifest/v3/manifest_builder/choice_builder.rb'

# Offense count: 1
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
Expand All @@ -31,6 +35,7 @@ RSpec/NamedSubject:
- 'spec/lib/iiif_manifest/display_image_spec.rb'
- 'spec/lib/iiif_manifest/iiif_endpoint_spec.rb'
- 'spec/lib/iiif_manifest/manifest_builder/resource_builder_spec.rb'
- 'spec/lib/iiif_manifest/v3/manifest_builder/body_builder_spec.rb'

# Offense count: 1
# Configuration parameters: IgnoreSymbolicNames.
Expand All @@ -41,6 +46,8 @@ RSpec/VerifiedDoubles:
RSpec/ExampleLength:
Exclude:
- 'spec/lib/iiif_manifest/manifest_factory_spec.rb'
- 'spec/lib/iiif_manifest/v3/manifest_factory_spec.rb'
- 'spec/lib/iiif_manifest/v3/manifest_builder/body_builder_spec.rb'

# Offense count: 20
Style/Documentation:
Expand All @@ -66,7 +73,21 @@ Style/Documentation:
- 'lib/iiif_manifest/manifest_service_locator.rb'
- 'lib/iiif_manifest.rb'
- 'lib/iiif_manifest/manifest_builder/iiif_service.rb'
- 'lib/iiif_manifest/v3.rb'
- 'lib/iiif_manifest/v3/display_content.rb'
- 'lib/iiif_manifest/v3/manifest_factory.rb'
- 'lib/iiif_manifest/v3/manifest_builder/structure_builder.rb'
- 'lib/iiif_manifest/v3/manifest_builder/iiif_service.rb'
- 'lib/iiif_manifest/v3/manifest_builder/canvas_builder.rb'
- 'lib/iiif_manifest/v3/manifest_builder/choice_builder.rb'
- 'lib/iiif_manifest/v3/manifest_builder/content_builder.rb'
- 'lib/iiif_manifest/v3/manifest_builder/body_builder.rb'
- 'lib/iiif_manifest/v3/manifest_builder/record_property_builder.rb'
- 'lib/iiif_manifest/v3/manifest_builder/image_service_builder.rb'
- 'lib/iiif_manifest/v3/manifest_builder.rb'
- 'lib/iiif_manifest/v3/manifest_service_locator.rb'
- 'spec/lib/iiif_manifest/manifest_factory_spec.rb'
- 'spec/lib/iiif_manifest/v3/manifest_factory_spec.rb'

# Offense count: 1
Style/MethodMissing:
Expand All @@ -76,10 +97,21 @@ Style/MethodMissing:
Metrics/ClassLength:
Exclude:
- 'lib/iiif_manifest/manifest_service_locator.rb'
- 'lib/iiif_manifest/v3/manifest_service_locator.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: MinSize, SupportedStyles.
# SupportedStyles: percent, brackets
Style/SymbolArray:
EnforcedStyle: brackets

Metrics/ParameterLists:
Exclude:
- 'lib/iiif_manifest/v3/display_content.rb'
- 'lib/iiif_manifest/v3/manifest_builder/canvas_builder.rb'

RSpec/NestedGroups:
Exclude:
- 'spec/lib/iiif_manifest/v3/manifest_factory_spec.rb'
- 'spec/lib/iiif_manifest/v3/manifest_builder/body_builder_spec.rb'
2 changes: 1 addition & 1 deletion iiif_manifest.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'iiif_manifest/version'

Expand Down
1 change: 1 addition & 0 deletions lib/iiif_manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ module IIIFManifest
autoload :DisplayImage
autoload :IIIFCollection
autoload :IIIFEndpoint
autoload :V3
end
10 changes: 6 additions & 4 deletions lib/iiif_manifest/iiif_collection.rb
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
13 changes: 13 additions & 0 deletions lib/iiif_manifest/v3.rb
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
17 changes: 17 additions & 0 deletions lib/iiif_manifest/v3/display_content.rb
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
39 changes: 39 additions & 0 deletions lib/iiif_manifest/v3/manifest_builder.rb
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
48 changes: 48 additions & 0 deletions lib/iiif_manifest/v3/manifest_builder/body_builder.rb
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
75 changes: 75 additions & 0 deletions lib/iiif_manifest/v3/manifest_builder/canvas_builder.rb
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
47 changes: 47 additions & 0 deletions lib/iiif_manifest/v3/manifest_builder/choice_builder.rb
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
38 changes: 38 additions & 0 deletions lib/iiif_manifest/v3/manifest_builder/content_builder.rb
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
Loading

0 comments on commit 93fa3c2

Please sign in to comment.