Skip to content

Commit

Permalink
Display as much metadata as possible.
Browse files Browse the repository at this point in the history
Closes #47.
  • Loading branch information
tpendragon committed Mar 14, 2016
1 parent c232e6c commit 31a8dac
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/iiif_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def to_solr
solr_doc['content_metadata_image_iiif_info_ssm'] = manifest['thumbnail']['@id'].sub(/full.*/, 'info.json')
end
manifest['metadata'].each do |h|
solr_doc[field_name(h['label'].parameterize('_'))] = h['value'].map { |v| v["@value"] || v}
solr_doc[field_name(h['label'].parameterize('_'))] = h['value'].map { |v| v["@value"] || v }
end
solr_doc.merge! sidecar.to_solr
end
Expand Down
20 changes: 20 additions & 0 deletions app/models/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,24 @@ class SolrDocument
# and Blacklight::Document::SemanticFields#to_semantic_values
# Recommendation: Use field names from Dublin Core
use_extension(Blacklight::Document::DublinCore)

def display_fields
@display_fields ||= to_h.select do |x|
!x.start_with?("spotlight_") &&
!reserved_fields.include?(x) &&
!x.end_with?("bsi")
end
end

private

def reserved_fields
[
"full_title_ssim",
"id",
"_version_",
"timestamp",
"manifest_url_ssm"
]
end
end
7 changes: 7 additions & 0 deletions app/views/catalog/_show_default.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<%# default partial to display solr document fields in catalog show view -%>
<dl class="dl-horizontal dl-invert">
<% document.display_fields.each do |field_name, field| -%>
<dt class="blacklight-<%= field_name.parameterize %>"><%= render_document_show_field_label document, field: field_name.gsub("_ssim","") %></dt>
<dd class="blacklight-<%= field_name.parameterize %>"><%= field.join(", ") %></dd>
<% end -%>
</dl>
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended, and will default to
# `true` in RSpec 4.
mocks.verify_partial_doubles = true
# mocks.verify_partial_doubles = true
end

# The settings below are suggested to provide a good initial experience
Expand Down
17 changes: 17 additions & 0 deletions spec/views/catalog/_show_default.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'rails_helper'

RSpec.describe "catalog/_show_default.html.erb" do
let(:document) do
SolrDocument.new(id: "1",
author_ssim: ["The Doctor"],
publisher_ssim: ["The Byzantium", "The Silence"])
end
before do
allow(view).to receive(:blacklight_config).and_return(CatalogController.blacklight_config)
render "catalog/show_default", document: document
end
it "renders all possible metadata fields" do
expect(rendered).to have_content "The Doctor"
expect(rendered).to have_content "The Byzantium, The Silence"
end
end

0 comments on commit 31a8dac

Please sign in to comment.