From a346e9c8b7039cac1ac7a6d0fad78999a58c3855 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Fri, 12 Oct 2018 13:27:49 -0400 Subject: [PATCH] use formatted citations from bolognese. datacite/bolognese#36 --- Gemfile | 4 +- Gemfile.lock | 82 +++++++++++++++++------------ app/controllers/index_controller.rb | 11 ++-- config/initializers/mime_types.rb | 9 ++++ spec/requests/index_spec.rb | 6 +-- 5 files changed, 65 insertions(+), 47 deletions(-) diff --git a/Gemfile b/Gemfile index 18567c075..c2444041e 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ gem 'mysql2', '~> 0.4.4' gem 'dotenv' gem 'multi_json' gem 'json', '~> 1.8', '>= 1.8.5' -gem 'oj', '~> 2.18', '>= 2.18.1' +gem 'oj', '>= 2.8.3' gem 'jsonlint', '~> 0.2.0' gem 'equivalent-xml', '~> 0.6.0' gem 'nokogiri', '~> 1.8.1' @@ -41,7 +41,7 @@ gem 'bergamasco', '~> 0.3.10' gem 'base32-url', '~> 0.3' gem 'mailgun-ruby', '~> 1.1', '>= 1.1.8' gem 'premailer', '~> 1.11', '>= 1.11.1' -gem 'flipper', '~> 0.15.0' +gem 'flipper', '~> 0.16.0' gem 'flipper-active_support_cache_store' gem 'rack-cors', '~> 1.0', '>= 1.0.2', :require => 'rack/cors' gem 'strip_attributes', '~> 1.8' diff --git a/Gemfile.lock b/Gemfile.lock index cd638f1c1..8ad4ad9ad 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -55,8 +55,8 @@ GEM api-pagination (4.8.1) arel (9.0.0) aws-eventstream (1.0.1) - aws-partitions (1.103.0) - aws-sdk-core (3.27.0) + aws-partitions (1.105.0) + aws-sdk-core (3.30.0) aws-eventstream (~> 1.0) aws-partitions (~> 1.0) aws-sigv4 (~> 1.0) @@ -64,11 +64,11 @@ GEM aws-sdk-kms (1.9.0) aws-sdk-core (~> 3, >= 3.26.0) aws-sigv4 (~> 1.0) - aws-sdk-s3 (1.19.0) + aws-sdk-s3 (1.21.0) aws-sdk-core (~> 3, >= 3.26.0) aws-sdk-kms (~> 1) aws-sigv4 (~> 1.0) - aws-sdk-sqs (1.6.0) + aws-sdk-sqs (1.7.0) aws-sdk-core (~> 3, >= 3.26.0) aws-sigv4 (~> 1.0) aws-sigv4 (1.0.3) @@ -93,33 +93,36 @@ GEM latex-decode (~> 0.0) binding_of_caller (0.8.0) debug_inspector (>= 0.0.1) - bolognese (0.14.1) + bolognese (0.15.1) activesupport (>= 4.2.5, < 6) benchmark_methods (~> 0.7) bibtex-ruby (~> 4.1) builder (~> 3.2, >= 3.2.2) + citeproc-ruby (~> 1.1, >= 1.1.10) colorize (~> 0.8.1) + csl-styles (~> 1.0, >= 1.0.1.8) + edtf (~> 3.0, >= 3.0.4) gender_detector (~> 0.1.2) iso8601 (~> 0.9.1) json-ld (~> 2.1, >= 2.1.2) jsonlint (~> 0.2.0) loofah (~> 2.0, >= 2.0.3) maremma (>= 3.5.7, < 5) - namae (~> 0.11.3) + namae (~> 1.0) nokogiri (~> 1.8.1) oj (>= 2.8.3) postrank-uri (~> 1.0, >= 1.0.18) rdf-rdfxml (~> 2.0) rdf-turtle (~> 2.2) thor (~> 0.19) - bootsnap (1.3.1) + bootsnap (1.3.2) msgpack (~> 1.0) bugsnag (6.8.0) concurrent-ruby (~> 1.0) builder (3.2.3) byebug (10.0.2) - cancancan (2.2.0) - capybara (3.7.1) + cancancan (2.3.0) + capybara (3.9.0) addressable mini_mime (>= 0.1.3) nokogiri (~> 1.8) @@ -128,11 +131,16 @@ GEM xpath (~> 3.1) case_transform (0.2) activesupport - codeclimate-test-reporter (1.0.8) + citeproc (1.0.9) + namae (~> 1.0) + citeproc-ruby (1.1.10) + citeproc (~> 1.0, >= 1.0.9) + csl (~> 1.5) + codeclimate-test-reporter (1.0.9) simplecov (<= 0.13) coderay (1.1.2) colorize (0.8.1) - commonmarker (0.17.12) + commonmarker (0.17.13) ruby-enum (~> 0.5) concurrent-ruby (1.0.5) countries (2.1.4) @@ -146,6 +154,10 @@ GEM crack (0.4.3) safe_yaml (~> 1.0.0) crass (1.0.4) + csl (1.5.0) + namae (~> 1.0) + csl-styles (1.0.1.8) + csl (~> 1.0) css_parser (1.6.0) addressable dalli (2.7.8) @@ -157,9 +169,11 @@ GEM domain_name (0.5.20180417) unf (>= 0.0.5, < 1.0.0) dotenv (2.5.0) - ebnf (1.1.2) - rdf (>= 2.2, < 4.0) + ebnf (1.1.3) + rdf (~> 3.0) sxp (~> 1.0) + edtf (3.0.4) + activesupport (>= 3.0, < 6.0) elasticsearch (5.0.5) elasticsearch-api (= 5.0.5) elasticsearch-transport (= 5.0.5) @@ -188,22 +202,22 @@ GEM railties (>= 3.0.0) faker (1.9.1) i18n (>= 0.7) - faraday (0.15.2) + faraday (0.15.3) multipart-post (>= 1.2, < 3) - faraday-encoding (0.0.4) + faraday-encoding (0.0.5) faraday faraday_middleware (0.12.2) faraday (>= 0.7.4, < 1.0) faraday_middleware-aws-sigv4 (0.2.4) aws-sigv4 (~> 1.0) faraday (>= 0.9) - fast_jsonapi (1.3) + fast_jsonapi (1.4) activesupport (>= 4.2) ffi (1.9.25) - flipper (0.15.0) - flipper-active_support_cache_store (0.15.0) + flipper (0.16.0) + flipper-active_support_cache_store (0.16.0) activesupport (>= 3.2, < 6) - flipper (~> 0.15.0) + flipper (~> 0.16.0) gender_detector (0.1.2) unicode_utils (>= 1.3.0) globalid (0.4.1) @@ -218,7 +232,7 @@ GEM htmlentities (4.3.4) http-cookie (1.0.3) domain_name (~> 0.5) - i18n (1.0.1) + i18n (1.1.0) concurrent-ruby (~> 1.0) i18n_data (0.8.0) iso8601 (0.9.1) @@ -263,9 +277,9 @@ GEM nokogiri (>= 1.5.9) mail (2.7.0) mini_mime (>= 0.1.1) - mailgun-ruby (1.1.10) - rest-client (~> 2.0) - marcel (0.3.2) + mailgun-ruby (1.1.11) + rest-client (~> 2.0.2) + marcel (0.3.3) mimemagic (~> 0.3.2) maremma (4.1.1) activesupport (>= 4.2.5, < 6) @@ -283,20 +297,20 @@ GEM mime-types-data (~> 3.2015) mime-types-data (3.2018.0812) mimemagic (0.3.2) - mini_magick (4.8.0) + mini_magick (4.9.2) mini_mime (1.0.1) mini_portile2 (2.3.0) minitest (5.11.3) - money (6.12.0) - i18n (>= 0.6.4, < 1.1) + money (6.13.0) + i18n (>= 0.6.4, <= 2) msgpack (1.2.4) multi_json (1.13.1) multipart-post (2.0.0) mysql2 (0.4.10) - namae (0.11.3) + namae (1.0.1) netrc (0.11.0) nio4r (2.3.1) - nokogiri (1.8.4) + nokogiri (1.8.5) mini_portile2 (~> 2.3.0) oj (2.18.5) oj_mimic_json (1.0.1) @@ -348,7 +362,7 @@ GEM rb-fsevent (0.10.3) rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) - rdf (3.0.2) + rdf (3.0.4) hamster (~> 3.0) link_header (~> 0.0, >= 0.0.8) rdf-aggregate-repo (2.2.1) @@ -367,7 +381,7 @@ GEM rdf-turtle (2.2.2) ebnf (~> 1.1) rdf (>= 2.2, < 4.0) - rdf-xsd (3.0.0) + rdf-xsd (3.0.1) rdf (~> 3.0) request_store (1.4.1) rack (>= 1.4) @@ -377,7 +391,7 @@ GEM netrc (~> 0.8) rspec-core (3.8.0) rspec-support (~> 3.8.0) - rspec-expectations (3.8.1) + rspec-expectations (3.8.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.8.0) rspec-mocks (3.8.0) @@ -396,7 +410,7 @@ GEM i18n ruby_dep (1.5.0) safe_yaml (1.0.4) - shoryuken (3.2.3) + shoryuken (3.3.0) aws-sdk-core (>= 2) concurrent-ruby thor @@ -487,7 +501,7 @@ DEPENDENCIES faker faraday_middleware-aws-sigv4 (~> 0.2.4) fast_jsonapi (~> 1.3) - flipper (~> 0.15.0) + flipper (~> 0.16.0) flipper-active_support_cache_store gender_detector (~> 0.1.2) iso8601 (~> 0.9.0) @@ -505,7 +519,7 @@ DEPENDENCIES multi_json mysql2 (~> 0.4.4) nokogiri (~> 1.8.1) - oj (~> 2.18, >= 2.18.1) + oj (>= 2.8.3) oj_mimic_json (~> 1.0, >= 1.0.1) patron (~> 0.13.1) premailer (~> 1.11, >= 1.11.1) diff --git a/app/controllers/index_controller.rb b/app/controllers/index_controller.rb index 0eb7c40f0..57175884a 100644 --- a/app/controllers/index_controller.rb +++ b/app/controllers/index_controller.rb @@ -16,14 +16,9 @@ def show respond_to do |format| format.citation do # fetch formatted citation - options = { - style: params[:style] || "apa", - locale: params[:locale] || "en-US" } - - citation_url = ENV["CITEPROC_URL"] + "?" + URI.encode_www_form(options) - response = Maremma.post citation_url, content_type: 'json', data: @doi.citeproc - - render plain: CGI.unescapeHTML(response.body.fetch("data", "")) + @doi.style = params[:style] || "apa" + @doi.locale = params[:locale] || "en-US" + render citation: @doi end format.any(:bibtex, :citeproc, :codemeta, :crosscite, :datacite, :datacite_json, :jats, :ris, :schema_org) { render request.format.to_sym => @doi } format.any { fail ActionController::UnknownFormat } diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index c9c2668d8..0663c200d 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -34,6 +34,15 @@ disposition: "attachment; filename=#{filename}.xml" end +ActionController::Renderers.add :citation do |obj, options| + uri = Addressable::URI.parse(obj.identifier) + data = obj.citation + + filename = uri.path.gsub(/[^0-9A-Za-z.\-]/, '_') + send_data data.to_s, type: Mime[:citation], + disposition: "attachment; filename=#{filename}.txt" +end + ActionController::Renderers.add :turtle do |obj, options| uri = Addressable::URI.parse(obj.identifier) data = obj.send(:turtle) diff --git a/spec/requests/index_spec.rb b/spec/requests/index_spec.rb index 592d7423f..f40c29e9a 100644 --- a/spec/requests/index_spec.rb +++ b/spec/requests/index_spec.rb @@ -341,7 +341,7 @@ before { get "/#{doi.doi}?style=ieee", headers: { "HTTP_ACCEPT" => "text/x-bibliography", 'Authorization' => 'Bearer ' + bearer } } it 'returns the Doi' do - expect(response.body).to start_with("[1]M. Fenner") + expect(response.body).to start_with("M. Fenner") end it 'returns status code 200' do @@ -355,7 +355,7 @@ before { get "/text/x-bibliography/#{doi.doi}?style=ieee" } it 'returns the Doi' do - expect(response.body).to start_with("[1]M. Fenner") + expect(response.body).to start_with("M. Fenner") end it 'returns status code 200' do @@ -367,7 +367,7 @@ before { get "/#{doi.doi}?style=vancouver&locale=de", headers: { "HTTP_ACCEPT" => "text/x-bibliography", 'Authorization' => 'Bearer ' + bearer } } it 'returns the Doi' do - expect(response.body).to start_with("1. Fenner M") + expect(response.body).to start_with("Fenner M") end it 'returns status code 200' do