dbpedialite.rb
# FIXME: do proper content negotiation using Sinatra::Request::AcceptEntry
# and Rack's MIME registry
do proper content negotiation using Sinatra::Request::AcceptEntry
and Rack's MIME registry
do proper content negotiation using Sinatra :: Request :: AcceptEntry and Rack ' s MIME registry
def negotiate_content(graph, format, html_view)
    if format.empty?
      format = request.accept.first.to_s || ''
      format.sub!(/;.+$/,'')
      headers 'Vary' => 'Accept'
    end
    case format
      when '', '*/*', 'html', 'application/xml', 'application/xhtml+xml', 'text/html' then
        content_type 'text/html'
        erb html_view
      when 'json', 'application/json', 'text/json' then
        content_type 'application/json'
        graph.dump(:json)
      when 'jsonld', 'application/ld+json' then
        content_type 'application/json'
        graph.dump(:jsonld, :standard_prefixes => true)
      when 'turtle', 'ttl', 'text/turtle', 'application/turtle' then
        content_type 'text/turtle'
        graph.dump(:turtle, :standard_prefixes => true)
      when 'nt', 'ntriples', 'application/n-triples', 'text/plain' then
        content_type 'text/plain'
        graph.dump(:ntriples)
      when 'rdf', 'rdfxml', 'application/rdf+xml', 'text/rdf' then
        content_type 'application/rdf+xml'
        graph.dump(:rdfxml, :standard_prefixes => true, :stylesheet => '/rdfxml.xsl')
      when 'trix', 'xml', 'application/trix' then
        content_type 'application/trix'
        graph.dump(:trix)
      else
        error 400, "Unsupported format: #{format}\n"
    end
  end
def negotiate_content ( graph , format , html_view ) if format . empty? format = request . accept . first . to_s || '' format . sub! ( / ;.+$ / , '' ) headers 'Vary' => 'Accept' end case format when '' , '*/*' , 'html' , 'application/xml' , 'application/xhtml+xml' , 'text/html' then content_type 'text/html' erb html_view when 'json' , 'application/json' , 'text/json' then content_type 'application/json' graph . dump ( :json ) when 'jsonld' , 'application/ld+json' then content_type 'application/json' graph . dump ( :jsonld , :standard_prefixes => true ) when 'turtle' , 'ttl' , 'text/turtle' , 'application/turtle' then content_type 'text/turtle' graph . dump ( :turtle , :standard_prefixes => true ) when 'nt' , 'ntriples' , 'application/n-triples' , 'text/plain' then content_type 'text/plain' graph . dump ( :ntriples ) when 'rdf' , 'rdfxml' , 'application/rdf+xml' , 'text/rdf' then content_type 'application/rdf+xml' graph . dump ( :rdfxml , :standard_prefixes => true , :stylesheet => '/rdfxml.xsl' ) when 'trix' , 'xml' , 'application/trix' then content_type 'application/trix' graph . dump ( :trix ) else error 400 , "Unsupported format: #{format}\n" end end
FIXME: do proper content negotiation using Sinatra::Request::AcceptEntry
and Rack's MIME registry
FIXME : do proper content negotiation using Sinatra :: Request :: AcceptEntry and Rack ' s MIME registry
graph
<not_specific>
format
<not_specific>
html_view
<not_specific>