-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add citations for SCSB items #4427
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
849aa79
Add MLA citation for SCSB items
maxkadel ea75017
Merge branch 'main' into i4012_add_citation_scsb
maxkadel bbea05f
Get rid of collisions with json-ld. This suggests this should be in a…
maxkadel 79407d2
Add private method section
maxkadel 1c20768
Add APA and Chicago CiteProc citations
maxkadel df3938c
Update Gemfile
maxkadel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
app/components/orangelight/document/citation_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<div> | ||
<h1 class="modal-title"><%= title %></h1> | ||
|
||
<% @formats.each do |i18n_key, citation_method| %> | ||
<h2><%= t(i18n_key) %></h2> | ||
<%= @document.send(citation_method).html_safe %> | ||
<% unless @formats.keys.last === i18n_key %> | ||
<br/><br/> | ||
<% end %> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class Orangelight::Document::CitationComponent < Blacklight::Document::CitationComponent | ||
DEFAULT_FORMATS = { | ||
'blacklight.citation.mla': :export_as_mla, | ||
'blacklight.citation.apa': :export_as_apa, | ||
'blacklight.citation.chicago': :export_as_chicago | ||
}.freeze | ||
|
||
def initialize(document:, formats: DEFAULT_FORMATS) | ||
super | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
# Creates an html APA citation for non-Marc records | ||
module Blacklight::Document::Apa | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this structure with the 3 modules for the 3 citation styles |
||
def self.extended(document) | ||
Blacklight::Document::Apa.register_export_formats(document) | ||
end | ||
|
||
def self.register_export_formats(document) | ||
document.will_export_as(:apa, 'text/html') | ||
end | ||
|
||
def export_as_apa | ||
return export_as_apa_citation_txt if alma? | ||
|
||
cp = CiteProc::Processor.new style: 'apa', format: 'html' | ||
item = CiteProc::Item.new(properties) | ||
cp.import(item) | ||
cp.render(:bibliography, id:).first | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
# Creates an html Chicago citation for non-Marc records | ||
module Blacklight::Document::Chicago | ||
def self.extended(document) | ||
Blacklight::Document::Chicago.register_export_formats(document) | ||
end | ||
|
||
def self.register_export_formats(document) | ||
document.will_export_as(:chicago, 'text/html') | ||
end | ||
|
||
def export_as_chicago | ||
return export_as_chicago_citation_txt if alma? | ||
|
||
cp = CiteProc::Processor.new style: 'chicago-author-date', format: 'html' | ||
item = CiteProc::Item.new(properties) | ||
cp.import(item) | ||
cp.render(:bibliography, id:).first | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# frozen_string_literal: true | ||
|
||
## Adds the methods needed for CiteProc citations, | ||
# Including MLA, APA, and Chicago | ||
module Blacklight::Document::CiteProc | ||
private | ||
|
||
def properties | ||
props = {} | ||
props[:id] = id | ||
props[:edition] = cite_proc_edition if cite_proc_edition | ||
props[:type] = cite_proc_type if cite_proc_type | ||
props[:author] = cite_proc_author if cite_proc_author | ||
props[:title] = cite_proc_title if cite_proc_title | ||
props[:publisher] = cite_proc_publisher if cite_proc_publisher | ||
props[:'publisher-place'] = cite_proc_publisher_place if cite_proc_publisher_place | ||
props[:issued] = cite_proc_issued if cite_proc_issued | ||
props | ||
end | ||
|
||
def cite_proc_type | ||
self[:format]&.first&.downcase | ||
end | ||
|
||
def cite_proc_author | ||
@cite_proc_author ||= begin | ||
family, given = citation_fields_from_solr[:author_citation_display]&.first&.split(', ') | ||
CiteProc::Name.new(family:, given:) if family || given | ||
end | ||
end | ||
|
||
def cite_proc_edition | ||
@cite_proc_edition ||= begin | ||
str = citation_fields_from_solr[:edition_display]&.first | ||
str&.dup&.sub!(/[[:punct:]]?$/, '') | ||
end | ||
end | ||
|
||
def cite_proc_title | ||
@cite_proc_title ||= citation_fields_from_solr[:title_citation_display]&.first | ||
end | ||
|
||
def cite_proc_publisher | ||
@cite_proc_publisher ||= citation_fields_from_solr[:pub_citation_display]&.first&.split(': ').try(:[], 1) | ||
end | ||
|
||
def cite_proc_publisher_place | ||
@cite_proc_publisher_place ||= citation_fields_from_solr[:pub_citation_display]&.first&.split(': ').try(:[], 0) | ||
end | ||
|
||
def cite_proc_issued | ||
@cite_proc_issued ||= citation_fields_from_solr[:pub_date_start_sort] | ||
end | ||
|
||
def citation_fields_from_solr | ||
@citation_fields_from_solr ||= begin | ||
params = { q: "id:#{RSolr.solr_escape(id)}", fl: "author_citation_display, title_citation_display, pub_citation_display, number_of_pages_citation_display, pub_date_start_sort, edition_display" } | ||
solr_response = Blacklight.default_index.connection.get('select', params:) | ||
solr_response["response"]["docs"].first.with_indifferent_access | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
# Creates an html MLA citation for non-Marc records | ||
module Blacklight::Document::Mla | ||
def self.extended(document) | ||
Blacklight::Document::Mla.register_export_formats(document) | ||
end | ||
|
||
def self.register_export_formats(document) | ||
document.will_export_as(:mla, 'text/html') | ||
end | ||
|
||
def export_as_mla | ||
return export_as_mla_citation_txt if alma? | ||
|
||
cp = CiteProc::Processor.new style: 'modern-language-association', format: 'html' | ||
item = CiteProc::Item.new(properties) | ||
cp.import(item) | ||
cp.render(:bibliography, id:).first | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<%= render Blacklight::System::ModalComponent.new do |component| %> | ||
<% component.with_title { t('blacklight.tools.citation') } %> | ||
<%= render Orangelight::Document::CitationComponent.with_collection(@documents) if @documents.present? %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
spec/components/orangelight/document/citation_component_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe Orangelight::Document::CitationComponent, type: :component, citation: true do | ||
let(:document) { SolrDocument.new(properties) } | ||
let(:properties) do | ||
{ | ||
id: 'SCSB-2635660', | ||
author_citation_display: ["Saer, Juan José"] | ||
} | ||
end | ||
let(:component) { described_class.new(document:) } | ||
|
||
it 'can be rendered' do | ||
expect(render_inline(component).to_s).to include('Saer') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a custom routine for each citation form we want to support, correct? I like that this approach would route all types of records through the same routines. We definitely don't want some records to go through blacklight-marc and others to go through citeproc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the next step is to add the other citation formats. Right now if it's an Alma record it does use the Marc version, but we could change that once we've gotten the CiteProc code more refined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ticket to route all types of records through the same routines - #4428