sparql-doc 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,44 @@
1
+ <div class="container">
2
+ <div class="hero-unit">
3
+ <h1><%= title %></h1>
4
+ </div>
5
+
6
+ <div class="row">
7
+ <div class="span12">
8
+ <p><%= description %></p>
9
+ </div>
10
+ </div>
11
+
12
+ <% if overview %>
13
+ <div class="row">
14
+ <div class="span12">
15
+ <h3 id="overview">Overview</h3>
16
+ <%= overview %>
17
+ </div>
18
+ </div>
19
+ <% end %>
20
+
21
+ <div class="row">
22
+ <div class="span12">
23
+ <h3>Queries</h3>
24
+ <p>This set of documentation covers <strong><%= @queries.size %></strong> queries</p>
25
+ <table class="table">
26
+ <thead>
27
+ <tr>
28
+ <th>Title</th><th>Source Path</th>
29
+ </tr>
30
+ </thead>
31
+ <tbody>
32
+ <% @queries.each do |query| %>
33
+ <tr>
34
+ <td><a href="<%= query.output_filename %>"><%= query.title %></a></td><td><code><%= query.path %></code></td>
35
+ </tr>
36
+ <% end %>
37
+ </tbody>
38
+ </table>
39
+ </div>
40
+ </div>
41
+
42
+ <hr>
43
+ <footer class="footer">Generated with <a href="http://github.com/ldodds/sparql-doc">sparql-doc</a>.</footer>
44
+ </div>
@@ -0,0 +1,47 @@
1
+ <html>
2
+ <head>
3
+ <title><%= title %></title>
4
+ <link href="bootstrap.min.css" rel="stylesheet">
5
+ <link rel="stylesheet" href="codemirror.css">
6
+ <style type="text/css">
7
+ body {
8
+ padding-top: 60px;
9
+ padding-bottom: 40px;
10
+ }
11
+ .sidebar-nav {
12
+ padding: 9px 0;
13
+ }
14
+ </style>
15
+ <script src="jquery.js"></script>
16
+ <script src="bootstrap.min.js"></script>
17
+
18
+ <script src="codemirror.js" type="text/javascript"></script>
19
+ <script src="sparql.js"></script>
20
+ </head>
21
+ <body>
22
+
23
+ <div class="navbar navbar-inverse navbar-fixed-top">
24
+ <div class="navbar-inner">
25
+ <div class="container-fluid">
26
+ <a class="brand" href="index.html"><%= title %></a>
27
+ <ul class="nav">
28
+ <% if overview %>
29
+ <li><a href="index.html#overview">Overview</a></li>
30
+ <% end %>
31
+ <% if @package["extra-files"] %>
32
+ <% @package["extra-files"].each do |file| %>
33
+ <li><a href="<%= file.gsub(".md", ".html") %>">
34
+ <%= file.gsub(".md", "") %>
35
+ </a></li>
36
+ <% end %>
37
+ <% end %>
38
+ </ul>
39
+ </div>
40
+ </div>
41
+ </div>
42
+
43
+ <%= yield %>
44
+ </body>
45
+ </html>
46
+
47
+
@@ -0,0 +1,61 @@
1
+ <div class="container-fluid" vocab="http://purl.org/dc/elements/1.1/">
2
+ <div class="row-fluid">
3
+ <div class="span12">
4
+ <div class="row-fluid">
5
+ <div id="query-viewer">
6
+ <h2 property="title"><%= query.title %></h2>
7
+ <% if query.description %>
8
+ <p property="description"><%= query.description(true) %></p>
9
+ <% end %>
10
+ <dl>
11
+ <dt>Source File</dt>
12
+ <dd><code><%= query.path %></code></dd>
13
+ <% query.author.each do |author| %>
14
+ <dt>Author</dt>
15
+ <dd><span property="creator"><%= author %></span></dd>
16
+ <% end %>
17
+ <% query.see.each do |see| %>
18
+ <dt>Link</dt>
19
+ <dd><a href="<%= see %>"><%= see %></a></dd>
20
+ <% end %>
21
+ <% if query.tag.length > 0 %>
22
+ <dt>Tag</dt>
23
+ <dd>
24
+ <%= query.tag.map{|x| "<span property=\"subject\">#{x}</span>" }.join(", ") %>
25
+ </dd>
26
+ <% end %>
27
+ </dl>
28
+ <textarea id="sparql" cols="120" rows="50"><%= query.query %></textarea>
29
+ <script>
30
+ var editor = CodeMirror.fromTextArea(document.getElementById("sparql"), {
31
+ height: "250px",
32
+ width: "250px",
33
+ autofocus: false,
34
+ readOnly: true,
35
+
36
+ parserfile: "parsesparql.js",
37
+ stylesheet: "/sparqlcolors.css",
38
+ path: "js/",
39
+ lineNumbers: true
40
+ });
41
+ </script>
42
+ <% if query.endpoint.length > 0 %>
43
+ <h3>Test This Query</h3>
44
+ <p>Try this query against the following endpoints:</p>
45
+ <ul>
46
+ <% query.endpoint.each do |endpoint| %>
47
+ <li>
48
+ <a href="<%=endpoint%>?query=<%= query.query_string %>" target="_blank"><%= endpoint %></a>
49
+ </li>
50
+ <% end %>
51
+ </ul>
52
+ <% end %>
53
+ </div>
54
+ </div><!--/row-->
55
+ </div><!--/span-->
56
+ </div><!--/row-->
57
+
58
+ <hr>
59
+ <footer class="footer">Generated with <a href="http://github.com/ldodds/sparql-doc">sparql-doc</a>.</footer>
60
+
61
+ </div>
data/lib/sparql-doc.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'erb'
3
+ require 'cgi'
4
+ require 'json'
5
+ require 'fileutils'
6
+ require 'redcarpet'
7
+
8
+ require 'sparql-doc/query'
9
+ require 'sparql-doc/generator'
10
+
11
+
@@ -0,0 +1,64 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+ require 'sparql-doc'
3
+ require 'test/unit'
4
+ require 'fakefs/safe'
5
+
6
+ class GeneratorTest < Test::Unit::TestCase
7
+ include FakeFS
8
+
9
+ def setup
10
+ FakeFS.activate!
11
+
12
+ FileUtils.mkdir_p("/lib/views")
13
+ FileUtils.touch("/lib/views/index.erb")
14
+ FileUtils.touch("/lib/views/query.erb")
15
+ FileUtils.mkdir_p("/lib/assets")
16
+ FileUtils.touch("/lib/assets/test.js")
17
+ FileUtils.touch("/lib/assets/test.css")
18
+
19
+ FileUtils.mkdir_p("/in")
20
+
21
+ File.open("/in/test.rq", "w") do |f|
22
+ f.puts "DESCRIBE ?x"
23
+ end
24
+ FileUtils.mkdir_p("/out")
25
+ end
26
+
27
+ def teardown
28
+ FakeFS.deactivate!
29
+ end
30
+
31
+ def test_copy_assets
32
+ generator = SparqlDoc::Generator.new("/in", "/out", "/lib/views", "/lib/assets")
33
+ generator.copy_assets()
34
+ assert_equal( true, File.exists?("/out/test.js") )
35
+ assert_equal( true, File.exists?("/out/test.css") )
36
+ end
37
+
38
+ def test_parse_queries
39
+ generator = SparqlDoc::Generator.new("/in", "/out", "/lib/views", "/lib/assets")
40
+ generator.parse_queries
41
+ assert_equal( 1, generator.queries.size )
42
+ end
43
+
44
+ def test_parse_package
45
+ generator = SparqlDoc::Generator.new("/in", "/out", "/lib/views", "/lib/assets")
46
+ assert_equal( {}, generator.parse_package )
47
+
48
+ File.open("/in/package.json", "w") do |f|
49
+ f.puts "{\"title\": \"Package Title\"}"
50
+ end
51
+ assert_equal( {"title"=>"Package Title"}, generator.parse_package )
52
+ end
53
+
54
+ def test_get_overview
55
+ generator = SparqlDoc::Generator.new("/in", "/out", "/lib/views", "/lib/assets")
56
+ assert_equal( nil, generator.get_overview )
57
+
58
+ File.open("/in/overview.md", "w") do |f|
59
+ f.puts "Overview"
60
+ end
61
+ assert_equal( "<p>Overview</p>\n", generator.get_overview )
62
+ end
63
+
64
+ end
data/tests/tc_query.rb ADDED
@@ -0,0 +1,137 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+ require 'sparql-doc'
3
+ require 'test/unit'
4
+
5
+ class QueryTest < Test::Unit::TestCase
6
+
7
+ def test_basic
8
+ query = SparqlDoc::Query.new("/path/to/query.rq", "DESCRIBE ?x")
9
+ assert_equal("/path/to/query.rq", query.title)
10
+ assert_equal("", query.description)
11
+ assert_equal({}, query.prefixes)
12
+ assert_equal([], query.see)
13
+ assert_equal([], query.tag)
14
+ assert_equal([], query.author)
15
+ assert_equal([], query.endpoint)
16
+ assert_equal([], query.param)
17
+ assert_equal("DESCRIBE ?x", query.query)
18
+ assert_equal("DESCRIBE ?x", query.raw_query)
19
+ assert_equal("DESCRIBE+%3Fx", query.query_string)
20
+ assert_equal("DESCRIBE", query.type)
21
+ end
22
+
23
+ def test_type
24
+ query = SparqlDoc::Query.new("/path/to/query.rq", "describe ?x")
25
+ assert_equal("DESCRIBE", query.type)
26
+ end
27
+
28
+ def test_prefixes
29
+ sparql=<<-EOL
30
+ #Description
31
+ PREFIX foaf: <http://xmlns.com/foaf/0.1/>
32
+ prefix foo: <http://example.org/foo>
33
+ PREFIX bar: <http://example.org/bar>
34
+ prefix baz : <http://example.org/baz#>
35
+ DESCRIBE ?x
36
+ EOL
37
+ query = SparqlDoc::Query.new("/path/to/query.rq", sparql)
38
+ assert_equal("DESCRIBE", query.type)
39
+ assert_equal( 4, query.prefixes.size )
40
+ assert_equal( "http://xmlns.com/foaf/0.1/", query.prefixes["foaf"] )
41
+ assert_equal( "http://example.org/foo", query.prefixes["foo"] )
42
+ assert_equal( "http://example.org/bar", query.prefixes["bar"] )
43
+ assert_equal( "http://example.org/baz#", query.prefixes["baz"] )
44
+ end
45
+
46
+ def test_description
47
+ sparql=<<-EOL
48
+ #Description
49
+ DESCRIBE ?x
50
+ EOL
51
+ query = SparqlDoc::Query.new("/path/to/query.rq", sparql)
52
+ assert_equal("/path/to/query.rq", query.title)
53
+ assert_equal("Description", query.description)
54
+ assert_equal("DESCRIBE ?x", query.query)
55
+ assert_equal("#Description\nDESCRIBE ?x\n", query.raw_query)
56
+ end
57
+
58
+ def test_description
59
+ sparql=<<-EOL
60
+ #Description
61
+ #Over multiple
62
+ #...lines
63
+ DESCRIBE ?x
64
+ EOL
65
+ query = SparqlDoc::Query.new("/path/to/query.rq", sparql)
66
+ assert_equal("/path/to/query.rq", query.title)
67
+ assert_equal("Description\nOver multiple\n...lines", query.description)
68
+ assert_equal("DESCRIBE ?x", query.query)
69
+ assert_equal("#Description\n#Over multiple\n#...lines\nDESCRIBE ?x\n", query.raw_query)
70
+ end
71
+
72
+ def test_title
73
+ sparql=<<-EOL
74
+ #Description
75
+ # @title My Query
76
+ DESCRIBE ?x
77
+ EOL
78
+ query = SparqlDoc::Query.new("/path/to/query.rq", sparql)
79
+ assert_equal("My Query", query.title)
80
+ assert_equal("Description", query.description)
81
+ assert_equal("DESCRIBE ?x", query.query)
82
+ end
83
+
84
+ def test_all
85
+ sparql=<<-EOL
86
+ #Description
87
+ # @title My Query
88
+ # @author leigh@ldodds.com
89
+ # @tag demo
90
+ # @tag test
91
+ # @see http://github.com/ldodds/sparql-doc
92
+ DESCRIBE ?x
93
+ EOL
94
+ query = SparqlDoc::Query.new("/path/to/query.rq", sparql)
95
+ assert_equal("My Query", query.title)
96
+ assert_equal("Description", query.description)
97
+ assert_equal("DESCRIBE ?x", query.query)
98
+ assert_equal(["leigh@ldodds.com"], query.author)
99
+ assert_equal(["http://github.com/ldodds/sparql-doc"], query.see)
100
+ assert_equal(["demo", "test"], query.tag)
101
+ end
102
+
103
+ def test_markdown
104
+ sparql=<<-EOL
105
+ #Description
106
+ DESCRIBE ?x
107
+ EOL
108
+ query = SparqlDoc::Query.new("/path/to/query.rq", sparql)
109
+ assert_equal("<p>Description<p>", query.description(true))
110
+ assert_equal("DESCRIBE ?x", query.query)
111
+ end
112
+
113
+ def test_markdown
114
+ sparql=<<-EOL
115
+ #See [my website](http://example.org)
116
+ DESCRIBE ?x
117
+ EOL
118
+ query = SparqlDoc::Query.new("/path/to/query.rq", sparql)
119
+ assert_equal("<p>See <a href=\"http://example.org\">my website</a></p>\n", query.description(true))
120
+ assert_equal("DESCRIBE ?x", query.query)
121
+ end
122
+
123
+ def test_provide_default_authors
124
+ query = SparqlDoc::Query.new("/path/to/query.rq", "DESCRIBE ?x", {"author" => ["Leigh Dodds"]})
125
+ assert_equal(["Leigh Dodds"], query.author)
126
+ end
127
+
128
+ def test_provide_default_endpoint
129
+ query = SparqlDoc::Query.new("/path/to/query.rq", "DESCRIBE ?x", {"endpoint" => ["http://example.org"]})
130
+ assert_equal(["http://example.org"], query.endpoint)
131
+ end
132
+
133
+ def test_provide_default_tag
134
+ query = SparqlDoc::Query.new("/path/to/query.rq", "DESCRIBE ?x", {"tag" => ["foo"]})
135
+ assert_equal(["foo"], query.tag)
136
+ end
137
+ end
@@ -0,0 +1,5 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'test/unit'
3
+
4
+ require 'tc_query.rb'
5
+ require 'tc_generator.rb'
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sparql-doc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Leigh Dodds
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: redcarpet
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: fakefs
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: SPARQL documentation generator
63
+ email: leigh@ldodds.com
64
+ executables:
65
+ - sparql-doc
66
+ extensions: []
67
+ extra_rdoc_files:
68
+ - README.md
69
+ files:
70
+ - README.md
71
+ - Rakefile
72
+ - bin/sparql-doc
73
+ - tests/ts_sparql_doc.rb
74
+ - tests/tc_generator.rb
75
+ - tests/tc_query.rb
76
+ - lib/sparql-doc.rb
77
+ - lib/sparql-doc/query.rb
78
+ - lib/sparql-doc/assets/codemirror.js
79
+ - lib/sparql-doc/assets/sparql.js
80
+ - lib/sparql-doc/assets/bootstrap.min.css
81
+ - lib/sparql-doc/assets/codemirror.css
82
+ - lib/sparql-doc/assets/jquery.js
83
+ - lib/sparql-doc/assets/bootstrap.min.js
84
+ - lib/sparql-doc/views/index.erb
85
+ - lib/sparql-doc/views/layout.erb
86
+ - lib/sparql-doc/views/query.erb
87
+ - lib/sparql-doc/generator.rb
88
+ homepage: http://github.com/ldodds/sparql-doc
89
+ licenses: []
90
+ post_install_message:
91
+ rdoc_options:
92
+ - --quiet
93
+ - --title
94
+ - SPARQL Doc Reference
95
+ - --main
96
+ - README
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: 1.9.3
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 1.8.23
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: SPARQL documentation generator
117
+ test_files:
118
+ - tests/ts_sparql_doc.rb