Skip to content

Commit

Permalink
Merge pull request #1495 from projectblacklight/1453-indexentry-tables
Browse files Browse the repository at this point in the history
Format EAD index/indexentry and EAD table elements as HTML tables. Cl…
  • Loading branch information
dl-maura authored Dec 15, 2023
2 parents d4e1b89 + 2cb8537 commit b281049
Show file tree
Hide file tree
Showing 11 changed files with 220 additions and 6 deletions.
10 changes: 5 additions & 5 deletions app/assets/stylesheets/arclight/modules/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
padding-bottom: $spacer;
margin-bottom: $spacer * .75;
width: 100%;

$bent-arrow: "data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='15'><path fill-rule='evenodd' d='M1.5 1.5A.5.5 0 0 0 1 2v4.8a2.5 2.5 0 0 0 2.5 2.5h9.793l-3.347 3.346a.5.5 0 0 0 .708.708l4.2-4.2a.5.5 0 0 0 0-.708l-4-4a.5.5 0 0 0-.708.708L13.293 8.3H3.5A1.5 1.5 0 0 1 2 6.8V2a.5.5 0 0 0-.5-.5z'></path></svg>";

.breadcrumb {
Expand Down Expand Up @@ -131,11 +131,11 @@
}
}

svg.bi {
svg.bi {
vertical-align: text-bottom;
color: $light-icon-color;
}

.dropdown-item svg.bi {
color: $dark-icon-color;
}
Expand All @@ -144,7 +144,7 @@
.bookmark-toggle {
display: inline;
margin-left: 1em;

.toggle-bookmark {
display: inline;
margin-bottom: 0;
Expand Down Expand Up @@ -177,7 +177,7 @@ dl.deflist dt {
text-align: left;
}

.chronlist-head, .list-head {
.chronlist-head, .list-head, .index-head, .table-head {
caption-side: top;
font-size: 1.25rem;
font-weight: 500;
Expand Down
62 changes: 61 additions & 1 deletion app/helpers/arclight/ead_format_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,25 @@ def transform_ead_to_html(value)
.scrub!(:strip).to_html
end

# rubocop:disable Metrics/AbcSize
def ead_to_html_scrubber
Loofah::Scrubber.new do |node|
format_render_attributes(node) if node.attr('render').present?
convert_to_span(node) if CONVERT_TO_SPAN_TAGS.include? node.name
convert_to_br(node) if CONVERT_TO_BR_TAG.include? node.name
format_links(node) if %w[extptr extref extrefloc ptr ref].include? node.name
format_lists(node) if %w[list chronlist].include? node.name
format_indexes(node) if node.name == 'index'
format_tables(node) if node.name == 'table'
node
end
end
# rubocop:enable Metrics/AbcSize

# Tags that should be converted to <span> tags because of formatting conflicts between XML and HTML
CONVERT_TO_SPAN_TAGS = ['title'].freeze
# Tags that should be converted to <span> tags because of formatting conflicts between XML and HTML

# Tags that should be converted to HTML <br/> tags
CONVERT_TO_BR_TAG = ['lb'].freeze

def convert_to_span(node)
Expand Down Expand Up @@ -245,5 +250,60 @@ def format_chronlist_events(eventgrps, single_events, multi_events)
end
multi_events.each { |event_node| event_node.name = 'div' }
end

# Format EAD <index> elements
def format_indexes(node)
index_head = node.at_css('head')
index_head&.name = 'h3'
index_head&.add_class('index-head')
index_head['id'] = ['index-', index_head.text].join.parameterize if index_head.present?
format_indexentries(node)
node.name = 'div'
end

# Grab all of the <indexentry> children as a nodeset, move them into
# a <table>, wrap each entry in a <tr> & each value in a <td>.
def format_indexentries(node)
indexentries = node.css('indexentry')
return if indexentries.blank?

indexentries.first.previous = '<table class="table indexentries" />'
indexentries.map do |i|
i.parent = node.at_css('table.table.indexentries')
i.wrap('<tr/>')
i.element_children.map { |c| c.wrap('<td/>') }
# Assuming two columns in an index, create a blank cell for entries
# with a missing value.
i.add_child('<td/>') if i.element_children.count == 1
end
end

# Format EAD <table> elements, converting <tgroup> to HTML <table>.
# Ignoring <colspec>, @colname, @colwidth complex rendering
# logic for now.
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
def format_tables(node)
node.remove_attribute('frame')
node.name = 'div' if node.css('tgroup').present?
format_table_head(node)
tgroups = node.css('tgroup')
tgroups&.map do |t|
t.name = 'table'
t.remove_attribute('cols')
t.add_class('table')
t.css('row').map { |r| r.name = 'tr' }
t.css('thead entry').map { |e| e.name = 'th' }
t.css('tbody entry').map { |e| e.name = 'td' }
end
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength

def format_table_head(node)
table_head = node.at_css('head')
return if table_head.blank?

table_head.name = 'h3'
table_head.add_class('table-head')
end
end
end
3 changes: 3 additions & 0 deletions lib/arclight/traject/ead2_component_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@
to_field 'physfacet_tesim', extract_xpath('./did/physdesc/physfacet')
to_field 'dimensions_tesim', extract_xpath('./did/physdesc/dimensions')

to_field 'indexes_html_tesm', extract_xpath('./index', to_text: false)
to_field 'indexes_tesim', extract_xpath('./index')

to_field 'creator_ssm', extract_xpath('./did/origination')
to_field 'creator_ssim', extract_xpath('./did/origination')
to_field 'creators_ssim', extract_xpath('./did/origination')
Expand Down
3 changes: 3 additions & 0 deletions lib/arclight/traject/ead2_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@
accumulator.replace range.years
end

to_field 'indexes_html_tesm', extract_xpath('/ead/archdesc/index', to_text: false)
to_field 'indexes_tesim', extract_xpath('/ead/archdesc/index')

SEARCHABLE_NOTES_FIELDS.map do |selector|
to_field "#{selector}_html_tesm", extract_xpath("/ead/archdesc/#{selector}/*[local-name()!='head']", to_text: false) do |_record, accumulator|
accumulator.map!(&:to_html)
Expand Down
6 changes: 6 additions & 0 deletions lib/generators/arclight/templates/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ class CatalogController < ApplicationController
last_word_connector: '<br/>'
}

config.add_indexed_terms_field 'indexes', field: 'indexes_html_tesm',
helper_method: :render_html_tags

# ==========================
# COMPONENT SHOW PAGE FIELDS
# ==========================
Expand Down Expand Up @@ -379,6 +382,9 @@ class CatalogController < ApplicationController
last_word_connector: '<br/>'
}

config.add_component_indexed_terms_field 'indexes', field: 'indexes_html_tesm',
helper_method: :render_html_tags

# =================
# ACCESS TAB FIELDS
# =================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ en:
physdesc: Physical description
physfacet: Physical facet
dimensions: Dimensions
indexes: Indexes
descrules: Rules or conventions

relatedmaterial: Related material
Expand Down
1 change: 1 addition & 0 deletions solr/conf/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@
<copyField source="custodhist_tesim" dest="text" />
<copyField source="did_note_tesim" dest="text" />
<copyField source="fileplan_tesim" dest="text" />
<copyField source="indexes_tesim" dest="text" />
<copyField source="language_ssim" dest="text" />
<copyField source="materialspec_tesim" dest="text" />
<copyField source="note_tesim" dest="text" />
Expand Down
2 changes: 2 additions & 0 deletions spec/features/collection_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,15 @@
expect(page).to have_css('dt', text: 'Subjects')
expect(page).to have_css('dt', text: 'Names')
expect(page).to have_css('dt', text: 'Places')
expect(page).to have_css('dt', text: 'Indexes')
expect(page).to have_css('dd', text: 'Societies')
expect(page).to have_css('dd', text: 'Photographs')
expect(page).to have_css('dd', text: 'Medicine')
expect(page).to have_css('dd', text: 'Alpha Omega Alpha')
expect(page).to have_css('dd', text: 'Root, William Webster, 1867-1932')
expect(page).to have_css('dd', text: 'Bierring, Walter L. (Walter Lawrence), 1868-1961')
expect(page).to have_css('dd', text: 'Mindanao Island (Philippines)')
expect(page).to have_css('td', text: 'ABC Something')
expect(page).not_to have_css('dd', text: 'Higgins, L. Raymond')
end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/features/component_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
expect(page).to have_css('dd', text: /^various/)
expect(page).to have_css('dt', text: 'Physical facet')
expect(page).to have_css('dd', text: /^Boxes and folders/)
expect(page).to have_css('dt', text: 'Scope and content')
expect(page).to have_css('table thead tr th', text: 'GHI')
end

it 'multivalued notes are rendered as paragaphs' do
Expand Down
44 changes: 44 additions & 0 deletions spec/fixtures/ead/nlm/alphaomegaalpha.xml
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,21 @@
<persname source="mesh">Bierring, Walter L. (Walter Lawrence), 1868-1961</persname>
<geogname source="lcsh">Mindanao Island (Philippines)</geogname>
</controlaccess>
<index id="aspace_c42daf6e91923b8bee57622436d8f8a4">
<head>Alphabetical Listing of Test Titles</head>
<indexentry>
<title>ABC Something</title>
<ref>Box RN2</ref>
</indexentry>
<indexentry>
<title>B402 Something</title>
<ref>Box OV2 </ref>
</indexentry>
<indexentry>
<title>C200 Something</title>
<ref>Box DO14</ref>
</indexentry>
</index>
<dsc>
<c id="aspace_563a320bb37d24a9e1e6f7bf95b52671" level="series">
<did>
Expand Down Expand Up @@ -501,6 +516,35 @@
Office in the records storage facility until they were transferred, at his
family's request in 1988.</p>
</custodhist>
<scopecontent id="aspace_63fb9d2df5fb62ff01de34b0dd002155">
<p>Here is a table in a paragraph.</p>
<p>
<table frame="none">
<head>Test Table</head>
<tgroup cols="3">
<thead>
<row>
<entry colname="1">ABC</entry>
<entry colname="2">DEF</entry>
<entry colname="3">GHI</entry>
</row>
</thead>
<tbody>
<row>
<entry colname="1">123</entry>
<entry colname="2">456</entry>
<entry colname="3">789</entry>
</row>
<row>
<entry colname="1">012</entry>
<entry colname="2">345</entry>
<entry colname="3">678</entry>
</row>
</tbody>
</tgroup>
</table>
</p>
</scopecontent>
</c>
<c id="aspace_a8b5c3a57013462581d0e807241fcf93" level="otherlevel">
<did>
Expand Down
92 changes: 92 additions & 0 deletions spec/helpers/arclight/ead_format_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -425,5 +425,97 @@
end
end
end

describe 'indexes' do
describe 'basic index with name/ref pairs' do
it 'index -> table' do
content = helper.render_html_tags(value: [%(
<index>
<head>Alphabetical Listing By Client</head>
<p>Here's a brief note describing the index</p>
<indexentry>
<name>Absorbine Jr.</name>
<ref>1947 Feb. 17</ref>
</indexentry>
<indexentry>
<name>Action Gemeinsinn</name>
<ref>1962 Feb. 7</ref>
</indexentry>
<indexentry>
<name>Alexander Smith Inc.</name>
<ref>1952 Mar. 24</ref>
</indexentry>
</index>
)])
expect(content).to eq_ignoring_whitespace %(
<div>
<h3 class="index-head" id="index-alphabetical-listing-by-client">Alphabetical Listing By Client</h3>
<p>Here's a brief note describing the index</p>
<table class="table indexentries">
<tr>
<td>Absorbine Jr.</td>
<td>1947 Feb. 17</td>
</tr>
<tr>
<td>Action Gemeinsinn</td>
<td>1962 Feb. 7</td>
</tr>
<tr>
<td>Alexander Smith Inc.</td>
<td>1952 Mar. 24</td>
</tr>
</table>
</div>
)
end
end
end

describe 'tables' do
describe 'table with headers' do
it 'EAD table -> HTML table' do
content = helper.render_html_tags(value: [%(
<table frame="none">
<tgroup cols="3">
<thead>
<row>
<entry colname="1">Major Family Members</entry>
<entry colname="2">Spouses</entry>
<entry colname="3">Children</entry>
</row>
</thead>
<tbody>
<row>
<entry colname="1">John Albemarle (1760-1806)</entry>
<entry colname="2">Mary Frances Delaney (1769-1835)</entry>
<entry colname="3">John Delaney Albemarle (1787-1848)</entry>
</row>
</tbody>
</tgroup>
</table>
)])
expect(content).to eq_ignoring_whitespace %(
<div>
<table class="table">
<thead>
<tr>
<th>Major Family Members</th>
<th>Spouses</th>
<th>Children</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Albemarle (1760-1806)</td>
<td>Mary Frances Delaney (1769-1835)</td>
<td>John Delaney Albemarle (1787-1848)</td>
</tr>
</tbody>
</table>
</div>
)
end
end
end
end
end

0 comments on commit b281049

Please sign in to comment.