ttl2html 1.3.5 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ttl2html/template.rb +39 -35
- data/lib/ttl2html/util.rb +32 -0
- data/lib/ttl2html/version.rb +1 -1
- data/lib/ttl2html.rb +114 -65
- data/locales/en.yml +2 -0
- data/locales/ja.yml +2 -0
- data/templates/about.html.erb +1 -1
- data/templates/default.html.erb +4 -1
- data/templates/index-list.html.erb +20 -0
- data/templates/index.html.erb +3 -11
- data/templates/layout.html.erb +8 -3
- data/templates/shape-table.html.erb +15 -3
- data/templates/triples-blank.html.erb +4 -0
- data/templates/triples-inverse.html.erb +20 -0
- data/templates/triples.html.erb +5 -9
- data/templates/version.html.erb +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfd5d041b79e5600dd3ef9beb2f2d41604414cd6d35cbb4a1c34c659a43861ef
|
4
|
+
data.tar.gz: 39fd23928a3608b9a9dba9d08dcf82034d713d90b8f695e24e735b4bbc46b487
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63654dfadd4a153c9858c4bff7e6726309d3f472f9887f9a8f343184565e673b83244e2dc98dd05da8c0c1cc629b4388b950da020fd1d78a791a3bbf422020ee
|
7
|
+
data.tar.gz: 3acab63f0efab2592d4a7423020c495fe0df3af3b8ba53eaad7c73f724a0d0385182732becbdfa0ea5b7e33c7862a8acbc5f9f8b7706a11aafb17fb45559345e
|
data/lib/ttl2html/template.rb
CHANGED
@@ -59,6 +59,7 @@ module TTL2HTML
|
|
59
59
|
def expand_shape(data, uri, prefixes = {})
|
60
60
|
return nil if not data[uri]
|
61
61
|
return nil if not data[uri]["http://www.w3.org/ns/shacl#property"]
|
62
|
+
prefix_used = {}
|
62
63
|
result = data[uri]["http://www.w3.org/ns/shacl#property"].sort_by do |e|
|
63
64
|
e["http://www.w3.org/ns/shacl#order"]
|
64
65
|
end.map do |property|
|
@@ -67,6 +68,7 @@ module TTL2HTML
|
|
67
68
|
prefixes.each do |prefix, val|
|
68
69
|
if path.index(val) == 0
|
69
70
|
shorten_path = path.sub(/\A#{val}/, "#{prefix}:")
|
71
|
+
prefix_used[prefix] = val
|
70
72
|
end
|
71
73
|
end
|
72
74
|
repeatable = false
|
@@ -107,41 +109,16 @@ module TTL2HTML
|
|
107
109
|
nodeKind: data[property]["http://www.w3.org/ns/shacl#nodeKind"] ? data[property]["http://www.w3.org/ns/shacl#nodeKind"].first : nil,
|
108
110
|
nodes: nodes,
|
109
111
|
node_mode: node_mode,
|
112
|
+
prefix: prefix_used,
|
110
113
|
}
|
111
114
|
end
|
112
115
|
template = "shape-table.html.erb"
|
113
116
|
tmpl = Template.new(template)
|
114
|
-
tmpl.to_html_raw(template, {properties: result})
|
117
|
+
tmpl.to_html_raw(template, { properties: result, prefix: prefix_used })
|
115
118
|
end
|
116
119
|
|
117
120
|
# helper method:
|
118
|
-
|
119
|
-
path = nil
|
120
|
-
if @param[:uri_mappings]
|
121
|
-
@param[:uri_mappings].each do |mapping|
|
122
|
-
local_file = uri.sub(@param[:base_uri], "")
|
123
|
-
if mapping["regexp"] =~ local_file
|
124
|
-
path = local_file.sub(mapping["regexp"], mapping["path"])
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
if path.nil?
|
129
|
-
if suffix == ".html"
|
130
|
-
if @param[:data_global] and @param[:data_global].keys.find{|e| e.start_with?(uri + "/") }
|
131
|
-
path = uri + "/index"
|
132
|
-
elsif uri.end_with?("/")
|
133
|
-
path = uri + "index"
|
134
|
-
else
|
135
|
-
path = uri
|
136
|
-
end
|
137
|
-
else
|
138
|
-
path = uri
|
139
|
-
end
|
140
|
-
end
|
141
|
-
path = path.sub(@param[:base_uri], "") if @param[:base_uri]
|
142
|
-
path << suffix
|
143
|
-
path
|
144
|
-
end
|
121
|
+
include TTL2HTML::Util
|
145
122
|
def relative_path(dest)
|
146
123
|
path = nil
|
147
124
|
dest_uri = RDF::IRI.parse(dest)
|
@@ -158,7 +135,7 @@ module TTL2HTML
|
|
158
135
|
def relative_path_uri(dest_uri, base_uri)
|
159
136
|
if dest_uri.start_with? base_uri
|
160
137
|
dest = dest_uri.sub(base_uri, "")
|
161
|
-
dest = uri_mapping_to_path(dest, "")
|
138
|
+
dest = uri_mapping_to_path(dest, @param, "")
|
162
139
|
relative_path(dest)
|
163
140
|
else
|
164
141
|
dest_uri
|
@@ -217,14 +194,18 @@ module TTL2HTML
|
|
217
194
|
object
|
218
195
|
end
|
219
196
|
end
|
220
|
-
def format_property(property, labels = {})
|
221
|
-
if
|
197
|
+
def format_property(property, labels = {}, subject = nil)
|
198
|
+
subject = @param[:blank_subject] if not subject and @param[:blank_subject]
|
199
|
+
subject_class = @param[:data_global][subject][RDF.type.to_s]&.first if subject
|
200
|
+
if subject_class and @param[:labels_with_class][subject_class] and @param[:labels_with_class][subject_class][property]
|
201
|
+
@param[:labels_with_class][subject_class][property]
|
202
|
+
elsif labels and labels[property]
|
222
203
|
labels[property]
|
223
204
|
else
|
224
205
|
property.split(/[\/\#]/).last.capitalize
|
225
206
|
end
|
226
207
|
end
|
227
|
-
def format_object(object, data)
|
208
|
+
def format_object(object, data, type = {})
|
228
209
|
if object =~ /\Ahttps?:\/\//
|
229
210
|
rel_path = relative_path_uri(object, param[:base_uri])
|
230
211
|
if param[:data_global][object]
|
@@ -233,12 +214,16 @@ module TTL2HTML
|
|
233
214
|
"<a href=\"#{rel_path}\">#{object}</a>"
|
234
215
|
end
|
235
216
|
elsif object =~ /\A_:/ and param[:data_global][object]
|
236
|
-
|
217
|
+
if type[:inverse] and param[:data_inverse_global][object]
|
218
|
+
format_triples(param[:data_inverse_global][object], inverse: true, blank: true)
|
219
|
+
else
|
220
|
+
format_triples(param[:data_global][object], blank: true)
|
221
|
+
end
|
237
222
|
else
|
238
223
|
object
|
239
224
|
end
|
240
225
|
end
|
241
|
-
def format_triples(triples, type =
|
226
|
+
def format_triples(triples, type = {})
|
242
227
|
param_local = @param.dup.merge(data: triples)
|
243
228
|
param_local[:type] = type
|
244
229
|
if @param[:labels_with_class] and triples["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"]
|
@@ -265,7 +250,26 @@ module TTL2HTML
|
|
265
250
|
end
|
266
251
|
end
|
267
252
|
end
|
268
|
-
|
253
|
+
if type[:inverse] == true
|
254
|
+
if type[:blank] == true
|
255
|
+
#p param_local[:data]
|
256
|
+
#p param_local[:data_inverse]
|
257
|
+
#p param_local[:data_inverse].values.first.first
|
258
|
+
param_local[:blank_subject] = param_local[:data].values.first.first
|
259
|
+
param_local[:blank_triples] = {
|
260
|
+
param_local[:data].keys.first => param_local[:data_global][param_local[:blank_subject]][param_local[:data].keys.first]
|
261
|
+
}
|
262
|
+
#p param_local[:blank_subject]
|
263
|
+
#p param_local[:blank_triples]
|
264
|
+
param_local[:type] = {}
|
265
|
+
#pp param_local
|
266
|
+
to_html_raw("triples-blank.html.erb", param_local)
|
267
|
+
else
|
268
|
+
to_html_raw("triples-inverse.html.erb", param_local)
|
269
|
+
end
|
270
|
+
else
|
271
|
+
to_html_raw("triples.html.erb", param_local)
|
272
|
+
end
|
269
273
|
end
|
270
274
|
def format_version_info(version)
|
271
275
|
param_local = @param.dup.merge(data: version)
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module TTL2HTML
|
2
|
+
module Util
|
3
|
+
def uri_mapping_to_path(uri, param, suffix = ".html")
|
4
|
+
path = nil
|
5
|
+
if param[:uri_mappings]
|
6
|
+
param[:uri_mappings].each do |mapping|
|
7
|
+
local_file = uri.sub(param[:base_uri], "")
|
8
|
+
if mapping["regexp"] =~ local_file
|
9
|
+
path = local_file.sub(mapping["regexp"], mapping["path"])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
if path.nil?
|
14
|
+
if suffix == ".html"
|
15
|
+
if @data.keys.find{|e| e.start_with?(uri + "/") }
|
16
|
+
path = uri + "/index"
|
17
|
+
elsif uri.end_with?("/")
|
18
|
+
path = uri + "index"
|
19
|
+
else
|
20
|
+
path = uri
|
21
|
+
end
|
22
|
+
else
|
23
|
+
path = uri
|
24
|
+
end
|
25
|
+
end
|
26
|
+
path = path.sub(param[:base_uri], "")
|
27
|
+
path << suffix
|
28
|
+
#p [uri, path]
|
29
|
+
path
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/ttl2html/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
TTL2HTML::VERSION = "
|
1
|
+
TTL2HTML::VERSION = "2.0.0"
|
data/lib/ttl2html.rb
CHANGED
@@ -1,15 +1,18 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require "zlib"
|
4
|
+
require "uri"
|
4
5
|
require "yaml"
|
5
6
|
require "nokogiri"
|
6
7
|
require "rdf/turtle"
|
7
8
|
require "ruby-progressbar"
|
8
9
|
|
10
|
+
require "ttl2html/util"
|
9
11
|
require "ttl2html/template"
|
10
12
|
|
11
13
|
module TTL2HTML
|
12
14
|
class App
|
15
|
+
include Util
|
13
16
|
def initialize(config = "config.yml")
|
14
17
|
@config = load_config(config)
|
15
18
|
if not @config[:base_uri]
|
@@ -18,7 +21,6 @@ module TTL2HTML
|
|
18
21
|
@data = {}
|
19
22
|
@data_inverse = {}
|
20
23
|
@prefix = {}
|
21
|
-
@graph = RDF::Graph.new
|
22
24
|
end
|
23
25
|
|
24
26
|
def load_config(file)
|
@@ -39,10 +41,8 @@ module TTL2HTML
|
|
39
41
|
else
|
40
42
|
io = File.open(file)
|
41
43
|
end
|
42
|
-
RDF::
|
43
|
-
@prefix.merge! reader.prefixes
|
44
|
+
RDF::Format.for(:turtle).reader.new(io) do |reader|
|
44
45
|
reader.statements.each do |statement|
|
45
|
-
@graph.insert(statement)
|
46
46
|
s = statement.subject
|
47
47
|
v = statement.predicate
|
48
48
|
o = statement.object
|
@@ -55,12 +55,13 @@ module TTL2HTML
|
|
55
55
|
@data[s.to_s][v.to_s] ||= []
|
56
56
|
@data[s.to_s][v.to_s] << o.to_s
|
57
57
|
end
|
58
|
-
if o.is_a? RDF::URI
|
58
|
+
if o.is_a? RDF::URI or o.is_a? RDF::Node
|
59
59
|
@data_inverse[o.to_s] ||= {}
|
60
60
|
@data_inverse[o.to_s][v.to_s] ||= []
|
61
61
|
@data_inverse[o.to_s][v.to_s] << s.to_s
|
62
62
|
end
|
63
63
|
end
|
64
|
+
@prefix.merge! reader.prefixes
|
64
65
|
end
|
65
66
|
STDERR.puts "#{count} triples. #{@data.size} subjects."
|
66
67
|
@data
|
@@ -120,9 +121,12 @@ module TTL2HTML
|
|
120
121
|
end
|
121
122
|
def output_html_files
|
122
123
|
template = Template.new("", @config)
|
123
|
-
shapes =
|
124
|
-
|
125
|
-
|
124
|
+
shapes = []
|
125
|
+
@data.each do |s, v|
|
126
|
+
if v[RDF.type.to_s] and @data[s][RDF.type.to_s].include?("http://www.w3.org/ns/shacl#NodeShape")
|
127
|
+
shapes << s
|
128
|
+
end
|
129
|
+
end
|
126
130
|
labels = shapes2labels(shapes)
|
127
131
|
versions = extract_versions
|
128
132
|
toplevel = extract_toplevel
|
@@ -145,38 +149,57 @@ module TTL2HTML
|
|
145
149
|
param[:turtle_uri] = uri + ".ttl"
|
146
150
|
param[:data] = v
|
147
151
|
param[:data_inverse] = @data_inverse[uri]
|
152
|
+
param[:data_inverse_global] = @data_inverse
|
148
153
|
param[:data_global] = @data
|
149
154
|
param[:title] = template.get_title(v)
|
150
155
|
if param[:breadcrumbs]
|
151
156
|
param[:breadcrumbs_items] = build_breadcrumbs(uri, template)
|
152
157
|
end
|
153
|
-
file = uri_mapping_to_path(uri, ".html")
|
158
|
+
file = uri_mapping_to_path(uri, @config, ".html")
|
154
159
|
if @config[:output_dir]
|
155
160
|
Dir.mkdir @config[:output_dir] if not File.exist? @config[:output_dir]
|
156
161
|
file = File.join(@config[:output_dir], file)
|
157
162
|
end
|
163
|
+
if template.find_template_path("_default.html.erb")
|
164
|
+
param[:additional_content] = template.to_html_raw("_default.html.erb", param)
|
165
|
+
end
|
158
166
|
template.output_to(file, param)
|
159
167
|
end
|
160
168
|
index_html = "index.html"
|
161
169
|
index_html = File.join(@config[:output_dir], "index.html") if @config[:output_dir]
|
162
170
|
if @config.has_key? :top_class
|
163
|
-
subjects =
|
164
|
-
|
165
|
-
|
171
|
+
subjects = []
|
172
|
+
@data.each do |s, v|
|
173
|
+
if @data[s][RDF.type.to_s] and @data[s][RDF.type.to_s].include?(@config[:top_class])
|
174
|
+
subjects << s
|
175
|
+
end
|
176
|
+
end
|
166
177
|
if subjects.empty?
|
167
178
|
STDERR.puts "WARN: top_class parameter specified as [#{@config[:top_class]}], but there is no instance data."
|
168
|
-
STDERR.puts " Skip generation of top page."
|
169
179
|
else
|
170
180
|
template = Template.new("index.html.erb", @config)
|
171
181
|
param = @config.dup
|
172
182
|
param[:class_label] = template.get_title(@data[@config[:top_class]], nil)
|
173
183
|
param[:data_global] = @data
|
184
|
+
param[:data_inverse_global] = @data_inverse
|
174
185
|
param[:versions] = versions
|
175
186
|
param[:toplevel] = toplevel
|
176
187
|
subjects.sort.each do |subject|
|
188
|
+
objects = []
|
189
|
+
if @config.has_key? :top_additional_property
|
190
|
+
@config[:top_additional_property].each do |property|
|
191
|
+
if @data[subject][property]
|
192
|
+
objects += @data[subject][property]
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
177
196
|
param[:index_data] ||= []
|
178
|
-
param[:index_data] <<
|
197
|
+
param[:index_data] << {
|
198
|
+
subject.to_s => objects
|
199
|
+
}
|
179
200
|
end
|
201
|
+
param[:output_file] = index_html
|
202
|
+
param[:index_list] = template.to_html_raw("index-list.html.erb", param)
|
180
203
|
template.output_to(index_html, param)
|
181
204
|
end
|
182
205
|
end
|
@@ -190,7 +213,13 @@ module TTL2HTML
|
|
190
213
|
param[:versions] = versions
|
191
214
|
param[:toplevel] = toplevel
|
192
215
|
param[:shapes] = {}
|
193
|
-
shapes.
|
216
|
+
shapes.each do |subject|
|
217
|
+
orders = []
|
218
|
+
if param[:shape_orders]
|
219
|
+
param[:shape_orders].index(subject)
|
220
|
+
orders << ( param[:shape_orders].index(subject) or Float::INFINITY )
|
221
|
+
end
|
222
|
+
orders << subject
|
194
223
|
label = comment = nil
|
195
224
|
target_class = @data[subject.to_s]["http://www.w3.org/ns/shacl#targetClass"]
|
196
225
|
if target_class
|
@@ -209,6 +238,7 @@ module TTL2HTML
|
|
209
238
|
comment: comment,
|
210
239
|
html: template.expand_shape(@data, subject.to_s, @prefix),
|
211
240
|
target_class: target_class,
|
241
|
+
order: orders,
|
212
242
|
}
|
213
243
|
end
|
214
244
|
template.output_to(about_html, param)
|
@@ -227,30 +257,62 @@ module TTL2HTML
|
|
227
257
|
@config[:breadcrumbs].each do |e|
|
228
258
|
data_target = data
|
229
259
|
data_target = @data_inverse[uri] if e["inverse"]
|
230
|
-
if data_target
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
260
|
+
if data_target
|
261
|
+
if e["property"].kind_of? Array
|
262
|
+
parent = nil
|
263
|
+
data_target_sub = data_target
|
264
|
+
e["property"].each do |prop|
|
265
|
+
if data_target_sub[prop["property"]]
|
266
|
+
data_target_sub[prop["property"]].each do |o|
|
267
|
+
parent = o
|
268
|
+
data_target_sub = @data[parent]
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
272
|
+
if parent
|
273
|
+
results << build_breadcrumbs_sub(parent, template)
|
274
|
+
results += build_breadcrumbs(parent, template, depth + 1)
|
275
|
+
return results
|
276
|
+
end
|
277
|
+
elsif data_target[e["property"]]
|
278
|
+
data_target[e["property"]].each do |parent|
|
279
|
+
results << build_breadcrumbs_sub(parent, template, e["label"])
|
280
|
+
results += build_breadcrumbs(parent, template, depth + 1)
|
281
|
+
return results
|
282
|
+
end
|
240
283
|
end
|
241
|
-
return results
|
242
284
|
end
|
243
285
|
end
|
244
286
|
end
|
245
287
|
results
|
246
288
|
end
|
289
|
+
def build_breadcrumbs_sub(parent, template, label_prop = nil)
|
290
|
+
data_parent = @data[parent]
|
291
|
+
label = template.get_title(data_parent)
|
292
|
+
label = data_parent[label_prop].first if label_prop and data_parent[label_prop]
|
293
|
+
{
|
294
|
+
uri: parent,
|
295
|
+
label: label,
|
296
|
+
}
|
297
|
+
end
|
247
298
|
|
248
299
|
def shapes_parse(shapes)
|
249
|
-
shapes.
|
250
|
-
target_class = @data[shape
|
300
|
+
shapes.each do |shape|
|
301
|
+
target_class = @data[shape]["http://www.w3.org/ns/shacl#targetClass"]&.first
|
251
302
|
if target_class
|
252
303
|
properties = @data[shape.to_s]["http://www.w3.org/ns/shacl#property"]
|
253
|
-
if
|
304
|
+
if @data[shape.to_s]["http://www.w3.org/ns/shacl#or"]
|
305
|
+
properties ||= []
|
306
|
+
node_list = @data[shape.to_s]["http://www.w3.org/ns/shacl#or"].first
|
307
|
+
while node_list and @data[node_list] do
|
308
|
+
sub_shape = @data[node_list]["http://www.w3.org/1999/02/22-rdf-syntax-ns#first"].first
|
309
|
+
if @data[sub_shape] and @data[sub_shape]["http://www.w3.org/ns/shacl#property"]
|
310
|
+
properties += @data[sub_shape]["http://www.w3.org/ns/shacl#property"]
|
311
|
+
end
|
312
|
+
node_list = @data[node_list]["http://www.w3.org/1999/02/22-rdf-syntax-ns#rest"].first
|
313
|
+
end
|
314
|
+
end
|
315
|
+
if not properties.empty?
|
254
316
|
properties.each do |property|
|
255
317
|
path = @data[property]["http://www.w3.org/ns/shacl#path"].first
|
256
318
|
yield target_class, property
|
@@ -283,11 +345,17 @@ module TTL2HTML
|
|
283
345
|
def extract_versions
|
284
346
|
versions = []
|
285
347
|
["http://purl.org/pav/hasVersion", "http://purl.org/pav/hasCurrentVersion", "http://purl.org/dc/terms/hasVersion"].each do |prop|
|
286
|
-
objects =
|
348
|
+
objects = []
|
349
|
+
@data.each do |s, v|
|
350
|
+
if @data[s][prop]
|
351
|
+
objects += @data[s][prop]
|
352
|
+
end
|
353
|
+
end
|
287
354
|
objects.each do |o|
|
288
355
|
uri = o.to_s
|
289
356
|
version = @data[uri]
|
290
357
|
next if not version
|
358
|
+
next if not version["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"]
|
291
359
|
next if not version["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"].include? "http://rdfs.org/ns/void#Dataset"
|
292
360
|
description = version["http://purl.org/dc/terms/description"]
|
293
361
|
link = nil
|
@@ -323,15 +391,24 @@ module TTL2HTML
|
|
323
391
|
end
|
324
392
|
def extract_toplevel
|
325
393
|
result = {}
|
326
|
-
toplevel =
|
394
|
+
toplevel = nil
|
395
|
+
@data.each do |s, v|
|
396
|
+
if @data[s]["http://purl.org/pav/hasCurrentVersion"]
|
397
|
+
toplevel = s
|
398
|
+
end
|
399
|
+
end
|
327
400
|
data = @data[toplevel.to_s]
|
328
401
|
if toplevel
|
329
402
|
license = {}
|
330
403
|
if data["http://purl.org/dc/terms/license"]
|
331
404
|
license_data = @data[data["http://purl.org/dc/terms/license"].first]
|
332
|
-
|
333
|
-
|
334
|
-
|
405
|
+
if license_data
|
406
|
+
license[:url] = license_data["http://www.w3.org/1999/02/22-rdf-syntax-ns#value"]&.first
|
407
|
+
license[:icon] = license_data["http://xmlns.com/foaf/0.1/thumbnail"]&.first
|
408
|
+
license[:label] = license_data["http://www.w3.org/2000/01/rdf-schema#label"]
|
409
|
+
elsif data["http://purl.org/dc/terms/license"].first =~ URI::regexp
|
410
|
+
license[:url] = license[:label] = data["http://purl.org/dc/terms/license"].first
|
411
|
+
end
|
335
412
|
end
|
336
413
|
if data["http://purl.org/dc/terms/publisher"]
|
337
414
|
publisher_data = @data[data["http://purl.org/dc/terms/publisher"].first]
|
@@ -363,7 +440,7 @@ module TTL2HTML
|
|
363
440
|
|
364
441
|
def output_turtle_files
|
365
442
|
each_data(:output_turtle_files) do |uri, v|
|
366
|
-
file = uri_mapping_to_path(uri, ".ttl")
|
443
|
+
file = uri_mapping_to_path(uri, @config, ".ttl")
|
367
444
|
if @config[:output_dir]
|
368
445
|
Dir.mkdir @config[:output_dir] if not File.exist? @config[:output_dir]
|
369
446
|
file = File.join(@config[:output_dir], file)
|
@@ -383,44 +460,16 @@ module TTL2HTML
|
|
383
460
|
output_turtle_files if @config[:output_turtle]
|
384
461
|
end
|
385
462
|
|
386
|
-
def uri_mapping_to_path(uri, suffix = ".html")
|
387
|
-
path = nil
|
388
|
-
if @config[:uri_mappings]
|
389
|
-
@config[:uri_mappings].each do |mapping|
|
390
|
-
local_file = uri.sub(@config[:base_uri], "")
|
391
|
-
if mapping["regexp"] =~ local_file
|
392
|
-
path = local_file.sub(mapping["regexp"], mapping["path"])
|
393
|
-
end
|
394
|
-
end
|
395
|
-
end
|
396
|
-
if path.nil?
|
397
|
-
if suffix == ".html"
|
398
|
-
if @data.keys.find{|e| e.start_with?(uri + "/") }
|
399
|
-
path = uri + "/index"
|
400
|
-
elsif uri.end_with?("/")
|
401
|
-
path = uri + "index"
|
402
|
-
else
|
403
|
-
path = uri
|
404
|
-
end
|
405
|
-
else
|
406
|
-
path = uri
|
407
|
-
end
|
408
|
-
end
|
409
|
-
path = path.sub(@config[:base_uri], "")
|
410
|
-
path << suffix
|
411
|
-
#p [uri, path]
|
412
|
-
path
|
413
|
-
end
|
414
463
|
def cleanup
|
415
464
|
@data.select do |uri, v|
|
416
465
|
uri.start_with? @config[:base_uri]
|
417
466
|
end.sort_by do |uri, v|
|
418
467
|
-(uri.size)
|
419
468
|
end.each do |uri, v|
|
420
|
-
html_file = uri_mapping_to_path(uri, ".html")
|
469
|
+
html_file = uri_mapping_to_path(uri, @config, ".html")
|
421
470
|
html_file = File.join(@config[:output_dir], html_file) if @config[:output_dir]
|
422
471
|
File.unlink html_file if File.exist? html_file
|
423
|
-
ttl_file = uri_mapping_to_path(uri, ".ttl")
|
472
|
+
ttl_file = uri_mapping_to_path(uri, @config, ".ttl")
|
424
473
|
ttl_file = File.join(@config[:output_dir], ttl_file) if @config[:output_dir]
|
425
474
|
File.unlink ttl_file if File.exist? ttl_file
|
426
475
|
dir = uri.sub(@config[:base_uri], "")
|
data/locales/en.yml
CHANGED
@@ -4,6 +4,7 @@ en:
|
|
4
4
|
shape-heading: "Resources description"
|
5
5
|
shape-note: "The properties for the %{resource} resources are as follows:"
|
6
6
|
shape-target: Target class
|
7
|
+
shape-namespace: "The namespace URIs used in the table are as follows:"
|
7
8
|
versions: Versions
|
8
9
|
version-release: "Version %{version} released."
|
9
10
|
version-triples: "%{triples} triples"
|
@@ -37,3 +38,4 @@ en:
|
|
37
38
|
blank-node-or-structure: "The structural contents of a blank node are either of the followings:"
|
38
39
|
triples:
|
39
40
|
inverse_refered: "Referred to as '%{property}' from:"
|
41
|
+
blank_node: "Blank node"
|
data/locales/ja.yml
CHANGED
@@ -4,6 +4,7 @@ ja:
|
|
4
4
|
shape-heading: "各リソースの説明"
|
5
5
|
shape-note: "%{resource}リソースが持つプロパティを下表に示します"
|
6
6
|
shape-target: 対象クラス
|
7
|
+
shape-namespace: "表内で用いている名前空間URIは以下の通りです"
|
7
8
|
versions: 更新履歴
|
8
9
|
version-release: "バージョン%{version}を公開。"
|
9
10
|
version-triples: "%{triples}トリプル"
|
@@ -37,3 +38,4 @@ ja:
|
|
37
38
|
blank-node-or-structure: ブランクノードの内容は以下のいずれかの内容からなる構造を持ちます。
|
38
39
|
triples:
|
39
40
|
inverse_refered: "'%{property}'としての参照元:"
|
41
|
+
blank_node: "空ノード"
|
data/templates/about.html.erb
CHANGED
@@ -28,7 +28,7 @@
|
|
28
28
|
<div class="row">
|
29
29
|
<div class="col-md">
|
30
30
|
<h2 id="shapes"><%=h t("about.shape-heading") %></h2>
|
31
|
-
<%- param[:shapes].keys.
|
31
|
+
<%- param[:shapes].keys.sort_by{|k| param[:shapes][k][:order] }.each do |shape| -%>
|
32
32
|
<h3><%=h param[:shapes][shape][:label] %></h3>
|
33
33
|
<%- if param[:shapes][shape][:target_class] -%>
|
34
34
|
<ul><li><%= t("about.shape-target") %>: <a href="<%=h param[:shapes][shape][:target_class] %>"><%=h param[:shapes][shape][:target_class] %></a></li></ul>
|
data/templates/default.html.erb
CHANGED
@@ -31,11 +31,14 @@
|
|
31
31
|
<%= format_triples(param[:data]) %>
|
32
32
|
</div>
|
33
33
|
</div>
|
34
|
+
<%- if param[:additional_content] -%>
|
35
|
+
<%= param[:additional_content] %>
|
36
|
+
<%- end -%>
|
34
37
|
<%- if param[:data_inverse] -%>
|
35
38
|
<div class="row inverse">
|
36
39
|
<div class="col-md-12">
|
37
40
|
<h2><%=h t("default.inverse_data") %></h2>
|
38
|
-
<%= format_triples(param[:data_inverse], :
|
41
|
+
<%= format_triples(param[:data_inverse], inverse: true) %>
|
39
42
|
</div>
|
40
43
|
</div>
|
41
44
|
<%- end -%>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<div class="row">
|
2
|
+
<div class="col-md-12">
|
3
|
+
<h2><%=h t("index.list", resource: param[:class_label]) %></h2>
|
4
|
+
<ul>
|
5
|
+
<%- param[:index_data].each do |e| -%>
|
6
|
+
<%- e.each do |s, o| -%>
|
7
|
+
<li><%= format_object(s, param[:data_global]) %>
|
8
|
+
<%- if o and o.size > 0 -%>
|
9
|
+
<ul>
|
10
|
+
<%- o.each do |o2| -%>
|
11
|
+
<li><%= format_object(o2.to_s, param[:data_global]) %></li>
|
12
|
+
<%- end -%>
|
13
|
+
</ul>
|
14
|
+
<%- end -%>
|
15
|
+
</li>
|
16
|
+
<%- end -%>
|
17
|
+
<%- end -%>
|
18
|
+
</ul>
|
19
|
+
</div>
|
20
|
+
</div>
|
data/templates/index.html.erb
CHANGED
@@ -5,19 +5,11 @@
|
|
5
5
|
<p><%= get_language_literal(param[:toplevel][:description]) %></p>
|
6
6
|
<%- end -%>
|
7
7
|
<p><i class="bi bi-link-45deg"></i> <a href="<%=h param[:base_uri] %>"><%=h param[:base_uri] %></a></p>
|
8
|
+
<p><a class="btn btn-info" href="<%=h relative_path(param[:about_file] || "about.html") %>"><%=h t("about.title", title: param[:site_title]) %> »</a></p>
|
8
9
|
</div>
|
9
10
|
</div>
|
10
11
|
<div class="container">
|
11
|
-
|
12
|
-
<div class="col-md-12">
|
13
|
-
<h2><%=h t("index.list", resource: param[:class_label]) %></h2>
|
14
|
-
<ul>
|
15
|
-
<%- param[:index_data].each do |e| -%>
|
16
|
-
<li><%= format_object(e, param[:data_global]) %></li>
|
17
|
-
<%- end -%>
|
18
|
-
</ul>
|
19
|
-
</div>
|
20
|
-
</div>
|
12
|
+
<%= param[:index_list] %>
|
21
13
|
<%- if param[:versions].size > 0 -%>
|
22
14
|
<div class="row">
|
23
15
|
<div class="col-md">
|
@@ -39,4 +31,4 @@
|
|
39
31
|
</div>
|
40
32
|
</div>
|
41
33
|
<%- end -%>
|
42
|
-
</div>
|
34
|
+
</div>
|
data/templates/layout.html.erb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
|
-
<html>
|
2
|
+
<html lang="<%= param[:locale] || I18n.default_locale %>">
|
3
3
|
<head>
|
4
4
|
<meta charset="utf-8">
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
@@ -33,9 +33,11 @@
|
|
33
33
|
<%- end -%>
|
34
34
|
</head>
|
35
35
|
<body>
|
36
|
-
<nav class="navbar navbar-expand-lg navbar-light">
|
36
|
+
<nav class="navbar navbar-expand-lg <%=h param[:navbar_class] || "navbar-light" %>">
|
37
37
|
<%- if param[:logo] -%>
|
38
|
-
<a class="navbar-brand" href="<%=h relative_path_uri(param[:base_uri], param[:base_uri]) %>"
|
38
|
+
<a class="navbar-brand" href="<%=h relative_path_uri(param[:base_uri], param[:base_uri]) %>">
|
39
|
+
<img src="<%=h relative_path(param[:logo]) %>" style="max-height: 54px" alt="<%=h param[:site_title] %>">
|
40
|
+
</a>
|
39
41
|
<%- end -%>
|
40
42
|
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
41
43
|
<span class="navbar-toggler-icon"></span>
|
@@ -76,5 +78,8 @@
|
|
76
78
|
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
|
77
79
|
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
|
78
80
|
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
|
81
|
+
<%- if param[:javascript_file] -%>
|
82
|
+
<script src="<%=h relative_path(param[:javascript_file]) %>"></script>
|
83
|
+
<%- end -%>
|
79
84
|
</body>
|
80
85
|
</html>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<table class="table table-
|
1
|
+
<table class="table table-sm">
|
2
2
|
<tr>
|
3
3
|
<th><%=h t('shape-table.header.property-name') %></th>
|
4
4
|
<th><%=h t('shape-table.header.description') %></th>
|
@@ -56,5 +56,17 @@
|
|
56
56
|
<%- end -%>
|
57
57
|
<%- end -%>
|
58
58
|
</tbody>
|
59
|
-
|
60
|
-
|
59
|
+
<%- if param[:prefix] and not param[:prefix].empty? -%>
|
60
|
+
<tfoot>
|
61
|
+
<tr><td colspan="5">
|
62
|
+
<%=h t('about.shape-namespace') %>
|
63
|
+
<dl class="row small">
|
64
|
+
<%- param[:prefix].each do |prefix, url| -%>
|
65
|
+
<dt class="col-sm-2"><code><%=h prefix %>:</code></dt>
|
66
|
+
<dd class="col-sm-10"><%=h url %></dd>
|
67
|
+
<%- end -%>
|
68
|
+
</dl>
|
69
|
+
<%- end -%>
|
70
|
+
</td></tr>
|
71
|
+
</tfoot>
|
72
|
+
</table>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<dl class="row">
|
2
|
+
<%- param[:data].sort_by{|k, v|
|
3
|
+
order = param[:orders][k] if param[:orders] and param[:orders][k]
|
4
|
+
order = Float::INFINITY if order.nil?
|
5
|
+
[ order, k ]
|
6
|
+
}.each do |k, v| -%>
|
7
|
+
<dt class="col-sm-3"><%=h t('triples.inverse_refered', property: format_property(k, param[:labels], v.first)) %></dt>
|
8
|
+
<%- if v.respond_to? :has_key? -%>
|
9
|
+
<% v.each_with_index do |v2, idx| %>
|
10
|
+
<dd class="col-sm-9<%= ' offset-sm-3' if idx > 0 %>" lang="<%=h v2[0] %>"><%= format_object v2[1], param[:data], param[:type] %></dd>
|
11
|
+
<% end %>
|
12
|
+
<%- elsif v.size > 1 -%>
|
13
|
+
<%- v.each_with_index do |v2, idx| -%>
|
14
|
+
<dd class="col-sm-9<%= ' offset-sm-3' if idx > 0 %>"><%= format_object v2, param[:data], param[:type] %></dd>
|
15
|
+
<%- end -%>
|
16
|
+
<%- else -%>
|
17
|
+
<dd class="col-sm-9"><%= format_object v.first, param[:data], param[:type] %></dd>
|
18
|
+
<%- end -%>
|
19
|
+
<%- end -%>
|
20
|
+
</dl>
|
data/templates/triples.html.erb
CHANGED
@@ -4,21 +4,17 @@
|
|
4
4
|
order = Float::INFINITY if order.nil?
|
5
5
|
[ order, k ]
|
6
6
|
}.each do |k, v| -%>
|
7
|
-
<%- if param[:type] == :inverse -%>
|
8
|
-
<dt class="col-sm-3"><%=h t('triples.inverse_refered', property: format_property(k, param[:labels])) %></dt>
|
9
|
-
<%- else -%>
|
10
7
|
<dt class="col-sm-3"><%=h format_property(k, param[:labels]) %></dt>
|
11
|
-
<%- end -%>
|
12
8
|
<%- if v.respond_to? :has_key? -%>
|
13
|
-
|
14
|
-
<dd class="col-sm-9<%= ' offset-sm-3' if idx > 0 %>" lang="<%=h v2[0] %>"><%= format_object v2[1], param[:data] %></dd>
|
15
|
-
|
9
|
+
<%- v.each_with_index do |v2, idx| -%>
|
10
|
+
<dd class="col-sm-9<%= ' offset-sm-3' if idx > 0 %>" lang="<%=h v2[0] %>"><%= format_object v2[1], param[:data], param[:type] %></dd>
|
11
|
+
<%- end -%>
|
16
12
|
<%- elsif v.size > 1 -%>
|
17
13
|
<%- v.each_with_index do |v2, idx| -%>
|
18
|
-
<dd class="col-sm-9<%= ' offset-sm-3' if idx > 0 %>"><%= format_object v2, param[:data] %></dd>
|
14
|
+
<dd class="col-sm-9<%= ' offset-sm-3' if idx > 0 %>"><%= format_object v2, param[:data], param[:type] %></dd>
|
19
15
|
<%- end -%>
|
20
16
|
<%- else -%>
|
21
|
-
<dd class="col-sm-9"><%= format_object v.first, param[:data] %></dd>
|
17
|
+
<dd class="col-sm-9"><%= format_object v.first, param[:data], param[:type] %></dd>
|
22
18
|
<%- end -%>
|
23
19
|
<%- end -%>
|
24
20
|
</dl>
|
data/templates/version.html.erb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ttl2html
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masao Takaku
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -150,15 +150,19 @@ files:
|
|
150
150
|
- bin/xlsx2shape
|
151
151
|
- lib/ttl2html.rb
|
152
152
|
- lib/ttl2html/template.rb
|
153
|
+
- lib/ttl2html/util.rb
|
153
154
|
- lib/ttl2html/version.rb
|
154
155
|
- lib/xlsx2shape.rb
|
155
156
|
- locales/en.yml
|
156
157
|
- locales/ja.yml
|
157
158
|
- templates/about.html.erb
|
158
159
|
- templates/default.html.erb
|
160
|
+
- templates/index-list.html.erb
|
159
161
|
- templates/index.html.erb
|
160
162
|
- templates/layout.html.erb
|
161
163
|
- templates/shape-table.html.erb
|
164
|
+
- templates/triples-blank.html.erb
|
165
|
+
- templates/triples-inverse.html.erb
|
162
166
|
- templates/triples.html.erb
|
163
167
|
- templates/version.html.erb
|
164
168
|
homepage: https://github.com/masao/ttl2html
|
@@ -180,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
184
|
- !ruby/object:Gem::Version
|
181
185
|
version: '0'
|
182
186
|
requirements: []
|
183
|
-
rubygems_version: 3.3.
|
187
|
+
rubygems_version: 3.3.7
|
184
188
|
signing_key:
|
185
189
|
specification_version: 4
|
186
190
|
summary: ttl2html
|