blacklight-gallery 1.7.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +45 -0
  3. data/README.md +1 -1
  4. data/app/assets/images/blacklight/pause_slideshow.svg +1 -0
  5. data/app/assets/images/blacklight/start_slideshow.svg +1 -0
  6. data/app/assets/javascripts/blacklight_gallery/default.js +0 -1
  7. data/app/assets/javascripts/blacklight_gallery/masonry.js +1 -1
  8. data/app/assets/javascripts/blacklight_gallery/osd_viewer.js +1 -1
  9. data/app/assets/javascripts/blacklight_gallery/slideshow.js +11 -8
  10. data/app/assets/stylesheets/blacklight_gallery/_gallery.scss +11 -17
  11. data/app/assets/stylesheets/blacklight_gallery/_masonry.scss +55 -24
  12. data/app/assets/stylesheets/blacklight_gallery/_osd_viewer.scss +2 -2
  13. data/app/assets/stylesheets/blacklight_gallery/_slideshow.scss +11 -3
  14. data/app/components/blacklight/gallery/document_component.html.erb +20 -0
  15. data/app/components/blacklight/gallery/document_component.rb +11 -0
  16. data/app/components/blacklight/gallery/slideshow_component.html.erb +12 -0
  17. data/app/components/blacklight/gallery/slideshow_component.rb +40 -0
  18. data/app/components/blacklight/gallery/slideshow_preview_component.html.erb +5 -0
  19. data/app/components/blacklight/gallery/slideshow_preview_component.rb +28 -0
  20. data/app/helpers/blacklight/gallery_helper.rb +0 -38
  21. data/app/models/concerns/blacklight/gallery/openseadragon_solr_document.rb +1 -1
  22. data/app/views/catalog/_document_gallery.html.erb +4 -3
  23. data/app/views/catalog/_document_masonry.html.erb +2 -3
  24. data/app/views/catalog/_document_slideshow.html.erb +26 -9
  25. data/app/views/catalog/_openseadragon_default.html.erb +14 -15
  26. data/app/views/catalog/_slideshow_modal.html.erb +2 -2
  27. data/blacklight-gallery.gemspec +4 -4
  28. data/config/locales/blacklight-gallery.ar.yml +8 -4
  29. data/config/locales/blacklight-gallery.en.yml +6 -2
  30. data/config/locales/blacklight-gallery.es.yml +3 -2
  31. data/config/locales/blacklight-gallery.fr.yml +3 -2
  32. data/config/locales/blacklight-gallery.it.yml +3 -2
  33. data/config/locales/blacklight-gallery.pt-BR.yml +3 -0
  34. data/config/locales/blacklight-gallery.zh.yml +3 -2
  35. data/lib/blacklight/gallery/engine.rb +0 -2
  36. data/lib/blacklight/gallery/version.rb +1 -1
  37. data/lib/generators/blacklight_gallery/install_generator.rb +10 -3
  38. data/lib/generators/blacklight_gallery/templates/blacklight_gallery.js +2 -1
  39. data/spec/components/blacklight/gallery/document_component_spec.rb +46 -0
  40. data/spec/components/blacklight/gallery/slideshow_component_spec.rb +67 -0
  41. data/spec/features/gallery_spec.rb +3 -4
  42. data/spec/features/masonry_spec.rb +2 -3
  43. data/spec/features/slideshow_spec.rb +0 -2
  44. data/spec/models/concerns/openseadragon_solr_document_spec.rb +1 -1
  45. data/spec/spec_helper.rb +4 -11
  46. data/spec/views/catalog/_document_slideshow.html.erb_spec.rb +15 -5
  47. metadata +45 -39
  48. data/.travis.yml +0 -21
  49. data/app/views/catalog/_grid_slideshow.html.erb +0 -11
  50. data/app/views/catalog/_index_gallery.html.erb +0 -14
  51. data/app/views/catalog/_index_masonry.html.erb +0 -8
  52. data/app/views/catalog/_index_masonry_default.html.erb +0 -1
  53. data/app/views/catalog/_index_slideshow.html.erb +0 -11
  54. data/app/views/catalog/_slideshow.html.erb +0 -15
  55. data/spec/helpers/blacklight/gallery_helper_spec.rb +0 -110
  56. data/spec/views/catalog/_index_gallery.html.erb_spec.rb +0 -22
  57. data/spec/views/catalog/_index_masonry.html.erb_spec.rb +0 -34
@@ -1,42 +1,4 @@
1
1
  module Blacklight
2
2
  module GalleryHelper
3
- def render_gallery_collection documents
4
- index = -1
5
- documents.map do |object|
6
- index += 1
7
- template = gallery_wrapper_template(object)
8
- template.render(self, {document: object, document_counter: index}) if template
9
-
10
- end.join().html_safe
11
- end
12
-
13
- def render_slideshow_tag(document, image_options = {}, url_options = {})
14
- if blacklight_config.view_config(document_index_view_type).slideshow_method
15
- method_name = blacklight_config.view_config(document_index_view_type).slideshow_method
16
- send(method_name, document, image_options)
17
- elsif blacklight_config.view_config(document_index_view_type).slideshow_field
18
- url = slideshow_image_url(document)
19
-
20
- image_tag url, image_options if url.present?
21
- elsif has_thumbnail?(document)
22
- render_thumbnail_tag(document, image_options, url_options.reverse_merge(suppress_link: true))
23
- end
24
- end
25
-
26
- def slideshow_image_url(document)
27
- if document.has? blacklight_config.view_config(document_index_view_type).slideshow_field
28
- document.first(blacklight_config.view_config(document_index_view_type).slideshow_field)
29
- end
30
- end
31
-
32
- def gallery_wrapper_template(object)
33
- format = document_partial_name(object, nil)
34
- ['index_gallery_%{format}_wrapper', 'index_gallery'].each do |str|
35
- partial = str % { format: format }
36
- logger.debug "Looking for gallery document wrapper #{partial}"
37
- template = lookup_context.find_all(partial, lookup_context.prefixes, true, [:document, :document_counter], {}).first
38
- return template if template
39
- end
40
- end
41
3
  end
42
4
  end
@@ -1,6 +1,6 @@
1
1
  module Blacklight::Gallery::OpenseadragonSolrDocument
2
2
  def to_openseadragon(view_config = nil)
3
- return unless view_config.try(:tile_source_field) &&
3
+ return unless view_config&.tile_source_field &&
4
4
  fetch(view_config.tile_source_field, nil)
5
5
  Array(fetch(view_config.tile_source_field))
6
6
  end
@@ -1,4 +1,5 @@
1
- <% # container for all documents in index view -%>
2
- <div id="documents" class="row gallery">
3
- <%= render_gallery_collection documents %>
1
+ <div class="container">
2
+ <div id="documents" class="<%= (Array(blacklight_config.view_config(document_index_view_type).classes || 'row-cols-2 row-cols-md-3') + ["row documents-#{document_index_view_type}"]).join(' ') %>">
3
+ <%= render documents, as: :document %>
4
+ </div>
4
5
  </div>
@@ -1,4 +1,3 @@
1
- <% # container for all documents in index view -%>
2
- <div id="documents" class="row" data-behavior="masonry-gallery">
3
- <%= render collection: documents, as: :document, partial: 'index_masonry', locals: {count: documents.count} %>
1
+ <div id="documents" class="<%= (Array(blacklight_config.view_config(document_index_view_type).classes) + ["documents-#{document_index_view_type}"]).join(' ') %>">
2
+ <%= render documents, as: :document %>
4
3
  </div>
@@ -1,14 +1,31 @@
1
- <% # container for all documents in slideshow view -%>
2
- <div id="documents" class="row slideshow-documents">
3
- <div class="info w-100">
4
- <h3><%= t(:'blacklight_gallery.catalog.document_slideshow.header') %></h3>
5
- </div>
6
-
1
+ <div id="documents" class="<%= (Array(blacklight_config.view_config(document_index_view_type).classes) + ["documents-#{document_index_view_type}"]).join(' ') %>">
7
2
  <div class="grid">
8
- <%= render collection: documents, as: :document, partial: 'grid_slideshow' %>
3
+ <%= render((blacklight_config.view_config(document_index_view_type).preview_component || Blacklight::Gallery::SlideshowPreviewComponent).with_collection(documents)) %>
9
4
  </div>
10
5
 
11
- <%= render layout: 'slideshow_modal', locals: {documents: documents} do %>
12
- <%= render partial: 'slideshow', locals: {documents: documents} %>
6
+ <%= render layout: 'slideshow_modal' do %>
7
+ <div id="slideshow" class="slideshow-presenter">
8
+ <!-- Wrapper for slides -->
9
+ <div class="slideshow-inner">
10
+ <%= render documents, as: :document %>
11
+ </div>
12
+
13
+ <!-- Controls -->
14
+ <a class="left carousel-control prev" href="#slideshow" data-slide="prev">
15
+ <%= blacklight_icon 'chevron_left', { additional_options: { label_context: 'previous_image' }} %>
16
+ </a>
17
+ <a class="right carousel-control next" href="#slideshow" data-slide="next">
18
+ <%= blacklight_icon 'chevron_right', { additional_options: { label_context: 'next_image' }} %>
19
+ </a>
20
+
21
+ <div class="controls text-center">
22
+ <button class="btn btn-sm btn-link" data-behavior="pause-slideshow" aria-label="<%= t('blacklight_gallery.catalog.slideshow.pause') %>">
23
+ <%= blacklight_icon 'pause_slideshow' %>
24
+ </button>
25
+ <button class="btn btn-sm btn-link" data-behavior="start-slideshow" aria-label="<%= t('blacklight_gallery.catalog.slideshow.start') %>">
26
+ <%= blacklight_icon 'start_slideshow' %>
27
+ </button>
28
+ </div>
29
+ </div>
13
30
  <% end %>
14
31
  </div>
@@ -23,21 +23,20 @@
23
23
  <% count = Array(image).length %>
24
24
  <div class="openseadragon-container <%= osd_container_class %>">
25
25
  <div class="osd-toolbar row">
26
- <% if count > 1 %>
27
- <% osd_config = osd_config_referencestrip.merge(osd_config) %>
28
-
29
- <div class="col-md-6 pagination">
30
- <a id="osd-previous"><%= blacklight_icon('chevron_left') %></a>
31
- <span id="osd-page">1</span> of <%= count %>
32
- <a id="osd-next"><%= blacklight_icon('chevron_right') %></a>
33
- </div>
34
- <% end %>
35
- <div class="col-md-6 controls">
36
- <a id="osd-zoom-in"><%= blacklight_icon('add_circle') %></a>
37
- <a id="osd-zoom-out"><%= blacklight_icon('remove_circle') %></a>
38
- <a id="osd-home"><%= blacklight_icon('resize_small') %></a>
39
- <a id="osd-full-page"><%= blacklight_icon('custom_fullscreen') %></a>
40
- </div>
26
+ <div class="col-md-6 pagination">
27
+ <% if count > 1 %>
28
+ <% osd_config = osd_config_referencestrip.merge(osd_config) %>
29
+ <a id="osd-previous"><%= blacklight_icon('chevron_left') %></a>
30
+ <span id="osd-page">1</span> of <%= count %>
31
+ <a id="osd-next"><%= blacklight_icon('chevron_right') %></a>
32
+ <% end %>
33
+ </div>
34
+ <div class="col-md-6 controls">
35
+ <a id="osd-zoom-in"><%= blacklight_icon('add_circle') %></a>
36
+ <a id="osd-zoom-out"><%= blacklight_icon('remove_circle') %></a>
37
+ <a id="osd-home"><%= blacklight_icon('resize_small') %></a>
38
+ <a id="osd-full-page"><%= blacklight_icon('custom_fullscreen') %></a>
39
+ </div>
41
40
  </div>
42
41
  <%= openseadragon_picture_tag image, class: 'osd-image row', data: { openseadragon: osd_config } %>
43
42
  </div>
@@ -3,8 +3,8 @@
3
3
  <div class="modal-dialog modal-xl">
4
4
  <div class="modal-content">
5
5
  <div class="modal-header">
6
- <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
7
- ×
6
+ <button type="button" class="blacklight-modal-close close" data-dismiss="modal" aria-label="<%= t('blacklight.modal.close') %>">
7
+ <span aria-hidden="true">&times;</span>
8
8
  </button>
9
9
  </div>
10
10
  <div class="modal-body">
@@ -17,10 +17,9 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_dependency "rails", '~> 5.1'
21
- spec.add_dependency 'blacklight', '~> 7.0'
20
+ spec.add_dependency "rails", '>= 5.1', '< 7'
21
+ spec.add_dependency 'blacklight', '~> 7.12'
22
22
  spec.add_dependency "bootstrap", "~> 4.0"
23
- spec.add_dependency "openseadragon", ">= 0.2.0"
24
23
 
25
24
  spec.add_development_dependency "rake"
26
25
  spec.add_development_dependency 'sqlite3'
@@ -31,6 +30,7 @@ Gem::Specification.new do |spec|
31
30
  spec.add_development_dependency "solr_wrapper"
32
31
  spec.add_development_dependency "engine_cart", "~> 2.0"
33
32
  spec.add_development_dependency "capybara"
34
- spec.add_development_dependency 'chromedriver-helper'
33
+ spec.add_development_dependency 'webdrivers'
34
+ spec.add_development_dependency 'rexml' # pending https://github.com/SeleniumHQ/selenium/issues/9001
35
35
  spec.add_development_dependency "selenium-webdriver", '>= 3.13.1'
36
36
  end
@@ -1,15 +1,19 @@
1
1
  ar:
2
2
  blacklight:
3
+ icon:
4
+ chevron_left_previous_image: 'الصورة السابقة'
5
+ chevron_right_next_image: 'الصورة التالية'
3
6
  search:
4
7
  view:
5
8
  gallery: "معرض الصور"
6
- slideshow: "عرض متتابع"
9
+ slideshow: "عرض الصور"
7
10
  masonry: "عرض الصور كمجموعة"
8
11
  blacklight_gallery:
9
12
  catalog:
10
13
  grid_slideshow:
11
- missing_image: "صورة غير موجودة"
12
- document_slideshow:
13
- header: "حدد صورة لبدء العرض المتتابع"
14
+ missing_image: 'غير موجود'
14
15
  modal_slideshow:
15
16
  counter: "%{counter} من %{count}"
17
+ slideshow:
18
+ pause: وقف عرض الصور
19
+ start: بدء عرض الصور
@@ -1,5 +1,8 @@
1
1
  en:
2
2
  blacklight:
3
+ icon:
4
+ chevron_left_previous_image: 'previous image'
5
+ chevron_right_next_image: 'next image'
3
6
  search:
4
7
  view:
5
8
  gallery: "Gallery"
@@ -9,7 +12,8 @@ en:
9
12
  catalog:
10
13
  grid_slideshow:
11
14
  missing_image: 'Missing'
12
- document_slideshow:
13
- header: "Select an image to start the slideshow"
14
15
  modal_slideshow:
15
16
  counter: "%{counter} of %{count}"
17
+ slideshow:
18
+ pause: Pause slideshow
19
+ start: Start slideshow
@@ -9,7 +9,8 @@ es:
9
9
  catalog:
10
10
  grid_slideshow:
11
11
  missing_image: No hay nada
12
- document_slideshow:
13
- header: Selecione una imagen para empezar
14
12
  modal_slideshow:
15
13
  counter: "%{counter} de %{count}"
14
+ slideshow:
15
+ pause: Pausa la Diapositivas
16
+ start: Empezar la Diapositivas
@@ -9,7 +9,8 @@ fr:
9
9
  catalog:
10
10
  grid_slideshow:
11
11
  missing_image: 'Image manquante'
12
- document_slideshow:
13
- header: "Sélectionnez une image pour lancer le diaporama"
14
12
  modal_slideshow:
15
13
  counter: "%{counter} de %{count}"
14
+ slideshow:
15
+ pause: Suspendre le diaporama
16
+ start: Lancer le diaporama
@@ -9,7 +9,8 @@ it:
9
9
  catalog:
10
10
  grid_slideshow:
11
11
  missing_image: 'Mancante'
12
- document_slideshow:
13
- header: "Seleziona un immagine per l'avvio del slideshow"
14
12
  modal_slideshow:
15
13
  counter: "%{counter} di %{count}"
14
+ slideshow:
15
+ pause: Pausa del slideshow
16
+ start: Avvia del slideshow
@@ -13,3 +13,6 @@ pt-BR:
13
13
  header: "Selecione uma imagem para iniciar a apresentação de slides"
14
14
  modal_slideshow:
15
15
  counter: "%{counter} de %{count}"
16
+ slideshow:
17
+ pause: Pausar a apresentação de slides
18
+ start: Iniciar a apresentação de slides
@@ -9,7 +9,8 @@ zh:
9
9
  catalog:
10
10
  grid_slideshow:
11
11
  missing_image: '图片缺失'
12
- document_slideshow:
13
- header: '选择图片启动幻灯展示'
14
12
  modal_slideshow:
15
13
  counter: "%{counter} of %{count}"
14
+ slideshow:
15
+ pause: 暂停幻灯片展示
16
+ start: 启动幻灯片展示
@@ -3,8 +3,6 @@ require 'blacklight'
3
3
  module Blacklight
4
4
  module Gallery
5
5
  class Engine < Rails::Engine
6
- require 'openseadragon'
7
-
8
6
  end
9
7
  end
10
8
  end
@@ -1,5 +1,5 @@
1
1
  module Blacklight
2
2
  module Gallery
3
- VERSION = "1.7.0"
3
+ VERSION = "3.0.0"
4
4
  end
5
5
  end
@@ -8,13 +8,18 @@ module BlacklightGallery
8
8
  def assets
9
9
  copy_file "blacklight_gallery.css.scss", "app/assets/stylesheets/blacklight_gallery.css.scss"
10
10
  copy_file "blacklight_gallery.js", "app/assets/javascripts/blacklight_gallery.js"
11
+
12
+ insert_into_file "app/assets/javascripts/application.js", after: '//= require blacklight/blacklight' do
13
+ "\n//= require blacklight_gallery"
14
+ end
11
15
  end
12
16
 
13
17
  def configuration
14
18
  inject_into_file 'app/controllers/catalog_controller.rb', after: "configure_blacklight do |config|" do
15
- "\n config.view.gallery.partials = [:index_header, :index]" \
16
- "\n config.view.masonry.partials = [:index]" \
17
- "\n config.view.slideshow.partials = [:index]\n\n" \
19
+ "\n config.view.gallery.document_component = Blacklight::Gallery::DocumentComponent" \
20
+ "\n # config.view.gallery.classes = 'row-cols-2 row-cols-md-3'" \
21
+ "\n config.view.masonry.document_component = Blacklight::Gallery::DocumentComponent" \
22
+ "\n config.view.slideshow.document_component = Blacklight::Gallery::SlideshowComponent" \
18
23
  "\n config.show.tile_source_field = :content_metadata_image_iiif_info_ssm" \
19
24
  "\n config.show.partials.insert(1, :openseadragon)"
20
25
  end
@@ -27,6 +32,8 @@ module BlacklightGallery
27
32
  end
28
33
 
29
34
  def add_openseadragon
35
+ gem "openseadragon", ">= 0.2.0"
36
+ Bundler.with_clean_env { run 'bundle install' }
30
37
  generate 'openseadragon:install'
31
38
  end
32
39
  end
@@ -1 +1,2 @@
1
- //= require blacklight_gallery/default
1
+ //= require blacklight_gallery/default
2
+ //= require blacklight_gallery/osd_viewer
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Blacklight::Gallery::DocumentComponent, type: :component do
6
+ subject(:component) { described_class.new(document: document, **attr) }
7
+
8
+ let(:attr) { {} }
9
+ let(:view_context) { controller.view_context }
10
+ let(:render) do
11
+ component.render_in(view_context)
12
+ end
13
+
14
+ let(:rendered) do
15
+ Capybara::Node::Simple.new(render)
16
+ end
17
+
18
+ let(:document) do
19
+ SolrDocument.new(
20
+ id: 'x',
21
+ thumbnail_path_ss: 'http://example.com/image.jpg',
22
+ title_tsim: 'This is my document title'
23
+ )
24
+ end
25
+
26
+ let(:blacklight_config) do
27
+ CatalogController.blacklight_config.deep_copy.tap do |config|
28
+ config.track_search_session = false
29
+ config.index.thumbnail_field = 'thumbnail_path_ss'
30
+ end
31
+ end
32
+
33
+ before do
34
+ allow(controller).to receive(:blacklight_config).and_return(blacklight_config)
35
+ allow(view_context).to receive(:current_search_session).and_return(nil)
36
+ allow(view_context).to receive(:search_session).and_return({})
37
+
38
+ # dumb hack to get our stubbing into the thumbnail component
39
+ allow(controller).to receive(:view_context).and_return(view_context)
40
+ end
41
+
42
+ it 'has a thumbnail and caption' do
43
+ expect(rendered).to have_selector '.document-thumbnail img'
44
+ expect(rendered).to have_selector '.caption', text: 'This is my document title'
45
+ end
46
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Blacklight::Gallery::SlideshowComponent, type: :component do
6
+ subject(:component) { described_class.new(document: document, **attr) }
7
+
8
+ let(:attr) { {} }
9
+ let(:view_context) { controller.view_context }
10
+ let(:render) do
11
+ component.render_in(view_context)
12
+ end
13
+
14
+ let(:rendered) do
15
+ Capybara::Node::Simple.new(render)
16
+ end
17
+
18
+ let(:blacklight_config) { Blacklight::Configuration.new }
19
+
20
+ before do
21
+ allow(view_context).to receive(:blacklight_config).and_return(blacklight_config)
22
+ end
23
+
24
+ describe '#slideshow_tag' do
25
+ subject { rendered }
26
+
27
+ let(:document) { SolrDocument.new({}) }
28
+
29
+ context 'with a slideshow method' do
30
+ let(:blacklight_config) { Blacklight::Configuration.new.tap { |config| config.index.slideshow_method = :xyz } }
31
+
32
+ it 'calls the provided slideshow method' do
33
+ expect(view_context).to receive_messages(xyz: 'some-slideshow')
34
+ expect(rendered).to have_text 'some-slideshow'
35
+ end
36
+
37
+ it 'does not render an image if the method returns nothing' do
38
+ expect(view_context).to receive_messages(xyz: nil)
39
+ expect(rendered).not_to have_selector 'img'
40
+ end
41
+ end
42
+
43
+ context 'with a field' do
44
+ let(:blacklight_config) { Blacklight::Configuration.new.tap { |config| config.index.slideshow_field = :xyz } }
45
+ let(:document) { SolrDocument.new({ xyz: 'http://example.com/some.jpg' }) }
46
+
47
+ it { is_expected.to have_selector 'img[src="http://example.com/some.jpg"]' }
48
+
49
+ context 'without data in the field' do
50
+ let(:document) { SolrDocument.new({}) }
51
+
52
+ it { is_expected.not_to have_selector 'img' }
53
+ end
54
+ end
55
+
56
+ context 'with nothing configured' do
57
+ it { is_expected.not_to have_selector 'img' }
58
+ end
59
+
60
+ context 'falling back to a thumbnail' do
61
+ let(:blacklight_config) { Blacklight::Configuration.new.tap { |config| config.index.thumbnail_field = :xyz } }
62
+ let(:document) { SolrDocument.new({ xyz: 'http://example.com/thumb.jpg' }) }
63
+
64
+ it { is_expected.to have_selector 'img[src="http://example.com/thumb.jpg"]' }
65
+ end
66
+ end
67
+ end