Skip to content

Commit

Permalink
new document component subclass for show page
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Constabaris committed Feb 21, 2025
1 parent bb440f1 commit a92969e
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 27 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ARG RUBY_VERSION=3.1.6
FROM ruby:${RUBY_VERSION} AS app_bootstrap

RUN apt-get update && apt-get install -y nodejs vim less
RUN apt-get update && apt-get -y upgrade && apt-get install -y nodejs vim less

FROM app_bootstrap AS builder

Expand All @@ -11,7 +11,7 @@ COPY lib/trln_argon/version.rb /build/lib/trln_argon/version.rb

WORKDIR /build

RUN $(./bundler_config.rb path /gems) && bundle install -j $(nproc)
RUN $(./bundler_config.rb path /gems) && bundle config set with development test && bundle install -j $(nproc)

FROM app_bootstrap AS runnable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module TrlnArgon
class DocumentComponent < Blacklight::DocumentComponent
# DocumentComponent for use on Index (results) pages;
# replaces metadata slot with basic "subheader" content
class DocumentIndexComponent < Blacklight::DocumentComponent
def before_render
set_slot(
:metadata,
Expand Down
31 changes: 31 additions & 0 deletions app/components/trln_argon/document_show_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<%= content_tag @component,
id: @id,
data: {
'document-id': @document.id.to_s.parameterize,
'document-counter': @counter,
},
itemscope: true,
itemtype: @document.itemtype,
class: classes.flatten.join(' ') do %>
<%= header %>
<% if body.present? %>
<%= body %>
<% else %>
<div class="document-main-section">
<%= title %>
<%= render with_sub_header %>
<%= content %>
<%= render partial: 'show_thumbnail_default', locals: { document: @document } %>
<% metadata_sections.each do |section| %>
<%= section %>
<% end %>

<% partials.each do |partial| %>
<%= partial %>
<% end %>
</div>

<%= thumbnail %>
<% end %>
<%= footer %>
<% end %>
21 changes: 21 additions & 0 deletions app/components/trln_argon/document_show_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module TrlnArgon
# customization of document component for the show page
# subclass used for index page overwrites the `metadata` slot
# with the same content used here for the sub header.
class DocumentShowComponent < Blacklight::DocumentComponent
# easiest way to use this is to call
# <%= render with_sub_header %>
renders_one :sub_header, (lambda do
generate_sub_header
end)

# returns a component configured for the
# you will still need to call `#render`
def generate_sub_header
# to customize the fields shown in the sub header, set
# blacklight_config.show_sub_header_fields in controller override
fields = helpers.show_sub_header_presenter(@document).field_presenters
TrlnArgon::DocumentHeaderMetadataComponent.new(fields: fields)
end
end
end
37 changes: 14 additions & 23 deletions app/views/catalog/_show_main_content.html.erb
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
<%= render blacklight_config.view_config(:show).document_header_component.new(document: @document, search_context: @search_context, search_session: search_session) %>
<% @page_title = t('blacklight.search.show.title', document_title: document_presenter(@document).html_title, application_name: application_name).html_safe %>
<% content_for(:head) { render_link_rel_alternates } %>

<div class="row">
<div class="<%= show_tools_class %>">
<%= render :partial => 'show_tools' %>
</div>
</div>

<% @page_title = t('blacklight.search.show.title', document_title: document_presenter(@document).html_title, application_name: application_name).html_safe %>
<% content_for(:head) { render_link_rel_alternates } %>

<div id="document" class="document <%= render_document_class %>" itemscope itemtype="<%= @document.itemtype %>" data-document-id="<%= @document.id %>">
<div id="doc_<%= @document.id.to_s.parameterize %>">
<div class="row">
<div id="title-and-thumbnail" class="<%= show_main_content_heading_partials_class %>" aria-label="Title and thumbnail">
<!-- Title Display -->
<h1 class="document-title"><%= document_presenter(@document).html_title %></h1>
<%= render_document_partials @document, blacklight_config.view_config(:show).heading_partials %>
</div>
<div class="<%= show_main_content_partials_class %>">
<%= render_document_partials @document, blacklight_config.view_config(:show).partials %>
<div id="librarian-tools">
<!-- TODO: Placeholder based on wireframes. Not functional yet.
Should probably create a partial for this and wire it through
the blacklight partials config. -->

</div>
</div>
</div>
</div>
</div>
<% document_component = blacklight_config.view_config(:show).document_component -%>
<%= render (document_component).new(document_component.collection_parameter => document_presenter(@document), component: :div, show: true, partials: blacklight_config.view_config(:show).partials) do |component| %>
<% component.with_title(as: 'h1', classes: '', link_to_document: false, actions: false) %>
<% component.with_footer do %>
<% if @document.respond_to?(:export_as_openurl_ctx_kev) %>
<!-- COinS, for Zotero among others. -->
<span class="Z3988" title="<%= @document.export_as_openurl_ctx_kev(document_presenter(@document).display_type) %>"></span>
<% end %>
<% end %>
<% end %>

10 changes: 9 additions & 1 deletion lib/trln_argon/controller_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,17 @@ module ControllerOverride

# Sets the sidebar component for the index view in the TrlnArgon configuration.
config.index.sidebar_component = TrlnArgon::Search::SidebarComponent
config.index.document_component = TrlnArgon::DocumentComponent

# refinement that replaces "metadata" slot with simplified
# document subheader content
config.index.document_component = TrlnArgon::DocumentIndexComponent
config.index.constraints_component = TrlnArgon::ConstraintsComponent

# refinement that adds a sub header slot that matches the simplified
# subheader in DocumentIndexComponent but which also keeps
# the metadata content for full display
config.show.document_component = TrlnArgon::DocumentShowComponent

# Use Solr search requestHandler for search requests
config.http_method = :get
config.solr_path = :select
Expand Down

0 comments on commit a92969e

Please sign in to comment.