Skip to content

Commit

Permalink
use formatted citations from bolognese. datacite/bolognese#36
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Oct 12, 2018
1 parent f2b0bbe commit a346e9c
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 47 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
82 changes: 48 additions & 34 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ 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)
jmespath (~> 1.0)
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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
11 changes: 3 additions & 8 deletions app/controllers/index_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
9 changes: 9 additions & 0 deletions config/initializers/mime_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions spec/requests/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit a346e9c

Please sign in to comment.