Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes to the collection indexer to make it aware of IIIF
Previously when you selected a collection thumbnail it did not know to use a IIIF url
- Loading branch information
Showing
16 changed files
with
117 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class CollectionIndexer < Hyrax::CollectionIndexer | ||
# This indexes the default metadata. You can remove it if you want to | ||
# provide your own metadata and indexing. | ||
include Hyrax::IndexesBasicMetadata | ||
|
||
# Use thumbnails served by RIIIF | ||
self.thumbnail_path_service = IIIFCollectionThumbnailPathService | ||
|
||
# Uncomment this block if you want to add custom indexing behavior: | ||
# def generate_solr_document | ||
# super.tap do |solr_doc| | ||
# solr_doc['my_custom_field_ssim'] = object.my_custom_property | ||
# 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
class FileSetIndexer < Hyrax::FileSetIndexer | ||
self.thumbnail_path_service = IIIFThumbnailPathService | ||
self.thumbnail_path_service = IIIFWorkThumbnailPathService | ||
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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module IIIFThumbnailPaths | ||
extend ActiveSupport::Concern | ||
|
||
class_methods do | ||
# @param [FileSet] file_set | ||
# @param [String] size ('!150,300') an IIIF image size defaults to an image no | ||
# wider than 150px and no taller than 300px | ||
# @return the IIIF url for the thumbnail if it's an image, otherwise gives | ||
# the thumbnail download path | ||
def thumbnail_path(file_set, size = '!150,300'.freeze) | ||
return super(file_set) unless file_set.image? | ||
iiif_thumbnail_path(file_set, size) | ||
end | ||
|
||
# @private | ||
def iiif_thumbnail_path(file_set, size) | ||
file = file_set.original_file | ||
return unless file | ||
Riiif::Engine.routes.url_helpers.image_path( | ||
file.id, | ||
size: size | ||
) | ||
end | ||
|
||
def thumbnail?(_thumbnail) | ||
true | ||
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,8 @@ | ||
class IIIFCollectionThumbnailPathService < Hyrax::CollectionThumbnailPathService | ||
include IIIFThumbnailPaths | ||
|
||
# The image to use if no thumbnail has been selected | ||
def self.default_image | ||
ActionController::Base.helpers.image_path 'collection.png' | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
class IIIFWorkThumbnailPathService < Hyrax::WorkThumbnailPathService | ||
include IIIFThumbnailPaths | ||
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,9 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe CollectionIndexer do | ||
describe ".thumbnail_path_service" do | ||
subject { described_class.thumbnail_path_service } | ||
|
||
it { is_expected.to eq IIIFCollectionThumbnailPathService } | ||
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
RSpec.describe FileSetIndexer do | ||
describe 'thumbnail_path_service' do | ||
subject { described_class.thumbnail_path_service } | ||
it { is_expected.to eq IIIFThumbnailPathService } | ||
it { is_expected.to eq IIIFWorkThumbnailPathService } | ||
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
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
38 changes: 38 additions & 0 deletions
38
spec/services/iiif_collection_thumbnail_path_service_spec.rb
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 @@ | ||
RSpec.describe IIIFCollectionThumbnailPathService do | ||
let(:file_set) { FileSet.new } | ||
let(:file) do | ||
double(id: 's1/78/4k/72/s1784k724/files/6185235a-79b2-4c29-8c24-4d6ad9b11470', | ||
mime_type: 'image/jpeg') | ||
end | ||
|
||
before do | ||
allow(ActiveFedora::Base).to receive(:find).with('s1784k724').and_return(file_set) | ||
allow(file_set).to receive_messages(original_file: file, id: 's1784k724') | ||
# https://github.com/projecthydra/active_fedora/issues/1251 | ||
allow(file_set).to receive(:persisted?).and_return(true) | ||
end | ||
|
||
context "on a collection" do | ||
subject { described_class.call(collection) } | ||
|
||
context "with a thumbnail" do | ||
let(:collection) { build(:collection, thumbnail_id: 's1784k724') } | ||
|
||
it { is_expected.to eq '/images/s1%2F78%2F4k%2F72%2Fs1784k724%2Ffiles%2F6185235a-79b2-4c29-8c24-4d6ad9b11470/full/!150,300/0/default.jpg' } | ||
end | ||
|
||
context "without a thumbnail" do | ||
let(:collection) { build(:collection) } | ||
|
||
it { is_expected.to start_with '/assets/collection-' } | ||
end | ||
end | ||
|
||
context "on a file set" do | ||
subject { described_class.call(file_set) } | ||
|
||
context "with an image" do | ||
it { is_expected.to eq '/images/s1%2F78%2F4k%2F72%2Fs1784k724%2Ffiles%2F6185235a-79b2-4c29-8c24-4d6ad9b11470/full/!150,300/0/default.jpg' } | ||
end | ||
end | ||
end |
2 changes: 1 addition & 1 deletion
2
...vices/iiif_thumbnail_path_service_spec.rb → .../iiif_work_thumbnail_path_service_spec.rb
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