sparql-doc 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +41 -42
- data/Rakefile +5 -5
- data/lib/sparql-doc/generator.rb +35 -35
- data/lib/sparql-doc/query.rb +47 -45
- data/lib/sparql-doc/views/index.erb +7 -7
- data/lib/sparql-doc/views/layout.erb +12 -14
- data/tests/tc_query.rb +47 -47
- metadata +34 -42
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9846edfd5ef98f3ae56e4767dfbe8058b46eab735c0cd149dbf2539a6b1234a8
|
4
|
+
data.tar.gz: d4c30f68264419a9d813688832e5293fe6439d47cbbaaa841096d77df91d25de
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d09bea2e0730f3e136f0a3b36657844351c6c04fd7c76f8498a4c15616e8ce43329c891ef44d31a134d79c19bacd8ece8475db811b672b3579c832f754043524
|
7
|
+
data.tar.gz: 0e0239d5a8c85694db39de8768dd0ab6cb52104dfb33fba3f12c62e972859c5c53f8c7ea2547cf02973a8f356d1e503ae30b87af4f7c9a56128ec1614656aa7f
|
data/README.md
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
# Generate HTML documentation from SPARQL queries
|
2
2
|
|
3
|
-
`sparql-doc` provides a simple tool for generating browsable HTML documentation
|
3
|
+
`sparql-doc` provides a simple tool for generating browsable HTML documentation
|
4
4
|
from SPARQL queries.
|
5
5
|
|
6
|
-
This is particularly useful when preparing training materials or resources to
|
6
|
+
This is particularly useful when preparing training materials or resources to
|
7
7
|
help developers to use a particular dataset or SPARQL endpoint.
|
8
8
|
|
9
9
|
## Documenting SPARQL queries
|
10
10
|
|
11
|
-
`sparql-doc` supports markup for documenting sparql queries, as well as a
|
11
|
+
`sparql-doc` supports markup for documenting sparql queries, as well as a
|
12
12
|
package metadata for a collection of queries.
|
13
13
|
|
14
14
|
These features are described in the next sections.
|
15
15
|
|
16
16
|
### SPARQL Documentation Extensions
|
17
17
|
|
18
|
-
`sparql-doc` processes your SPARQL queries and looks for comments. Like Javadoc, rdoc and
|
18
|
+
`sparql-doc` processes your SPARQL queries and looks for comments. Like Javadoc, rdoc and
|
19
19
|
similar tools, the content of the comments are used to provide metadata
|
20
20
|
|
21
21
|
All simple documentation lines at the start of a query will be treated as its description. E.g:
|
@@ -23,7 +23,7 @@ All simple documentation lines at the start of a query will be treated as its de
|
|
23
23
|
#This is a description
|
24
24
|
#of my query. It has multiple
|
25
25
|
#lines
|
26
|
-
DESCRIBE ?x
|
26
|
+
DESCRIBE ?x
|
27
27
|
|
28
28
|
Special tag can be used to specify other metadata, such as the title of a query:
|
29
29
|
|
@@ -31,7 +31,7 @@ Special tag can be used to specify other metadata, such as the title of a query:
|
|
31
31
|
#of my query. It has multiple
|
32
32
|
#lines
|
33
33
|
# @title My Query Title
|
34
|
-
DESCRIBE ?x
|
34
|
+
DESCRIBE ?x
|
35
35
|
|
36
36
|
The full list of supported tags is:
|
37
37
|
|
@@ -52,14 +52,14 @@ Here's an example that uses all these:
|
|
52
52
|
# @see http://www.isbn.org/
|
53
53
|
# @tag book
|
54
54
|
# @tag isbn
|
55
|
-
# @endpoint http://bnb.data.bl.uk/sparql
|
56
|
-
PREFIX bibo: <http://purl.org/ontology/bibo/>
|
55
|
+
# @endpoint http://bnb.data.bl.uk/sparql
|
56
|
+
PREFIX bibo: <http://purl.org/ontology/bibo/>
|
57
57
|
DESCRIBE ?uri WHERE {
|
58
58
|
?uri bibo:isbn10 "0261102214".
|
59
59
|
}
|
60
60
|
|
61
|
-
The query description can be written in [Markdown](http://daringfireball.net/projects/markdown/). So
|
62
|
-
you can include embedded markup, e.g. links, that help to further document a query.
|
61
|
+
The query description can be written in [Markdown](http://daringfireball.net/projects/markdown/). So
|
62
|
+
you can include embedded markup, e.g. links, that help to further document a query.
|
63
63
|
For example:
|
64
64
|
|
65
65
|
#This query illustrates how to describe a resource which is identified
|
@@ -68,40 +68,40 @@ For example:
|
|
68
68
|
# @author Leigh Dodds
|
69
69
|
# @tag book
|
70
70
|
# @tag isbn
|
71
|
-
# @endpoint http://bnb.data.bl.uk/sparql
|
72
|
-
PREFIX bibo: <http://purl.org/ontology/bibo/>
|
71
|
+
# @endpoint http://bnb.data.bl.uk/sparql
|
72
|
+
PREFIX bibo: <http://purl.org/ontology/bibo/>
|
73
73
|
DESCRIBE ?uri WHERE {
|
74
74
|
?uri bibo:isbn10 "0261102214".
|
75
75
|
}
|
76
76
|
|
77
77
|
### Overview Documentation
|
78
78
|
|
79
|
-
When processing a directory of queries, `sparql-doc` will automatically look for a file called
|
80
|
-
`overview.md`. If found, this file will be automatically parsed as Markdown and its contents included
|
79
|
+
When processing a directory of queries, `sparql-doc` will automatically look for a file called
|
80
|
+
`overview.md`. If found, this file will be automatically parsed as Markdown and its contents included
|
81
81
|
in an Overview section on the homepage of the documentation.
|
82
82
|
|
83
|
-
While the `description` in the `package.json` file is intended to provide a one line summary of the
|
84
|
-
package, the `overview.md` file is intended to provide a more detailed introduction. Both are optional,
|
83
|
+
While the `description` in the `package.json` file is intended to provide a one line summary of the
|
84
|
+
package, the `overview.md` file is intended to provide a more detailed introduction. Both are optional,
|
85
85
|
so authors can choose which approach they prefer.
|
86
86
|
|
87
87
|
### Package Metadata
|
88
88
|
|
89
|
-
`sparql-doc` considers a directory of SPARQL queries to be a _package_. Metadata that describes a package
|
90
|
-
and how its documentation should be generated is provided by a valid JSON file called `package.json` which
|
89
|
+
`sparql-doc` considers a directory of SPARQL queries to be a _package_. Metadata that describes a package
|
90
|
+
and how its documentation should be generated is provided by a valid JSON file called `package.json` which
|
91
91
|
is found in the same directory.
|
92
92
|
|
93
|
-
The following example of a package.json file shows how to provide a title and a short description
|
93
|
+
The following example of a package.json file shows how to provide a title and a short description
|
94
94
|
of a package of files. The title and description will automatically be injected into the documentation.
|
95
95
|
|
96
96
|
{
|
97
97
|
"title": "BNB SPARQL Queries",
|
98
98
|
"description": "A collection of SPARQL queries for the British National Bibliography"
|
99
|
-
}
|
99
|
+
}
|
100
100
|
|
101
|
-
It is common for a collection of queries to be written by the same person, be tagged in the same
|
102
|
-
way, or be useful against the same collection of endpoints. Rather than repeatedly apply the
|
103
|
-
`@author`, `@tag` and `@endpoint` annotations to all queries in a package, default values can be
|
104
|
-
specified in the `package.json` file.
|
101
|
+
It is common for a collection of queries to be written by the same person, be tagged in the same
|
102
|
+
way, or be useful against the same collection of endpoints. Rather than repeatedly apply the
|
103
|
+
`@author`, `@tag` and `@endpoint` annotations to all queries in a package, default values can be
|
104
|
+
specified in the `package.json` file.
|
105
105
|
|
106
106
|
The following example shows how to do this:
|
107
107
|
|
@@ -112,20 +112,20 @@ The following example shows how to do this:
|
|
112
112
|
"endpoint": ["http://bnb.data.bl.uk/sparql"]
|
113
113
|
}
|
114
114
|
|
115
|
-
Note that because `@author`, `@tag` and `@endpoint` are all multi-valued annotations, their values
|
115
|
+
Note that because `@author`, `@tag` and `@endpoint` are all multi-valued annotations, their values
|
116
116
|
must be specified as a JSON array.
|
117
117
|
|
118
|
-
The `package.json` file can also be used to indicate that extra files in the query directory should be
|
118
|
+
The `package.json` file can also be used to indicate that extra files in the query directory should be
|
119
119
|
processed and included in the documentation. E.g.:
|
120
120
|
|
121
121
|
{
|
122
122
|
"title": "BNB SPARQL Queries",
|
123
123
|
"description": "A collection of SPARQL queries for the British National Bibliography"
|
124
124
|
"extra-files": ["more-info.md"]
|
125
|
-
}
|
125
|
+
}
|
126
126
|
|
127
|
-
This will trigger `sparql-doc` to process the `more-info.md` file as Markdown, converting it to
|
128
|
-
`more-info.html` which is added to the output directory. A link to `more-info` will be automatically
|
127
|
+
This will trigger `sparql-doc` to process the `more-info.md` file as Markdown, converting it to
|
128
|
+
`more-info.html` which is added to the output directory. A link to `more-info` will be automatically
|
129
129
|
added to the header navigation
|
130
130
|
|
131
131
|
## Example
|
@@ -142,23 +142,22 @@ Here's [the example output](http://ldodds.github.com/sparql-doc/) using the exam
|
|
142
142
|
|
143
143
|
You'll need to make sure you have the following installed:
|
144
144
|
|
145
|
-
* Ruby
|
145
|
+
* Ruby 2.5.0+
|
146
146
|
* RubyGems
|
147
|
+
* Bundler
|
147
148
|
* Rake
|
148
149
|
|
149
|
-
|
150
|
-
|
151
|
-
[sudo] gem install json redcarpet
|
152
|
-
|
153
|
-
Once you have those installed, clone the repository and run the provided rake targets to build and install the gem
|
150
|
+
Once you have those installed, clone the repository and run the provided rake targets to build and install the gem
|
154
151
|
locally:
|
155
152
|
|
156
153
|
git clone https://github.com/ldodds/sparql-doc.git
|
157
154
|
cd sparql-doc
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
155
|
+
|
156
|
+
The code uses two gems which you'll need to have installed: JSON and [Redcarpet](https://github.com/vmg/redcarpet):
|
157
|
+
|
158
|
+
bundle install
|
159
|
+
|
160
|
+
Once installed you should be able to run the `bin/sparql-doc` command-line tool.
|
162
161
|
|
163
162
|
## Usage
|
164
163
|
|
@@ -168,12 +167,12 @@ This takes two parameters:
|
|
168
167
|
|
169
168
|
* The input directory. The tool will process all `.rq` files in that directory
|
170
169
|
* The output directory. All HTML output and required assets will be placed here
|
171
|
-
|
170
|
+
|
172
171
|
E.g. you can run:
|
173
172
|
|
174
173
|
sparql-doc examples/bnb /your/output/directory
|
175
|
-
|
176
|
-
This will generate documentation from the bundled examples and place it into the specified
|
174
|
+
|
175
|
+
This will generate documentation from the bundled examples and place it into the specified
|
177
176
|
directory.
|
178
177
|
|
179
178
|
Later versions will support additional command-line options
|
data/Rakefile
CHANGED
@@ -3,7 +3,7 @@ require 'rdoc/task'
|
|
3
3
|
require 'rake/testtask'
|
4
4
|
require 'rake/clean'
|
5
5
|
|
6
|
-
CLEAN.include ['*.gem', 'pkg']
|
6
|
+
CLEAN.include ['*.gem', 'pkg']
|
7
7
|
|
8
8
|
$spec = eval(File.read('sparql-doc.gemspec'))
|
9
9
|
|
@@ -11,19 +11,19 @@ Rake::RDocTask.new do |rdoc|
|
|
11
11
|
rdoc.rdoc_dir = 'doc/rdoc'
|
12
12
|
rdoc.options += RDOC_OPTS
|
13
13
|
rdoc.rdoc_files.include("README.md", "lib/**/*.rb")
|
14
|
-
rdoc.main = "README.md"
|
14
|
+
rdoc.main = "README.md"
|
15
15
|
end
|
16
16
|
|
17
17
|
Rake::TestTask.new do |test|
|
18
18
|
test.test_files = FileList['tests/tc_*.rb']
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
task :package do
|
22
|
-
sh %{gem build sparql-doc.gemspec}
|
22
|
+
sh %{gem build sparql-doc.gemspec}
|
23
23
|
end
|
24
24
|
|
25
25
|
task :install do
|
26
|
-
sh %{sudo gem install --no-
|
26
|
+
sh %{sudo gem install --no-document sparql-doc-#{$spec.version}.gem}
|
27
27
|
end
|
28
28
|
|
29
29
|
desc "Uninstall the gem"
|
data/lib/sparql-doc/generator.rb
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
module SparqlDoc
|
2
|
-
|
2
|
+
|
3
3
|
class Generator
|
4
|
-
|
4
|
+
|
5
5
|
attr_reader :dir, :graph, :queries, :package
|
6
|
-
|
6
|
+
|
7
7
|
def initialize(dir, output_dir, view_dir=nil, asset_dir=nil)
|
8
8
|
@dir = dir
|
9
|
-
@output_dir = output_dir
|
10
|
-
@asset_dir = asset_dir || File.join( File.dirname( __FILE__ ) , "assets")
|
9
|
+
@output_dir = output_dir
|
10
|
+
@asset_dir = asset_dir || File.join( File.dirname( __FILE__ ) , "assets")
|
11
11
|
@view_dir = view_dir || File.join( File.dirname( __FILE__ ) , "views")
|
12
12
|
@package = parse_package()
|
13
|
-
@queries = parse_queries()
|
13
|
+
@queries = parse_queries()
|
14
14
|
end
|
15
15
|
|
16
16
|
def read_template(name)
|
17
17
|
File.read(File.join(@view_dir, "#{name}.erb"))
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def parse_package()
|
21
21
|
package = File.join(@dir, "package.json")
|
22
22
|
if File.exists?(package)
|
23
|
-
return JSON.load( File.open(package) )
|
23
|
+
return JSON.load( File.open(package) )
|
24
24
|
end
|
25
25
|
Hash.new
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def parse_queries()
|
29
29
|
queries = []
|
30
30
|
Dir.glob("#{@dir}/*.rq") do |file|
|
@@ -32,17 +32,17 @@ module SparqlDoc
|
|
32
32
|
path = file.gsub("#{@dir}/", "")
|
33
33
|
queries << SparqlDoc::Query.new(path, content, @package)
|
34
34
|
end
|
35
|
-
queries.sort! {|x,y| x.title <=> y.title }
|
35
|
+
queries.sort! {|x,y| x.title <=> y.title }
|
36
36
|
queries
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def run()
|
40
40
|
copy_assets()
|
41
41
|
generate_index()
|
42
42
|
generate_query_pages()
|
43
43
|
copy_extra_files()
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def copy_assets(asset_dir=@asset_dir)
|
47
47
|
$stderr.puts("Copying assets");
|
48
48
|
if !File.exists?(@output_dir)
|
@@ -50,17 +50,17 @@ module SparqlDoc
|
|
50
50
|
end
|
51
51
|
Dir.new(asset_dir).each() do |file|
|
52
52
|
if file != "." and file != ".."
|
53
|
-
FileUtils.cp( File.join(asset_dir, file),
|
53
|
+
FileUtils.cp( File.join(asset_dir, file),
|
54
54
|
File.join(@output_dir, file) )
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
def copy_extra_files()
|
60
60
|
@package["extra-files"].each do |file|
|
61
61
|
markup = File.read( File.join(@dir, file) )
|
62
62
|
renderer = Redcarpet::Render::HTML.new({})
|
63
|
-
markdown = Redcarpet::Markdown.new(renderer, {})
|
63
|
+
markdown = Redcarpet::Markdown.new(renderer, {})
|
64
64
|
html = layout do
|
65
65
|
markdown.render(markup)
|
66
66
|
end
|
@@ -70,23 +70,23 @@ module SparqlDoc
|
|
70
70
|
end
|
71
71
|
end if @package["extra-files"]
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
def get_overview()
|
75
75
|
overview = File.join(@dir, "overview.md")
|
76
76
|
if File.exists?( overview )
|
77
77
|
markup = File.read( overview )
|
78
78
|
renderer = Redcarpet::Render::HTML.new({})
|
79
79
|
markdown = Redcarpet::Markdown.new(renderer, {})
|
80
|
-
return markdown.render(markup)
|
81
|
-
end
|
80
|
+
return markdown.render(markup)
|
81
|
+
end
|
82
82
|
nil
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
def generate_index()
|
86
86
|
$stderr.puts("Generating index.html");
|
87
|
-
|
88
|
-
|
89
|
-
|
87
|
+
_title = @package["title"] || "Sparql Query Documentation"
|
88
|
+
_overview = get_overview()
|
89
|
+
_description = @package["description"] || ""
|
90
90
|
template = ERB.new( read_template(:index) )
|
91
91
|
html = layout do
|
92
92
|
b = binding
|
@@ -96,29 +96,29 @@ module SparqlDoc
|
|
96
96
|
f.puts(html)
|
97
97
|
end
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
def layout
|
101
|
-
b = binding
|
102
|
-
|
103
|
-
|
101
|
+
b = binding
|
102
|
+
_title = @package["title"] || "Sparql Query Documentation"
|
103
|
+
_overview = get_overview()
|
104
104
|
ERB.new( read_template(:layout) ).result(b)
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
107
|
def generate_query_pages()
|
108
108
|
template = ERB.new( read_template(:query) )
|
109
109
|
@queries.each do |query|
|
110
110
|
$stderr.puts("Generating docs for #{query.path}")
|
111
111
|
File.open( File.join(@output_dir, query.output_filename), "w" ) do |f|
|
112
|
-
b = binding
|
113
|
-
|
114
|
-
|
112
|
+
b = binding
|
113
|
+
_title = @package["title"] || "Sparql Query Documentation"
|
114
|
+
_overview = get_overview()
|
115
115
|
html = layout do
|
116
116
|
template.result(b)
|
117
|
-
end
|
117
|
+
end
|
118
118
|
f.puts( html )
|
119
|
-
end
|
120
|
-
end
|
119
|
+
end
|
120
|
+
end
|
121
121
|
end
|
122
|
-
|
122
|
+
|
123
123
|
end
|
124
|
-
end
|
124
|
+
end
|
data/lib/sparql-doc/query.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
module SparqlDoc
|
2
2
|
|
3
|
-
#Wrapper for SPARQL query
|
3
|
+
#Wrapper for SPARQL query
|
4
4
|
class Query
|
5
|
-
|
5
|
+
|
6
6
|
attr_reader :path, :query, :raw_query, :prefixes, :type, :package
|
7
7
|
|
8
8
|
ANNOTATIONS = {
|
9
9
|
:author => {
|
10
|
-
:multi => true
|
10
|
+
:multi => true
|
11
11
|
},
|
12
12
|
:see => {
|
13
|
-
:multi => true
|
14
|
-
},
|
13
|
+
:multi => true
|
14
|
+
},
|
15
15
|
:tag => {
|
16
|
-
:multi => true
|
17
|
-
},
|
16
|
+
:multi => true
|
17
|
+
},
|
18
18
|
:title => {
|
19
|
-
:multi => false
|
19
|
+
:multi => false
|
20
20
|
},
|
21
21
|
:endpoint => {
|
22
22
|
:multi => true
|
@@ -25,11 +25,11 @@ module SparqlDoc
|
|
25
25
|
:multi => true
|
26
26
|
}
|
27
27
|
}
|
28
|
-
|
28
|
+
|
29
29
|
ANNOTATIONS.each do |var, config|
|
30
30
|
attr_reader(var)
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def initialize(path, query, package={})
|
34
34
|
ANNOTATIONS.each do |var, config|
|
35
35
|
if config[:multi]
|
@@ -40,23 +40,23 @@ module SparqlDoc
|
|
40
40
|
end
|
41
41
|
@path = path
|
42
42
|
@query = query
|
43
|
-
@raw_query = query
|
43
|
+
@raw_query = query
|
44
44
|
@title = @path
|
45
45
|
@description = ""
|
46
46
|
@prefixes = {}
|
47
|
-
|
47
|
+
|
48
48
|
["endpoint", "author", "tag"].each do |annotation|
|
49
49
|
if package[annotation]
|
50
50
|
instance_variable_set( "@#{annotation}", package[annotation])
|
51
51
|
end
|
52
|
-
end
|
52
|
+
end
|
53
53
|
parseQuery()
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def output_filename
|
57
57
|
return "#{path.gsub(".rq", "")}.html"
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
def description(html=false)
|
61
61
|
if html
|
62
62
|
renderer = Redcarpet::Render::HTML.new({})
|
@@ -65,45 +65,45 @@ module SparqlDoc
|
|
65
65
|
end
|
66
66
|
@description
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
def query_string
|
70
70
|
CGI::escape( @query )
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
private
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
else
|
90
|
-
instance_variable_set("@#{annotation}", matches[2].strip)
|
91
|
-
end
|
92
|
-
description = true
|
74
|
+
|
75
|
+
def parseQuery
|
76
|
+
query_lines = []
|
77
|
+
header = true
|
78
|
+
description = false
|
79
|
+
description_lines = []
|
80
|
+
@raw_query.split("\n").each do |line|
|
81
|
+
if ( header && line.match(/^#/) )
|
82
|
+
if ( matches = line.match(/^# *@([a-zA-Z]+) *(.+)$/i) )
|
83
|
+
annotation = matches[1]
|
84
|
+
config = ANNOTATIONS[ annotation.intern ]
|
85
|
+
if config
|
86
|
+
if config[:multi]
|
87
|
+
val = instance_variable_get("@#{annotation}")
|
88
|
+
val << matches[2].strip
|
93
89
|
else
|
94
|
-
|
90
|
+
instance_variable_set("@#{annotation}", matches[2].strip)
|
95
91
|
end
|
96
|
-
|
97
|
-
|
92
|
+
description = true
|
93
|
+
else
|
94
|
+
$stderr.puts("Ignoring unknown annotation: @#{annotation}")
|
98
95
|
end
|
99
|
-
end
|
100
96
|
else
|
101
|
-
|
102
|
-
|
97
|
+
if (description == false)
|
98
|
+
description_lines << line[1..-1].strip
|
99
|
+
end
|
103
100
|
end
|
101
|
+
else
|
102
|
+
header = false
|
103
|
+
query_lines << line
|
104
104
|
end
|
105
105
|
@description = description_lines.join("\n") unless description_lines.empty?
|
106
|
-
@query = query_lines.join("\n") unless query_lines.empty?
|
106
|
+
@query = query_lines.join("\n") unless query_lines.empty?
|
107
107
|
@query.strip!
|
108
108
|
query_lines.each do |line|
|
109
109
|
if (matches = line.match(/^ *PREFIX *([a-zA-Z_-]+) *: *<(.+)>$/i) )
|
@@ -112,7 +112,9 @@ module SparqlDoc
|
|
112
112
|
if (matches = line.match(/^ *(SELECT|CONSTRUCT|DESCRIBE|ASK) */i) )
|
113
113
|
@type = matches[1].upcase
|
114
114
|
end
|
115
|
-
end
|
115
|
+
end
|
116
116
|
end
|
117
|
+
end
|
117
118
|
end
|
118
|
-
|
119
|
+
|
120
|
+
end
|
@@ -1,23 +1,23 @@
|
|
1
1
|
<div class="container">
|
2
2
|
<div class="hero-unit">
|
3
|
-
<h1><%=
|
3
|
+
<h1><%= _title %></h1>
|
4
4
|
</div>
|
5
5
|
|
6
6
|
<div class="row">
|
7
7
|
<div class="span12">
|
8
|
-
<p><%=
|
8
|
+
<p><%= _description %></p>
|
9
9
|
</div>
|
10
10
|
</div>
|
11
11
|
|
12
|
-
<% if
|
12
|
+
<% if _overview %>
|
13
13
|
<div class="row">
|
14
14
|
<div class="span12">
|
15
15
|
<h3 id="overview">Overview</h3>
|
16
|
-
<%=
|
16
|
+
<%= _overview %>
|
17
17
|
</div>
|
18
18
|
</div>
|
19
|
-
<% end %>
|
20
|
-
|
19
|
+
<% end %>
|
20
|
+
|
21
21
|
<div class="row">
|
22
22
|
<div class="span12">
|
23
23
|
<h3>Queries</h3>
|
@@ -34,7 +34,7 @@
|
|
34
34
|
<td><a href="<%= query.output_filename %>"><%= query.title %></a></td><td><code><%= query.path %></code></td>
|
35
35
|
</tr>
|
36
36
|
<% end %>
|
37
|
-
</tbody>
|
37
|
+
</tbody>
|
38
38
|
</table>
|
39
39
|
</div>
|
40
40
|
</div>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<html>
|
2
2
|
<head>
|
3
3
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
4
|
-
<title><%=
|
4
|
+
<title><%= _title %></title>
|
5
5
|
<link href="bootstrap.min.css" rel="stylesheet">
|
6
6
|
<link rel="stylesheet" href="codemirror.css">
|
7
7
|
<style type="text/css">
|
@@ -12,23 +12,23 @@
|
|
12
12
|
.sidebar-nav {
|
13
13
|
padding: 9px 0;
|
14
14
|
}
|
15
|
-
</style>
|
16
|
-
<script src="jquery.js"></script>
|
15
|
+
</style>
|
16
|
+
<script src="jquery.js"></script>
|
17
17
|
<script src="bootstrap.min.js"></script>
|
18
|
-
|
19
|
-
<script src="codemirror.js" type="text/javascript"></script>
|
20
|
-
<script src="sparql.js"></script>
|
18
|
+
|
19
|
+
<script src="codemirror.js" type="text/javascript"></script>
|
20
|
+
<script src="sparql.js"></script>
|
21
21
|
</head>
|
22
22
|
<body>
|
23
|
-
|
23
|
+
|
24
24
|
<div class="navbar navbar-inverse navbar-fixed-top">
|
25
25
|
<div class="navbar-inner">
|
26
26
|
<div class="container-fluid">
|
27
|
-
<a class="brand" href="index.html"><%=
|
27
|
+
<a class="brand" href="index.html"><%= _title %></a>
|
28
28
|
<ul class="nav">
|
29
|
-
<% if
|
29
|
+
<% if _overview %>
|
30
30
|
<li><a href="index.html#overview">Overview</a></li>
|
31
|
-
<% end %>
|
31
|
+
<% end %>
|
32
32
|
<% if @package["extra-files"] %>
|
33
33
|
<% @package["extra-files"].each do |file| %>
|
34
34
|
<li><a href="<%= file.gsub(".md", ".html") %>">
|
@@ -40,9 +40,7 @@
|
|
40
40
|
</div>
|
41
41
|
</div>
|
42
42
|
</div>
|
43
|
-
|
43
|
+
|
44
44
|
<%= yield %>
|
45
|
-
</body>
|
45
|
+
</body>
|
46
46
|
</html>
|
47
|
-
|
48
|
-
|
data/tests/tc_query.rb
CHANGED
@@ -3,8 +3,8 @@ require 'sparql-doc'
|
|
3
3
|
require 'test/unit'
|
4
4
|
|
5
5
|
class QueryTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
def test_basic
|
6
|
+
|
7
|
+
def test_basic
|
8
8
|
query = SparqlDoc::Query.new("/path/to/query.rq", "DESCRIBE ?x")
|
9
9
|
assert_equal("/path/to/query.rq", query.title)
|
10
10
|
assert_equal("", query.description)
|
@@ -14,19 +14,19 @@ class QueryTest < Test::Unit::TestCase
|
|
14
14
|
assert_equal([], query.author)
|
15
15
|
assert_equal([], query.endpoint)
|
16
16
|
assert_equal([], query.param)
|
17
|
-
assert_equal("DESCRIBE ?x", query.query)
|
17
|
+
assert_equal("DESCRIBE ?x", query.query)
|
18
18
|
assert_equal("DESCRIBE ?x", query.raw_query)
|
19
19
|
assert_equal("DESCRIBE+%3Fx", query.query_string)
|
20
20
|
assert_equal("DESCRIBE", query.type)
|
21
21
|
end
|
22
22
|
|
23
|
-
def test_type
|
23
|
+
def test_type
|
24
24
|
query = SparqlDoc::Query.new("/path/to/query.rq", "describe ?x")
|
25
25
|
assert_equal("DESCRIBE", query.type)
|
26
|
-
end
|
27
|
-
|
26
|
+
end
|
27
|
+
|
28
28
|
def test_prefixes
|
29
|
-
sparql=<<-EOL
|
29
|
+
sparql=<<-EOL
|
30
30
|
#Description
|
31
31
|
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
|
32
32
|
prefix foo: <http://example.org/foo>
|
@@ -35,28 +35,28 @@ prefix baz : <http://example.org/baz#>
|
|
35
35
|
DESCRIBE ?x
|
36
36
|
EOL
|
37
37
|
query = SparqlDoc::Query.new("/path/to/query.rq", sparql)
|
38
|
-
assert_equal("DESCRIBE", query.type)
|
38
|
+
assert_equal("DESCRIBE", query.type)
|
39
39
|
assert_equal( 4, query.prefixes.size )
|
40
40
|
assert_equal( "http://xmlns.com/foaf/0.1/", query.prefixes["foaf"] )
|
41
41
|
assert_equal( "http://example.org/foo", query.prefixes["foo"] )
|
42
42
|
assert_equal( "http://example.org/bar", query.prefixes["bar"] )
|
43
43
|
assert_equal( "http://example.org/baz#", query.prefixes["baz"] )
|
44
44
|
end
|
45
|
-
|
46
|
-
def test_description
|
47
|
-
sparql=<<-EOL
|
45
|
+
|
46
|
+
def test_description
|
47
|
+
sparql=<<-EOL
|
48
48
|
#Description
|
49
49
|
DESCRIBE ?x
|
50
50
|
EOL
|
51
51
|
query = SparqlDoc::Query.new("/path/to/query.rq", sparql)
|
52
52
|
assert_equal("/path/to/query.rq", query.title)
|
53
53
|
assert_equal("Description", query.description)
|
54
|
-
assert_equal("DESCRIBE ?x", query.query)
|
55
|
-
assert_equal("#Description\nDESCRIBE ?x
|
54
|
+
assert_equal("DESCRIBE ?x", query.query)
|
55
|
+
assert_equal("#Description\nDESCRIBE ?x", query.raw_query)
|
56
56
|
end
|
57
|
-
|
58
|
-
def
|
59
|
-
sparql=<<-EOL
|
57
|
+
|
58
|
+
def test_description_multiple_lines
|
59
|
+
sparql=<<-EOL
|
60
60
|
#Description
|
61
61
|
#Over multiple
|
62
62
|
#...lines
|
@@ -65,73 +65,73 @@ EOL
|
|
65
65
|
query = SparqlDoc::Query.new("/path/to/query.rq", sparql)
|
66
66
|
assert_equal("/path/to/query.rq", query.title)
|
67
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
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_title
|
73
|
-
sparql=<<-EOL
|
68
|
+
assert_equal("DESCRIBE ?x", query.query)
|
69
|
+
assert_equal("#Description\n#Over multiple\n#...lines\nDESCRIBE ?x", query.raw_query)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_title
|
73
|
+
sparql=<<-EOL
|
74
74
|
#Description
|
75
|
-
# @title My Query
|
75
|
+
# @title My Query
|
76
76
|
DESCRIBE ?x
|
77
77
|
EOL
|
78
78
|
query = SparqlDoc::Query.new("/path/to/query.rq", sparql)
|
79
79
|
assert_equal("My Query", query.title)
|
80
80
|
assert_equal("Description", query.description)
|
81
|
-
assert_equal("DESCRIBE ?x", query.query)
|
81
|
+
assert_equal("DESCRIBE ?x", query.query)
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
def test_all
|
85
|
-
sparql=<<-EOL
|
85
|
+
sparql=<<-EOL
|
86
86
|
#Description
|
87
|
-
# @title My Query
|
87
|
+
# @title My Query
|
88
88
|
# @author leigh@ldodds.com
|
89
89
|
# @tag demo
|
90
90
|
# @tag test
|
91
|
-
# @see http://github.com/ldodds/sparql-doc
|
91
|
+
# @see http://github.com/ldodds/sparql-doc
|
92
92
|
DESCRIBE ?x
|
93
93
|
EOL
|
94
94
|
query = SparqlDoc::Query.new("/path/to/query.rq", sparql)
|
95
95
|
assert_equal("My Query", query.title)
|
96
96
|
assert_equal("Description", query.description)
|
97
|
-
assert_equal("DESCRIBE ?x", query.query)
|
97
|
+
assert_equal("DESCRIBE ?x", query.query)
|
98
98
|
assert_equal(["leigh@ldodds.com"], query.author)
|
99
99
|
assert_equal(["http://github.com/ldodds/sparql-doc"], query.see)
|
100
|
-
assert_equal(["demo", "test"], query.tag)
|
101
|
-
end
|
100
|
+
assert_equal(["demo", "test"], query.tag)
|
101
|
+
end
|
102
102
|
|
103
|
-
def test_markdown
|
104
|
-
sparql=<<-EOL
|
103
|
+
def test_markdown
|
104
|
+
sparql=<<-EOL
|
105
105
|
#Description
|
106
106
|
DESCRIBE ?x
|
107
107
|
EOL
|
108
108
|
query = SparqlDoc::Query.new("/path/to/query.rq", sparql)
|
109
|
-
assert_equal("<p>Description
|
110
|
-
assert_equal("DESCRIBE ?x", query.query)
|
111
|
-
end
|
112
|
-
|
113
|
-
def
|
114
|
-
sparql=<<-EOL
|
109
|
+
assert_equal("<p>Description</p>\n", query.description(true))
|
110
|
+
assert_equal("DESCRIBE ?x", query.query)
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_markdown_more
|
114
|
+
sparql=<<-EOL
|
115
115
|
#See [my website](http://example.org)
|
116
116
|
DESCRIBE ?x
|
117
117
|
EOL
|
118
118
|
query = SparqlDoc::Query.new("/path/to/query.rq", sparql)
|
119
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
|
120
|
+
assert_equal("DESCRIBE ?x", query.query)
|
121
|
+
end
|
122
122
|
|
123
123
|
def test_provide_default_authors
|
124
124
|
query = SparqlDoc::Query.new("/path/to/query.rq", "DESCRIBE ?x", {"author" => ["Leigh Dodds"]})
|
125
|
-
assert_equal(["Leigh Dodds"], query.author)
|
126
|
-
end
|
125
|
+
assert_equal(["Leigh Dodds"], query.author)
|
126
|
+
end
|
127
127
|
|
128
128
|
def test_provide_default_endpoint
|
129
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
|
130
|
+
assert_equal(["http://example.org"], query.endpoint)
|
131
|
+
end
|
132
132
|
|
133
133
|
def test_provide_default_tag
|
134
134
|
query = SparqlDoc::Query.new("/path/to/query.rq", "DESCRIBE ?x", {"tag" => ["foo"]})
|
135
|
-
assert_equal(["foo"], query.tag)
|
136
|
-
end
|
135
|
+
assert_equal(["foo"], query.tag)
|
136
|
+
end
|
137
137
|
end
|
metadata
CHANGED
@@ -1,65 +1,58 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sparql-doc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.5
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Leigh Dodds
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2021-02-05 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: json
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
19
|
+
version: 2.5.1
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
26
|
+
version: 2.5.1
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: redcarpet
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
33
|
+
version: 3.5.1
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
40
|
+
version: 3.5.1
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: fakefs
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - "~>"
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
47
|
+
version: 1.3.2
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - "~>"
|
60
53
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
62
|
-
description:
|
54
|
+
version: 1.3.2
|
55
|
+
description: Generates HTML documentation for a collection of sparql queries
|
63
56
|
email: leigh@ldodds.com
|
64
57
|
executables:
|
65
58
|
- sparql-doc
|
@@ -70,49 +63,48 @@ files:
|
|
70
63
|
- README.md
|
71
64
|
- Rakefile
|
72
65
|
- bin/sparql-doc
|
73
|
-
- tests/ts_sparql_doc.rb
|
74
|
-
- tests/tc_generator.rb
|
75
|
-
- tests/tc_query.rb
|
76
66
|
- 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
67
|
- lib/sparql-doc/assets/bootstrap.min.css
|
68
|
+
- lib/sparql-doc/assets/bootstrap.min.js
|
81
69
|
- lib/sparql-doc/assets/codemirror.css
|
70
|
+
- lib/sparql-doc/assets/codemirror.js
|
82
71
|
- lib/sparql-doc/assets/jquery.js
|
83
|
-
- lib/sparql-doc/assets/
|
72
|
+
- lib/sparql-doc/assets/sparql.js
|
73
|
+
- lib/sparql-doc/generator.rb
|
74
|
+
- lib/sparql-doc/query.rb
|
84
75
|
- lib/sparql-doc/views/index.erb
|
85
76
|
- lib/sparql-doc/views/layout.erb
|
86
77
|
- lib/sparql-doc/views/query.erb
|
87
|
-
-
|
78
|
+
- tests/tc_generator.rb
|
79
|
+
- tests/tc_query.rb
|
80
|
+
- tests/ts_sparql_doc.rb
|
88
81
|
homepage: http://github.com/ldodds/sparql-doc
|
89
|
-
licenses:
|
82
|
+
licenses:
|
83
|
+
- CC0-1.0
|
84
|
+
metadata: {}
|
90
85
|
post_install_message:
|
91
86
|
rdoc_options:
|
92
|
-
- --quiet
|
93
|
-
- --title
|
87
|
+
- "--quiet"
|
88
|
+
- "--title"
|
94
89
|
- SPARQL Doc Reference
|
95
|
-
- --main
|
90
|
+
- "--main"
|
96
91
|
- README
|
97
92
|
require_paths:
|
98
93
|
- lib
|
99
94
|
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
-
none: false
|
101
95
|
requirements:
|
102
|
-
- -
|
96
|
+
- - ">="
|
103
97
|
- !ruby/object:Gem::Version
|
104
|
-
version:
|
98
|
+
version: 2.5.0
|
105
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
-
none: false
|
107
100
|
requirements:
|
108
|
-
- -
|
101
|
+
- - ">="
|
109
102
|
- !ruby/object:Gem::Version
|
110
103
|
version: '0'
|
111
104
|
requirements: []
|
112
|
-
|
113
|
-
rubygems_version: 1.8.23
|
105
|
+
rubygems_version: 3.1.2
|
114
106
|
signing_key:
|
115
|
-
specification_version:
|
107
|
+
specification_version: 4
|
116
108
|
summary: SPARQL documentation generator
|
117
109
|
test_files:
|
118
110
|
- tests/ts_sparql_doc.rb
|