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

improved and human readable citations #1027

Merged
merged 55 commits into from Mar 27, 2018
Commits
Jump to file or symbol
Failed to load files and symbols.
+1,300 −277
Diff settings

Always

Just for now

View
@@ -40,6 +40,14 @@ gem 'rest-client'
gem 'whenever'
gem 'addressable', '~> 2.5'
# we use for data structures for citation models, and for generating citations
gem "citeproc-ruby", '~> 1.0'
gem 'csl-styles', '~> 1.0' # Need to load the styles so we can use chicago
# On MRI <= 2.3, citeproc-ruby insists upon `unicode` or `unicode_utils` gem. :(
# https://github.com/inukshuk/citeproc/commit/c14d3cd272698dd4aa52625dd140864b7a7bd6cb
gem 'unicode'
gem 'rails', '~> 5.0.0'
gem 'devise'
gem 'devise-guests', '~> 0.3'
View
@@ -598,6 +598,11 @@ GEM
childprocess (0.7.1)
ffi (~> 1.0, >= 1.0.11)
chronic (0.10.2)
citeproc (1.0.9)
namae (~> 1.0)
citeproc-ruby (1.1.10)
citeproc (~> 1.0, >= 1.0.9)
csl (~> 1.5)
clipboard-rails (1.7.1)
cliver (0.3.2)
coderay (1.1.2)
@@ -612,6 +617,10 @@ GEM
crack (0.4.3)
safe_yaml (~> 1.0.0)
crass (1.0.3)
csl (1.5.0)
namae (~> 1.0)
csl-styles (1.0.1.8)
csl (~> 1.0)
curation_concerns (1.7.8)
active-fedora (>= 10.3.0.rc1)
active_attr
@@ -913,6 +922,7 @@ GEM
multi_xml (0.6.0)
multipart-post (2.0.0)
mustermann (1.0.2)
namae (1.0.1)
nenv (0.3.0)
nest (2.1.0)
redic
@@ -1229,6 +1239,7 @@ GEM
unf (0.1.4)
unf_ext
unf_ext (0.0.7.4)
unicode (0.4.4.4)
vegas (0.1.11)
rack (>= 1.0.0)
warden (1.2.7)
@@ -1269,8 +1280,10 @@ DEPENDENCIES
capistrano-rails (~> 1.2)
capybara (~> 2.4)
capybara-screenshot
citeproc-ruby (~> 1.0)
coffee-rails (~> 4.2)
concurrent-ruby (~> 1.0)
csl-styles (~> 1.0)
curation_concerns (~> 1.7.7)
database_cleaner (~> 1.3)
devise
@@ -1323,6 +1336,7 @@ DEPENDENCIES
therubyracer
tty-command
uglifier (>= 1.3.0)
unicode
web-console (>= 3.3.0)
webmock
whenever
@@ -131,6 +131,10 @@ hr.brand {
.branded-body-font {
p:not(.collection-title):not(.sans-serif), dl:not(.sans-serif) dd, table:not(.sans-serif) td, table:not(.sans-serif) th, .serif {
@extend %text-font;
// super hacky sorry. :(
.btn {
font-family: $brand-sans-serif;
}
}
p:not(.collection-title):not(.sans-serif) {
// try to keep this readable, abril is particularly hard on long line lengths
@@ -116,10 +116,6 @@
margin-top: $paragraph-spacer;
}
.show-user-actions {
margin-bottom: $paragraph-spacer;
}
.rights-and-social {
display: flex;
flex-wrap: wrap;
@@ -295,3 +291,15 @@
vertical-align: middle;
}
}
// normally we have a table under a show sub-head, but when we want just
// a block instead, make it look like the table.
.show-sub-head-body {
border-top: 3px solid $table-border-color;
padding: $table-condensed-cell-padding;
}
.citation {
line-height: 1.5 !important; // ah, !important, the sign of CSS out of control
}
@@ -27,13 +27,19 @@ def viewer_images_info
# override from curation_concerns to add additional response formats to #show
def additional_response_formats(wants)
wants.ris do
@curation_concern = _curation_concern_type.find(params[:id]) unless curation_concern
# Terrible hack to get download name from our helper
download_name = helpers._download_name_base(presenter) + ".ris"
headers["Content-Disposition"] = ApplicationHelper.encoding_safe_content_disposition(download_name)
render body: CHF::RisSerializer.new(presenter).to_ris
end
wants.csl do
# Terrible hack to get download name from our helper
download_name = helpers._download_name_base(@curation_concern) + ".ris"
download_name = helpers._download_name_base(presenter) + ".json"
headers["Content-Disposition"] = ApplicationHelper.encoding_safe_content_disposition(download_name)
render body: CHF::RisSerializer.new(@curation_concern).serialize
render body: CHF::CitableAttributes.new(presenter).to_csl_json
end
end
@@ -0,0 +1,26 @@
module CitationRenderingHelper
# reuse this style cause it's expensive to load. Hope it's concurrency safe!
def self.csl_chicago_style
@csl_chicago_style ||= ::CSL::Style.load("chicago-note-bibliography")
end
# similar to csl_chicago_style
def self.csl_en_us_locale
@csl_en_us_locale ||= ::CSL::Locale.load("en-US")
end
# creates citation from presenter using CitableAttributes, and ruby CSL
def citation_for_work(presenter)
csl_data = CHF::CitableAttributes.new(presenter).as_csl_json.stringify_keys
citation_item = CiteProc::CitationItem.new(id: csl_data["id"] || "id") do |c|
c.data = CiteProc::Item.new(csl_data)
end
renderer = CiteProc::Ruby::Renderer.new :format => CiteProc::Ruby::Formats::Html.new,
:locale => CitationRenderingHelper.csl_en_us_locale
renderer.render(citation_item, CitationRenderingHelper.csl_chicago_style.bibliography).html_safe
end
end
@@ -2,14 +2,20 @@ module CHF
class GenericWorkIndexer < CurationConcerns::WorkIndexer
def generate_solr_document
super.tap do |doc|
%w(additional_credit inscription date_of_work).each do |field|
entries = remove_duplicates(field)
doc[ActiveFedora.index_field_mapper.solr_name(field, :stored_searchable)] = entries.map { |entry| entry.display_label }
end
unless object.physical_container.nil?
require_dependency Rails.root.join('lib','chf','utils','parse_fields')
# formatted
doc[ActiveFedora.index_field_mapper.solr_name("physical_container", :stored_searchable)] = CHF::Utils::ParseFields.display_physical_container(object.physical_container)
# and original
doc["physical_container_structured_ss"] = object.physical_container
end
makers = %w(after artist author addressee creator_of_work contributor engraver interviewee interviewer manufacturer photographer printer printer_of_plates publisher)
@@ -68,10 +74,14 @@ def generate_solr_document
# Taken from hyrax, so we can facet on visibility settings
# https://github.com/samvera/hyrax/blob/0d2e40e2ed09b07645dd71892e65c93aa58c88f9/app/indexers/hyrax/work_indexer.rb#L18
doc['visibility_ssi'] = object.visibility
# index structured date of works, so we can get them at index time
doc['date_of_work_json_ssm'] = object.date_of_work.collect { |d| d.to_json(except: "id") }
end
end
private
def remove_duplicates(field)
entries = object.send(field).to_a
entries.uniq! {|e| e.id} # can return nil
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.