Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit e34d26c963ddad3ecd8060136bde4a348797b995 @gkellogg committed Mar 28, 2011
19 Gemfile
@@ -0,0 +1,19 @@
+source 'http://rubygems.org'
+
+# Include non-released gems first
+gem 'rdf', :git => "https://github.com/gkellogg/rdf.git", :branch => "query-algebra"
+gem 'rdf-n3', :git => "https://github.com/gkellogg/rdf-n3.git", :require => "rdf/n3"
+#gem 'rdf-rdfa', :git => "https://github.com/gkellogg/rdf-rdfa.git", :require => "rdf/rdfa"
+gem 'rdf-rdfa', :path => "../rdf-rdfa"
+gem 'rdf-rdfxml', :git => "https://github.com/gkellogg/rdf-rdfxml.git", :require => "rdf/rdfxml"
+
+gem 'sinatra', '>= 1.2.1'
+gem 'sinatra-linkeddata', '>= 0.3.0', :require => 'sinatra/linkeddata'
+gem 'erubis', '>= 2.6.6'
+
+# Bundle gems for the local environment. Make sure to
+# put test-only gems in this group so their generators
+# and rake tasks are available in development mode:
+group :development, :test do
+ gem 'shotgun'
+end
@@ -0,0 +1,81 @@
+GIT
+ remote: https://github.com/gkellogg/rdf-n3.git
+ revision: 98085da296dc1d570b96c0fd93589b51c549d024
+ specs:
+ rdf-n3 (0.3.1.1)
+ rdf (>= 0.3.1)
+
+GIT
+ remote: https://github.com/gkellogg/rdf-rdfxml.git
+ revision: 3fa8e071295d587f3045810b1d85f245f8696879
+ specs:
+ rdf-rdfxml (0.3.2.1)
+ nokogiri (>= 1.4.4)
+ rdf (>= 0.3.1)
+
+GIT
+ remote: https://github.com/gkellogg/rdf.git
+ revision: 5b29e815e8e521b357a11087df3d70b502596e20
+ branch: query-algebra
+ specs:
+ rdf (0.3.1)
+ addressable (>= 2.2.4)
+
+PATH
+ remote: ../rdf-rdfa
+ specs:
+ rdf-rdfa (0.3.1.2)
+ nokogiri (>= 1.3.3)
+ rdf
+ rdf (>= 0.3.1)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ addressable (2.2.4)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ json_pure (1.5.1)
+ linkeddata (0.3.1)
+ rdf (~> 0.3.1)
+ rdf-isomorphic (~> 0.3.1)
+ rdf-json (~> 0.3.0)
+ rdf-n3 (~> 0.3.0)
+ rdf-rdfa (~> 0.3.0)
+ rdf-rdfxml (~> 0.3.0)
+ rdf-trix (~> 0.3.0)
+ nokogiri (1.4.4)
+ rack (1.2.2)
+ rack-linkeddata (0.3.0)
+ linkeddata (~> 0.3.0)
+ rack (>= 1.0)
+ rdf-isomorphic (0.3.4)
+ rdf (>= 0.2.3)
+ rdf-json (0.3.0)
+ json_pure (>= 1.4.2)
+ rdf (~> 0.3.0)
+ rdf-trix (0.3.0)
+ rdf (~> 0.3.0)
+ shotgun (0.9)
+ rack (>= 1.0)
+ sinatra (1.2.1)
+ rack (~> 1.1)
+ tilt (< 2.0, >= 1.2.2)
+ sinatra-linkeddata (0.3.0)
+ rack-linkeddata (~> 0.3.0)
+ sinatra (>= 1.0)
+ tilt (1.2.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ erubis (>= 2.6.6)
+ rdf!
+ rdf-n3!
+ rdf-rdfa!
+ rdf-rdfxml!
+ shotgun
+ sinatra (>= 1.2.1)
+ sinatra-linkeddata (>= 0.3.0)
1 README
No changes.
@@ -0,0 +1,24 @@
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to <http://unlicense.org/>
@@ -0,0 +1 @@
+0.0.1
@@ -0,0 +1,17 @@
+#!/usr/bin/env rackup
+$:.unshift(File.expand_path('../lib', __FILE__))
+
+#log = File.new('sinatra.log', 'a')
+#STDOUT.reopen(log)
+#STDERR.reopen(log)
+
+require 'rubygems' || Gem.clear_paths
+require 'bundler'
+Bundler.setup
+
+require 'rdf/portal'
+
+set :environment, :production
+disable :run, :reload
+
+run RDF::Portal::Application
@@ -0,0 +1,162 @@
+require 'sinatra'
+require 'sinatra/linkeddata' # Can't use this, as we may need to set by hand, and have to pass options to the serializer
+require 'sinatra/partials'
+require 'erubis'
+
+module RDF
+ module Portal
+ class Application < Sinatra::Base
+ #register Sinatra::LinkedData
+ helpers Sinatra::Partials
+ #use Rack::LinkedData::ContentNegotiation, :default => "text/html"
+ set :views, ::File.expand_path('../portal/views', __FILE__)
+
+ before do
+ puts "[#{request.path_info}], #{params.inspect}"
+ end
+
+ get '/' do
+ cache_control :public, :must_revalidate, :max_age => 60
+ erubis :index, :locals => {:title => "Ruby Linked Data Service"}
+ end
+
+ get '/about' do
+ cache_control :public, :must_revalidate, :max_age => 60
+ erubis :about, :locals => {:title => "About the Ruby Linked Data Service"}
+ end
+
+ get '/distiller' do
+ distil
+ end
+
+ post '/distiller' do
+ distil
+ end
+
+ private
+
+ # Handle GET/POST /distiller
+ def distil
+ content_type, content = parse
+ puts "content_type: #{content_type}"
+ if !params["raw"].to_s.empty? || content_type !~ /html/
+ status 200
+ headers "Allow" => "GET, POST", "Content-Type" => content_type
+ body content
+ else
+ @output = content
+ erubis :distiller, :locals => {:title => "RDF Distiller", :head => :distiller}
+ end
+ end
+
+ # Return ordered accept mime-types
+ def accepts
+ types = []
+ request.env["HTTP_ACCEPT"].to_s.split(",").each do |type|
+ t, q = type.split(';q=')
+ q ||= t =~ /xml$/ ? "0.9" : "1" # WebKit places application/xml at same priority as /html
+ types << [t, q.to_i]
+ end
+
+ types.sort {|a, b| b[1] <=> a[1]}.map {|(t, q)| t}
+ end
+
+ # Parse HTTP Accept header and find an suitable RDF writer
+ def writer(format = nil)
+ return format.to_sym if format && format.to_sym != :accept
+
+ # Look for formats matching accept headers
+ accepts.each do |t|
+ writer = RDF::Writer.for(:content_type => t)
+ return writer.to_sym if writer
+ end
+
+ return :ntriples
+ end
+
+ # Format symbol for RDF formats
+ # @param [Symbol] reader_or_writer
+ # @return [Array<Symbol>] List of format symbols
+ def formats(reader_or_writer = nil)
+ # Symbols for different input formats
+ RDF::Format.select do |f|
+ reader_or_writer != :reader || f.reader
+ reader_or_writer != :writer || f.writer
+ end.map(&:to_sym).sort
+ end
+
+ # Parse the an input file and re-serialize based on params and/or content-type/accept headers
+ def parse
+ reader_opts = {
+ :prefixes => {},
+ :base_uri => params["uri"],
+ :validate => params["validate"]
+ }
+ reader_opts[:format] = params["in_fmt"].to_sym unless params["in_fmt"].nil? || params["in_fmt"] == 'content'
+ reader_opts[:debug] = @debug = [] if params["debug"]
+ case
+ when !params["datafile"].to_s.empty?
+ raise "Specify input format" if params["in_fmt"].nil? || params["in_fmt"] == 'content'
+ reader = RDF::Reader.for(params["in_fmt"]).new(content, reader_opts)
+ when !params["content"].to_s.empty?
+ raise "Specify input format" if params["in_fmt"].nil? || params["in_fmt"] == 'content'
+ reader = RDF::Reader.for(params["in_fmt"]).new(content, reader_opts)
+ when !params["uri"].empty?
+ reader = RDF::Reader.open(params["uri"], reader_opts)
+ params["in_fmt"] = reader.class.to_sym if params["in_fmt"].nil? || params["in_fmt"] == 'content'
+ else
+ return ["text/html", ""]
+ end
+ content_type = reader.class.format.content_type.first
+
+ graph = RDF::Graph.new << reader
+
+ params["fmt"] = writer(params["fmt"])
+ [content_type, graph.dump(params["fmt"].to_sym, reader_opts)]
+ rescue Exception => e
+ @error = "#{e.class}: #{e.message}"
+ puts @error # to log
+ content_type ||= accepts.first
+ case content_type
+ when /html/
+ [content_type, @error] # XXX
+ when /xml/
+ [content_type, @error.to_xml]
+ else
+ [content_type, @error]
+ end
+ raise
+ end
+
+ end
+ end
+end
+
+module RDF
+ class Format
+ def self.to_sym
+ elements = self.to_s.split("::")
+ sym = elements.pop
+ sym = elements.pop if sym == 'Format'
+ sym.downcase.to_s
+ end
+ end
+
+ class Reader
+ def self.to_sym
+ elements = self.to_s.split("::")
+ sym = elements.pop
+ sym = elements.pop if sym == 'Reader'
+ sym.downcase.to_s
+ end
+ end
+
+ class Writer
+ def self.to_sym
+ elements = self.to_s.split("::")
+ sym = elements.pop
+ sym = elements.pop if sym == 'Writer'
+ sym.downcase.to_s
+ end
+ end
+end
No changes.
@@ -0,0 +1,28 @@
+<script type="text/javascript" charset="utf-8" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
+<script type="text/javascript">
+// Navigation
+$(function () {
+ // Display field sets having class of
+ // Clicking on a tab hides fieldsets not having that hash element as a class
+ $('nav.distiller a').click(function() {
+ var cls = this.hash.substr(1);
+ $('fieldset').hide();
+ $('fieldset.' + cls).show();
+ $('nav.distiller a').removeClass('selected');
+ $(this).addClass('selected');
+ window.location.hash = '#' + cls;
+ });
+
+ // Default tab, if none selected
+ if (window.location.hash === '') {
+ var dflt_hash = $('nav.distiller a:first').attr('href');
+ window.location.hash = dflt_hash;
+ }
+
+ // Select appropriate nav tab
+ var cls = window.location.hash.substr(1);
+ $('nav.distiller a.' + cls).click();
+
+});
+
+</script>
@@ -0,0 +1,3 @@
+<footer>
+ Thanks for your support
+</footer>
@@ -0,0 +1,9 @@
+<header>
+ <nav class="main">
+ <ul>
+ <li><a href="/">Home</a></li>
+ <li><a href="/distiller">Distiller</a></li>
+ <li><a href="/about">About</a></li>
+ </ul>
+ </nav>
+</header>
Oops, something went wrong.

0 comments on commit e34d26c

Please sign in to comment.