Skip to content

Commit

Permalink
Merge spotlight_resources_iiif gem into this project
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Feb 6, 2017
1 parent 6560011 commit ec7f914
Show file tree
Hide file tree
Showing 43 changed files with 54 additions and 1,019 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Metrics/AbcSize:

Metrics/ModuleLength:
Max: 120
Exclude:
- 'spec/fixtures/**/*'

Metrics/LineLength:
Max: 160
Expand All @@ -57,6 +59,7 @@ Metrics/BlockLength:
Metrics/ClassLength:
Exclude:
- 'app/models/spotlight/resource.rb'
- 'app/models/spotlight/resources/iiif_manifest.rb'
- 'lib/generators/spotlight/**/*' # Generators tend to have longer class lengths due to their lengthy public API

Style/PredicateName:
Expand All @@ -66,6 +69,7 @@ Style/PredicateName:
Metrics/MethodLength:
Exclude:
- 'lib/generators/spotlight/**/*'
- 'spec/fixtures/**/*'

RSpec/NestedGroups:
Max: 4
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Spotlight
module Resources
# IIIF resources harvesting endpoint
class IiifHarvesterController < Spotlight::ResourcesController
def resource_class
Spotlight::Resources::IiifHarvester
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,15 @@ def add_document_id
end

def add_collection_id
if collection
solr_hash[collection_id_field] = [collection.compound_id]
end
solr_hash[collection_id_field] = [collection.compound_id] if collection
end

def collection_id_field
Spotlight::Resources::Iiif::Engine.config.collection_id_field
Spotlight::Engine.config.iiif_collection_id_field
end

def add_manifest_url
solr_hash[Spotlight::Resources::Iiif::Engine.config.iiif_manifest_field] = url
solr_hash[Spotlight::Engine.config.iiif_manifest_field] = url
end

def add_thumbnail_url
Expand Down Expand Up @@ -158,7 +156,7 @@ def document_model
end

def metadata_class
Spotlight::Resources::Iiif::Engine.config.metadata_class.call
Spotlight::Engine.config.iiif_metadata_class.call
end

###
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,7 @@ def manifests
@manifests ||= if manifest?
[create_iiif_manifest(object)]
else
things = []
if collection?
self_manifest = create_iiif_manifest(object)
things << self_manifest
end
(object.try(:manifests) || []).each do |manifest|
things << create_iiif_manifest(
self.class.new(manifest['@id']).object, self_manifest
)
end
things
build_collection_manifest.to_a
end
end

Expand Down Expand Up @@ -62,9 +52,11 @@ def recursive_manifests(thing, &block)

thing.manifests.each(&block)

return unless thing.collections.present?

thing.collections.each do |collection|
recursive_manifests(collection, &block)
end if thing.collections.present?
end
end
end

Expand All @@ -83,6 +75,19 @@ def collection?
def response
@response ||= self.class.iiif_response(url)
end

def build_collection_manifest
return to_enum(:build_collection_manifest) unless block_given?

if collection?
self_manifest = create_iiif_manifest(object)
yield self_manifest
end

(object.try(:manifests) || []).each do |manifest|
yield create_iiif_manifest(self.class.new(manifest['@id']).object, self_manifest)
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= bootstrap_form_for([spotlight_resources_iiif_engine, current_exhibit, @resource.becomes(Spotlight::Resources::IiifHarvester)], as: :resource, layout: :horizontal, label_col: 'col-md-2', control_col: 'col-sm-6 col-md-6' ) do |f| %>
<%= bootstrap_form_for([spotlight, current_exhibit, @resource.becomes(Spotlight::Resources::IiifHarvester)], as: :resource, layout: :horizontal, label_col: 'col-md-2', control_col: 'col-sm-6 col-md-6' ) do |f| %>
<%= f.text_field :url, help: t('.url-field.help'), label: t('.manifest') %>
<div class="form-actions">
<div class="primary-actions">
Expand Down
7 changes: 7 additions & 0 deletions config/locales/spotlight.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,13 @@ en:
title: "Upload raw documents"
add_item: "Add item"
file_label: "JSON File"
iiif:
form:
title: 'IIIF URL'
manifest: "URL"
add_item: "Add IIIF items"
url-field:
help: "Add the URL of a IIIF manifest or collection."
bookmarklet:
instructions: "Drag this button to the bookmarks toolbar in your web browser"
bookmarklet: "%{application_name} widget"
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
end
end

resources :iiif_harvesters, controller: 'resources/iiif_harvester', only: :create, as: 'resources_iiif_harvesters'

resources :searches do
collection do
patch :update_all
Expand Down
5 changes: 4 additions & 1 deletion lib/spotlight/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def self.blacklight_config
'spotlight/resources/external_resources_form',
'spotlight/resources/upload/form',
'spotlight/resources/csv_upload/form',
'spotlight/resources/json_upload/form'
'spotlight/resources/json_upload/form',
'spotlight/resources/iiif/form'
]
config.external_resources_partials = []
config.solr_batch_size = 20
Expand Down Expand Up @@ -135,6 +136,8 @@ def self.blacklight_config
]

config.iiif_manifest_field = :iiif_manifest_url_ssi
config.iiif_metadata_class = -> { Spotlight::Resources::IiifManifest::Metadata }
config.iiif_collection_id_field = :collection_id_ssim

config.masthead_initial_crop_selection = [1200, 120]
config.thumbnail_initial_crop_selection = [120, 120]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'rails_helper'
require 'spec_helper'

describe 'adding IIIF Manifest', type: :feature do
let(:exhibit) { FactoryGirl.create(:exhibit) }
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'rails_helper'
require 'spec_helper'

describe Spotlight::Resources::IiifHarvester do
let(:exhibit) { FactoryGirl.create(:exhibit) }
Expand Down Expand Up @@ -26,11 +26,5 @@
expect(subject.documents_to_index).to be_a(Enumerator)
expect(subject.documents_to_index.count).to eq 8
end

it 'all solr documents include exhibit context' do
subject.documents_to_index.each do |doc|
expect(doc).to have_key("spotlight_exhibit_slug_#{exhibit.slug}_bsi")
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
require 'rails_helper'
require 'spec_helper'

class TestMetadataClass
def initialize(*)
end
def initialize(*); end

def to_solr
{ 'test_field' => 'metadata-to-solr' }
Expand All @@ -11,8 +10,8 @@ def to_solr

describe Spotlight::Resources::IiifManifest do
let(:url) { 'uri://to-manifest' }
subject { described_class.new({ url: url, manifest: manifest, collection: collection}) }
let(:collection) { double( compound_id: "1" ) }
subject { described_class.new(url: url, manifest: manifest, collection: collection) }
let(:collection) { double(compound_id: '1') }
before do
stub_iiif_response_for_url(url, test_manifest1)
subject.with_exhibit(exhibit)
Expand All @@ -34,15 +33,15 @@ def to_solr
end
end

describe "collection id" do
it "is included when a collection is given" do
expect(subject.to_solr[:collection_id_ssim]).to eq ["1"]
describe 'collection id' do
it 'is included when a collection is given' do
expect(subject.to_solr[:collection_id_ssim]).to eq ['1']
end
end

describe 'manifest url' do
it 'is inlcuded in the solr document when present' do
expect(subject.to_solr[:content_metadata_iiif_manifest_ssm]).to eq url
expect(subject.to_solr[:iiif_manifest_url_ssi]).to eq url
end
end

Expand All @@ -53,7 +52,7 @@ def to_solr
end

describe 'full size image url' do
it "is included in the solr document" do
it 'is included in the solr document' do
expect(subject.to_solr[:full_image_url_ssm]).to eq 'uri://full-image'
end
end
Expand Down Expand Up @@ -90,13 +89,13 @@ def to_solr
expect { subject.to_solr }.to change(Spotlight::CustomField, :count).by(5)
end

it "creates read-only custom fields" do
it 'creates read-only custom fields' do
expect { subject.to_solr }.to change(Spotlight::CustomField.where(readonly_field: true), :count).by(5)
end

context 'custom class' do
before do
Spotlight::Resources::Iiif::Engine.config.metadata_class = -> { TestMetadataClass }
Spotlight::Engine.config.iiif_metadata_class = -> { TestMetadataClass }
end

it 'merges the solr hash from the configured custom metadata class' do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'rails_helper'
require 'spec_helper'

describe Spotlight::Resources::IiifService do
let(:url) { 'uri://for-top-level-collection' }
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion spotlight_resources_iiif/.coveralls.yml

This file was deleted.

11 changes: 0 additions & 11 deletions spotlight_resources_iiif/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions spotlight_resources_iiif/.rspec

This file was deleted.

15 changes: 0 additions & 15 deletions spotlight_resources_iiif/.rubocop.yml

This file was deleted.

7 changes: 0 additions & 7 deletions spotlight_resources_iiif/.rubocop_todo.yml

This file was deleted.

5 changes: 0 additions & 5 deletions spotlight_resources_iiif/.solr_wrapper.yml

This file was deleted.

17 changes: 0 additions & 17 deletions spotlight_resources_iiif/.travis.yml

This file was deleted.

41 changes: 0 additions & 41 deletions spotlight_resources_iiif/Gemfile

This file was deleted.

13 changes: 0 additions & 13 deletions spotlight_resources_iiif/LICENSE.txt

This file was deleted.

0 comments on commit ec7f914

Please sign in to comment.