Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render embedded documents using components. #3152

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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