Skip to content

Commit

Permalink
Merge pull request #3152 from projectblacklight/embed-component
Browse files Browse the repository at this point in the history
Render embedded documents using components.
  • Loading branch information
corylown authored Sep 24, 2024
2 parents 40f023b + 4d15c47 commit 9e549b3
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% if body.present? %>
<%= body %>
<% elsif partials? %>
<% partials.each do |partial| %>
<%= partial %>
<% end %>
<% elsif embed? %>
<%= embed %>
<% elsif thumbnail? %>
<%= thumbnail %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

# Render an document suitable for embedding on a feature page.
module Spotlight
class SolrDocumentLegacyEmbedComponent < Blacklight::DocumentComponent
end
end
5 changes: 4 additions & 1 deletion app/models/spotlight/blacklight_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ def blacklight_config

config.view.embed!
# This is blacklight-gallery's openseadragon partial
config.view.embed.partials ||= ['openseadragon']
unless config.view.embed.document_component
config.view.embed.partials ||= ['openseadragon']
config.view.embed.document_component = Spotlight::SolrDocumentLegacyEmbedComponent
end
config.view.embed.if = false

# blacklight-gallery requires tile_source_field
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="box" data-id="<%= document.id %>">
<% view_config = blacklight_config.view_config(:embed) %>
<%= render (view_config.document_component || Spotlight::SolrDocumentLegacyEmbedComponent).new((Blacklight.version > '8.0' ? :document : :presenter) => document_presenter(document), counter: nil) do |component| %>
<% component.with_partial do %>
<%= render_document_partials document, view_config.partials, component: component, document_counter: nil, view_config: view_config, block: local_assigns[:block], **(view_config.locals) %>
<% end if view_config&.partials&.any? %>
<% end %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@
<%# Render the openseadragon viewer from blacklight-gallery.
# Settings in blacklight_configuration.rb %>
<% solr_documents_embed_block.each_document do |block_options, document| %>
<div class="box" data-id="<%= document.id %>">
<% view_config = blacklight_config.view_config(:embed) %>
<%= render_document_partials document, view_config.partials, (view_config.locals || {}).reverse_merge(block: solr_documents_embed_block, view_config: view_config) %>
</div>
<% end %>
</div>
<%= render '/spotlight/sir_trevor/blocks/embedded_document', document: document, block: solr_documents_embed_block %>
<% end %>
</div>
</div>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion blacklight-spotlight.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ these collections.)
s.add_dependency 'activejob-status'
s.add_dependency 'acts-as-taggable-on', '>= 5.0', '< 12'
s.add_dependency 'autoprefixer-rails'
s.add_dependency 'blacklight', '>= 7.18', '< 9'
s.add_dependency 'blacklight', '>= 7.19', '< 9'
s.add_dependency 'blacklight-gallery', '>= 3.0', '< 5'
s.add_dependency 'bootstrap_form', '>= 4.1', '< 6'
s.add_dependency 'breadcrumbs_on_rails', '>= 3.0', '< 5'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@
let(:doc) { blacklight_config.document_model.new(id: 1) }
let(:blacklight_config) do
Blacklight::Configuration.new do |config|
config.view.embed(partials: %w[a b c], locals: { a: 1 })
config.view.embed(
document_component: Spotlight::SolrDocumentLegacyEmbedComponent,
partials: %w[a b c],
locals: { a: 1 }
)
end
end
let(:stub_presenter) do
instance_double(Blacklight::DocumentPresenter, heading: 'blah', thumbnail: thumbnail_presenter)
instance_double(Blacklight::DocumentPresenter, document: doc, heading: 'blah',
thumbnail: thumbnail_presenter,
view_config: blacklight_config.view.embed,
field_presenters: [],
display_type: nil)
end

let(:thumbnail_presenter) { instance_double(Blacklight::ThumbnailPresenter, exists?: true, thumbnail_tag: 'thumb') }
Expand Down

0 comments on commit 9e549b3

Please sign in to comment.