This repository has been archived by the owner on May 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generate thumbnail paths for geo works
- Loading branch information
1 parent
08611d6
commit 73acbcf
Showing
6 changed files
with
113 additions
and
2 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,6 @@ | ||
module GeoConcernsHelper | ||
def geo_concerns_thumbnail_path(document, image_options = {}) | ||
url = thumbnail_url(document) | ||
image_tag url, image_options if url.present? | ||
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,29 @@ | ||
module ThumbnailHelper | ||
# Generates a thumbnail path for the various work and fileset types. | ||
# @param document [SolrDocument, ShowPresenter] an object's solr document or show presenter | ||
# @param image_options [Hash] | ||
# @return [String] thumbnail tag | ||
def plum_thumbnail_path(document, image_options = {}) | ||
value = send(plum_thumbnail_method(document), document, image_options) | ||
link_to_document document, value if value | ||
end | ||
|
||
# Gets the correct thumbnail path generation method | ||
# for work or fileset type. | ||
# @param document [SolrDocument, ShowPresenter] an object's solr document or show presenter | ||
# @return [Symbol] | ||
def plum_thumbnail_method(document) | ||
document = document.solr_document if document.respond_to?(:solr_document) | ||
class_name = document.to_model.class_name | ||
|
||
if document['geo_mime_type_tesim'] | ||
# geo fileset | ||
:geo_concerns_thumbnail_path | ||
elsif ["ImageWork", "RasterWork", "VectorWork"].include?(class_name) | ||
# geo work | ||
:geo_concerns_thumbnail_path | ||
else | ||
:iiif_thumbnail_path | ||
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,14 @@ | ||
FactoryGirl.define do | ||
factory :vector_work do | ||
title ["Test title"] | ||
visibility Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC | ||
|
||
transient do | ||
user { FactoryGirl.create(:user) } | ||
end | ||
|
||
after(:build) do |work, evaluator| | ||
work.apply_depositor_metadata(evaluator.user.user_key) | ||
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,61 @@ | ||
require 'rails_helper' | ||
|
||
describe ThumbnailHelper do | ||
subject { helper } | ||
|
||
before do | ||
allow(subject).to receive(:thumbnail_url).and_return('fileset.jpg') | ||
end | ||
|
||
context 'when document is a geo FileSet' do | ||
let(:file_set) { FactoryGirl.create(:file_set, geo_mime_type: 'application/vnd.geo+json') } | ||
let(:document) do | ||
FileSetPresenter.new( | ||
SolrDocument.new( | ||
file_set.to_solr | ||
), nil | ||
) | ||
end | ||
|
||
it 'returns a path to the thumbnail image' do | ||
expect(subject).to receive(:link_to_document).with(document, /<img src=\"\/images\/fileset.jpg/) | ||
subject.plum_thumbnail_path(document) | ||
end | ||
end | ||
|
||
context 'when document is a VectorWork' do | ||
let(:vector_work) { FactoryGirl.create(:vector_work) } | ||
let(:document) do | ||
GeoConcerns::VectorWorkShowPresenter.new( | ||
SolrDocument.new( | ||
vector_work.to_solr | ||
), nil | ||
) | ||
end | ||
|
||
it 'returns a path to the thumbnail image' do | ||
expect(subject).to receive(:link_to_document).with(document, /<img src=\"\/images\/vectorwork.jpg/) | ||
subject.plum_thumbnail_path(document) | ||
end | ||
end | ||
|
||
context 'when document is a ScannedResource' do | ||
let(:scanned_resource) { FactoryGirl.create(:scanned_resource) } | ||
let(:document) do | ||
ScannedResourceShowPresenter.new( | ||
SolrDocument.new( | ||
scanned_resource.to_solr | ||
), nil | ||
) | ||
end | ||
|
||
before do | ||
allow(document).to receive(:thumbnail_id).and_return('abcdefg') | ||
end | ||
|
||
it 'returns a path to the iiif thumbnail' do | ||
expect(subject).to receive(:link_to_document).with(document, /ab%2Fcd%2Fef%2Fg-intermediate_file.jp2/) | ||
subject.plum_thumbnail_path(document) | ||
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