Skip to content

Commit

Permalink
download metadata by default. #108
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Sep 1, 2018
1 parent d6137b1 commit 593f32a
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions config/initializers/mime_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,26 @@
disposition: "attachment; filename=#{filename}.xml"
end

%w(datacite_json schema_org crosscite turtle citeproc codemeta).each do |f|
ActionController::Renderers.add :turtle do |obj, options|
uri = Addressable::URI.parse(obj.identifier)
data = obj.send(:turtle)

filename = uri.path.gsub(/[^0-9A-Za-z.\-]/, '_')
send_data data.to_s, type: Mime[:turtle],
disposition: "attachment; filename=#{filename}.ttl"
end

%w(datacite_json schema_org crosscite citeproc codemeta).each do |f|
ActionController::Renderers.add f.to_sym do |obj, options|
uri = Addressable::URI.parse(obj.identifier)
data = obj.send(f)

self.content_type ||= Mime[f.to_sym]
self.response_body = data.to_s
filename = uri.path.gsub(/[^0-9A-Za-z.\-]/, '_')
send_data data.to_s, type: Mime[f.to_sym],
disposition: "attachment; filename=#{filename}.json"
end
end

# these Mime types send a file for download. We give proper filename and extension
%w(crossref rdf_xml jats).each do |f|
ActionController::Renderers.add f.to_sym do |obj, options|
uri = Addressable::URI.parse(obj.identifier)
Expand Down

0 comments on commit 593f32a

Please sign in to comment.