Skip to content

Commit

Permalink
Add thumbnails to index view.
Browse files Browse the repository at this point in the history
  • Loading branch information
Trey Terrell committed Jun 23, 2015
1 parent b6790e9 commit fea9009
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app/helpers/thumbnail_helper.rb
@@ -0,0 +1,8 @@
module ThumbnailHelper
include Blacklight::CatalogHelper
# Had to override the thumbnail URL because the document doesn't directly have
# the relative URL, just the raw location of the thumbnail on disk.
def thumbnail_url document
document.derivative_paths[:thumbnail].relative_path.to_s
end
end
3 changes: 2 additions & 1 deletion app/models/blacklight_config.rb
Expand Up @@ -23,7 +23,8 @@ def configurations
ViewConfiguration.new(configuration),
DefaultConfiguration.new(configuration),
SearchFieldConfiguration.new(configuration),
ShowActions.new(configuration)
ShowActions.new(configuration),
ThumbnailConfiguration.new(configuration)
]
end

Expand Down
6 changes: 6 additions & 0 deletions app/models/blacklight_config/thumbnail_configuration.rb
@@ -0,0 +1,6 @@
class BlacklightConfig::ThumbnailConfiguration
pattr_initialize :configuration
def run
configuration.index.thumbnail_field = :workflow_metadata__thumbnail_path_ssim
end
end
29 changes: 29 additions & 0 deletions spec/views/catalog/_thumbnail_default.html.erb_spec.rb
@@ -0,0 +1,29 @@
require 'rails_helper'

RSpec.describe "catalog/_thumbnail_default.html.erb" do
let(:document) { SolrDocument.new(solr_hash) }
let(:solr_hash) {
{
:id => "1",
:workflow_metadata__thumbnail_path_ssim => [OregonDigital.derivative_injector.thumbnail_path("13")]
}
}
let(:blacklight_config) {
BlacklightConfig.new(GenericAsset, CatalogController.blacklight_config).configuration
}
describe "thumbnails" do
before do
allow(view).to receive(:blacklight_config).and_return(blacklight_config)
allow(view).to receive(:render_grouped_response?).and_return false
allow(view).to receive(:current_search_session).and_return nil
allow(view).to receive(:search_session).and_return({})
assign :response, double(start: 0)
render :partial => "catalog/thumbnail_default", :locals => {:document => document, :document_counter => 1}
end
context "when there's a thumbnail" do
it "should show it" do
expect(rendered).to have_selector "img[src='/media/thumbnails/3/1/13.jpg']"
end
end
end
end

0 comments on commit fea9009

Please sign in to comment.