diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index 8a4276138..c9c2668d8 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -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)