ttl2html 1.3.4 → 1.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/ttl2html +1 -2
- data/lib/ttl2html/template.rb +12 -5
- data/lib/ttl2html/version.rb +1 -1
- data/lib/ttl2html.rb +42 -24
- data/locales/en.yml +3 -1
- data/locales/ja.yml +3 -0
- data/templates/about.html.erb +13 -2
- data/templates/layout.html.erb +27 -6
- data/templates/version.html.erb +5 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64841e5acabefa8d0ff72ab9a5b342d2cb8c6a5f3ecbcce5d70d9c223ae6f694
|
4
|
+
data.tar.gz: 4c17bd90212017eccb86e6b96d3d2d1fe87c13841f5a0003a8f19d3e011aa1c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd727e999f72c76af779008495bb858eb27bbf05f4e79b8ac9aeee0c61e3b225f8d5710209dcc29538fa7133c0c4da93573e864b2144447840b36ddb22306b36
|
7
|
+
data.tar.gz: 24fd2e31ebd3df0eb3ee62c62005356f6c66ab7b43697a7e1d82206314d1c038038bc44f145035f7aae87506878f19e458c265a1ebcb2a6fe9b389e70f40ce66
|
data/bin/ttl2html
CHANGED
data/lib/ttl2html/template.rb
CHANGED
@@ -15,7 +15,7 @@ module TTL2HTML
|
|
15
15
|
def initialize(template, param = {})
|
16
16
|
@template = template
|
17
17
|
@param = param.dup
|
18
|
-
@template_path = [
|
18
|
+
@template_path = [ File.join(Dir.pwd, "templates") ]
|
19
19
|
@template_path << File.join(File.dirname(__FILE__), "..", "..", "templates")
|
20
20
|
I18n.load_path << Dir[File.join(File.dirname(__FILE__), "..", "..", "locales") + "/*.yml"]
|
21
21
|
I18n.load_path << Dir[File.expand_path("locales") + "/*.yml"]
|
@@ -143,10 +143,16 @@ module TTL2HTML
|
|
143
143
|
path
|
144
144
|
end
|
145
145
|
def relative_path(dest)
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
146
|
+
path = nil
|
147
|
+
dest_uri = RDF::IRI.parse(dest)
|
148
|
+
if dest_uri.absolute?
|
149
|
+
path = dest
|
150
|
+
else
|
151
|
+
src = @param[:output_file]
|
152
|
+
src = Pathname.new(src).relative_path_from(Pathname.new(@param[:output_dir])) if @param[:output_dir]
|
153
|
+
path = Pathname(dest).relative_path_from(Pathname(File.dirname src))
|
154
|
+
path = path.to_s + "/" if File.directory? path
|
155
|
+
end
|
150
156
|
path
|
151
157
|
end
|
152
158
|
def relative_path_uri(dest_uri, base_uri)
|
@@ -176,6 +182,7 @@ module TTL2HTML
|
|
176
182
|
end
|
177
183
|
end
|
178
184
|
def get_title(data, default_title = "no title")
|
185
|
+
return default_title if data.nil?
|
179
186
|
if @param[:title_property_perclass] and data["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"]
|
180
187
|
@param[:title_property_perclass].each do |klass, property|
|
181
188
|
if data["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"].include?(klass) and data[property]
|
data/lib/ttl2html/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
TTL2HTML::VERSION = "1.3.
|
1
|
+
TTL2HTML::VERSION = "1.3.3"
|
data/lib/ttl2html.rb
CHANGED
@@ -22,7 +22,7 @@ module TTL2HTML
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def load_config(file)
|
25
|
-
config = {}
|
25
|
+
config = { output_turtle: true }
|
26
26
|
open(file) do |io|
|
27
27
|
YAML.safe_load(io, permitted_classes: [Regexp]).each do |k, v|
|
28
28
|
config[k.intern] = v
|
@@ -142,7 +142,7 @@ module TTL2HTML
|
|
142
142
|
template = Template.new("default.html.erb", @config)
|
143
143
|
param = @config.dup
|
144
144
|
param[:uri] = uri
|
145
|
-
param[:turtle_uri] =
|
145
|
+
param[:turtle_uri] = uri + ".ttl"
|
146
146
|
param[:data] = v
|
147
147
|
param[:data_inverse] = @data_inverse[uri]
|
148
148
|
param[:data_global] = @data
|
@@ -169,6 +169,7 @@ module TTL2HTML
|
|
169
169
|
else
|
170
170
|
template = Template.new("index.html.erb", @config)
|
171
171
|
param = @config.dup
|
172
|
+
param[:class_label] = template.get_title(@data[@config[:top_class]], nil)
|
172
173
|
param[:data_global] = @data
|
173
174
|
param[:versions] = versions
|
174
175
|
param[:toplevel] = toplevel
|
@@ -179,11 +180,12 @@ module TTL2HTML
|
|
179
180
|
template.output_to(index_html, param)
|
180
181
|
end
|
181
182
|
end
|
182
|
-
if shapes.size > 0 or versions.size > 0 or toplevel.size > 0
|
183
|
+
if template.find_template_path("about.html") or shapes.size > 0 or versions.size > 0 or toplevel.size > 0
|
183
184
|
about_html = @config[:about_file] || "about.html"
|
184
185
|
about_html = File.join(@config[:output_dir], about_html) if @config[:output_dir]
|
185
186
|
template = Template.new("about.html.erb", @config)
|
186
187
|
param = @config.dup
|
188
|
+
param[:content] = template.to_html_raw("about.html", {}) if template.find_template_path("about.html")
|
187
189
|
param[:data_global] = @data
|
188
190
|
param[:versions] = versions
|
189
191
|
param[:toplevel] = toplevel
|
@@ -206,6 +208,7 @@ module TTL2HTML
|
|
206
208
|
label: label,
|
207
209
|
comment: comment,
|
208
210
|
html: template.expand_shape(@data, subject.to_s, @prefix),
|
211
|
+
target_class: target_class,
|
209
212
|
}
|
210
213
|
end
|
211
214
|
template.output_to(about_html, param)
|
@@ -242,33 +245,37 @@ module TTL2HTML
|
|
242
245
|
results
|
243
246
|
end
|
244
247
|
|
245
|
-
def
|
246
|
-
labels = {}
|
248
|
+
def shapes_parse(shapes)
|
247
249
|
shapes.subjects.each do |shape|
|
248
250
|
target_class = @data[shape.to_s]["http://www.w3.org/ns/shacl#targetClass"]&.first
|
249
251
|
if target_class
|
250
|
-
@data[shape.to_s]["http://www.w3.org/ns/shacl#property"]
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
252
|
+
properties = @data[shape.to_s]["http://www.w3.org/ns/shacl#property"]
|
253
|
+
if properties
|
254
|
+
properties.each do |property|
|
255
|
+
path = @data[property]["http://www.w3.org/ns/shacl#path"].first
|
256
|
+
yield target_class, property
|
257
|
+
end
|
255
258
|
end
|
256
259
|
end
|
257
260
|
end
|
261
|
+
end
|
262
|
+
def shapes2labels(shapes)
|
263
|
+
labels = {}
|
264
|
+
shapes_parse(shapes) do |target_class, property|
|
265
|
+
path = @data[property]["http://www.w3.org/ns/shacl#path"].first
|
266
|
+
name = @data[property]["http://www.w3.org/ns/shacl#name"]
|
267
|
+
labels[target_class] ||= {}
|
268
|
+
labels[target_class][path] = name
|
269
|
+
end
|
258
270
|
labels
|
259
271
|
end
|
260
272
|
def shapes2orders(shapes)
|
261
273
|
orders = {}
|
262
|
-
shapes
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
order = @data[property]["http://www.w3.org/ns/shacl#order"]
|
268
|
-
orders[target_class] ||= {}
|
269
|
-
orders[target_class][path] = order&.first&.to_i
|
270
|
-
end
|
271
|
-
end
|
274
|
+
shapes_parse(shapes) do |target_class, property|
|
275
|
+
path = @data[property]["http://www.w3.org/ns/shacl#path"].first
|
276
|
+
order = @data[property]["http://www.w3.org/ns/shacl#order"]
|
277
|
+
orders[target_class] ||= {}
|
278
|
+
orders[target_class][path] = order&.first&.to_i
|
272
279
|
end
|
273
280
|
orders
|
274
281
|
end
|
@@ -283,10 +290,12 @@ module TTL2HTML
|
|
283
290
|
next if not version
|
284
291
|
next if not version["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"].include? "http://rdfs.org/ns/void#Dataset"
|
285
292
|
description = version["http://purl.org/dc/terms/description"]
|
293
|
+
link = nil
|
286
294
|
if not description
|
287
295
|
qrev = version["http://www.w3.org/ns/prov#qualifiedRevision"]&.first
|
288
|
-
if
|
296
|
+
if @data[qrev]
|
289
297
|
description = @data[qrev]["http://www.w3.org/2000/01/rdf-schema#comment"]
|
298
|
+
link = @data[qrev]["http://www.w3.org/2000/01/rdf-schema#seeAlso"]&.first
|
290
299
|
end
|
291
300
|
end
|
292
301
|
subset = []
|
@@ -306,6 +315,7 @@ module TTL2HTML
|
|
306
315
|
date: date,
|
307
316
|
description: description,
|
308
317
|
subset: subset,
|
318
|
+
link: link,
|
309
319
|
}
|
310
320
|
end
|
311
321
|
end
|
@@ -358,13 +368,21 @@ module TTL2HTML
|
|
358
368
|
Dir.mkdir @config[:output_dir] if not File.exist? @config[:output_dir]
|
359
369
|
file = File.join(@config[:output_dir], file)
|
360
370
|
end
|
361
|
-
|
371
|
+
dir = File.dirname(file)
|
372
|
+
FileUtils.mkdir_p(dir) if not File.exist?(dir)
|
373
|
+
str = format_turtle(uri)
|
362
374
|
str << format_turtle_inverse(uri)
|
363
375
|
open(file, "w") do |io|
|
364
376
|
io.puts str.strip
|
365
377
|
end
|
366
378
|
end
|
367
379
|
end
|
380
|
+
|
381
|
+
def output_files
|
382
|
+
output_html_files
|
383
|
+
output_turtle_files if @config[:output_turtle]
|
384
|
+
end
|
385
|
+
|
368
386
|
def uri_mapping_to_path(uri, suffix = ".html")
|
369
387
|
path = nil
|
370
388
|
if @config[:uri_mappings]
|
@@ -401,10 +419,10 @@ module TTL2HTML
|
|
401
419
|
end.each do |uri, v|
|
402
420
|
html_file = uri_mapping_to_path(uri, ".html")
|
403
421
|
html_file = File.join(@config[:output_dir], html_file) if @config[:output_dir]
|
404
|
-
File.unlink html_file
|
422
|
+
File.unlink html_file if File.exist? html_file
|
405
423
|
ttl_file = uri_mapping_to_path(uri, ".ttl")
|
406
424
|
ttl_file = File.join(@config[:output_dir], ttl_file) if @config[:output_dir]
|
407
|
-
File.unlink ttl_file
|
425
|
+
File.unlink ttl_file if File.exist? ttl_file
|
408
426
|
dir = uri.sub(@config[:base_uri], "")
|
409
427
|
dir = File.join(@config[:output_dir], dir) if @config[:output_dir]
|
410
428
|
Dir.rmdir dir if File.exist? dir
|
data/locales/en.yml
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
en:
|
2
2
|
about:
|
3
3
|
title: "About %{title}"
|
4
|
-
|
4
|
+
shape-heading: "Resources description"
|
5
5
|
shape-note: "The properties for the %{resource} resources are as follows:"
|
6
|
+
shape-target: Target class
|
6
7
|
versions: Versions
|
7
8
|
version-release: "Version %{version} released."
|
8
9
|
version-triples: "%{triples} triples"
|
10
|
+
version-link: "Please refer to <a href=\"%{link}\">here</a> for the revision details."
|
9
11
|
contact: Contact
|
10
12
|
contact-contribution: "This dataset was developed by %{name}"
|
11
13
|
contact-email: "For dataset inquiries, please contact at <a href=\"%{email}\">%{email}</a>"
|
data/locales/ja.yml
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
ja:
|
2
2
|
about:
|
3
3
|
title: "%{title}について"
|
4
|
+
shape-heading: "各リソースの説明"
|
4
5
|
shape-note: "%{resource}リソースが持つプロパティを下表に示します"
|
6
|
+
shape-target: 対象クラス
|
5
7
|
versions: 更新履歴
|
6
8
|
version-release: "バージョン%{version}を公開。"
|
7
9
|
version-triples: "%{triples}トリプル"
|
10
|
+
version-link: "更新の詳細については<a href=\"%{link}\">こちら</a>をご覧ください。"
|
8
11
|
contact: 連絡先
|
9
12
|
contact-contribution: "本データセットは %{name} が開発したものです"
|
10
13
|
contact-email: "データセットに関する問い合わせは <a href=\"%{email}\">%{email}</a> までお問い合わせください。"
|
data/templates/about.html.erb
CHANGED
@@ -17,11 +17,22 @@
|
|
17
17
|
</nav>
|
18
18
|
</div>
|
19
19
|
</div>
|
20
|
-
<%- if param[:
|
20
|
+
<%- if param[:content] -%>
|
21
21
|
<div class="row">
|
22
22
|
<div class="col-md">
|
23
|
+
<%= param[:content] %>
|
24
|
+
</div>
|
25
|
+
</div>
|
26
|
+
<%- end -%>
|
27
|
+
<%- if param[:shapes].size > 0 -%>
|
28
|
+
<div class="row">
|
29
|
+
<div class="col-md">
|
30
|
+
<h2 id="shapes"><%=h t("about.shape-heading") %></h2>
|
23
31
|
<%- param[:shapes].keys.sort.each do |shape| -%>
|
24
32
|
<h3><%=h param[:shapes][shape][:label] %></h3>
|
33
|
+
<%- if param[:shapes][shape][:target_class] -%>
|
34
|
+
<ul><li><%= t("about.shape-target") %>: <a href="<%=h param[:shapes][shape][:target_class] %>"><%=h param[:shapes][shape][:target_class] %></a></li></ul>
|
35
|
+
<%- end -%>
|
25
36
|
<p><%= param[:shapes][shape][:comment] %></p>
|
26
37
|
<p><%=h t("about.shape-note", resource: param[:shapes][shape][:label]) %></p>
|
27
38
|
<%= param[:shapes][shape][:html] -%>
|
@@ -29,7 +40,7 @@
|
|
29
40
|
</div>
|
30
41
|
</div>
|
31
42
|
<%- end -%>
|
32
|
-
<%- if param[:versions] -%>
|
43
|
+
<%- if param[:versions].size > 0 -%>
|
33
44
|
<div class="row">
|
34
45
|
<div class="col-md">
|
35
46
|
<h2 id="versions"><%=h t("about.versions") %> <i class="bi bi-info-circle"></i></h2>
|
data/templates/layout.html.erb
CHANGED
@@ -3,7 +3,6 @@
|
|
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">
|
6
|
-
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
|
7
6
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
|
8
7
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.1/font/bootstrap-icons.css">
|
9
8
|
<%- if param[:css_file] -%>
|
@@ -15,11 +14,28 @@
|
|
15
14
|
<title><%=h html_title(param) %></title>
|
16
15
|
<meta name="twitter:card" content="summary">
|
17
16
|
<meta name="twitter:title" content="<%=h html_title(param) %>">
|
17
|
+
<meta property="og:title" content="<%=h html_title(param) %>">
|
18
|
+
<meta property="og:type" content="website">
|
19
|
+
<%- if param[:uri] -%>
|
20
|
+
<meta property="og:url" content="<%=h param[:uri] %>">
|
21
|
+
<%- end -%>
|
22
|
+
<%- if param[:logo] -%>
|
23
|
+
<meta property="og:image" content="<%=h URI.parse(param[:base_uri]) + param[:logo] %>">
|
24
|
+
<%- end -%>
|
25
|
+
<%- if param[:google_analytics] -%>
|
26
|
+
<script async src="https://www.googletagmanager.com/gtag/js?id=<%=h param[:google_analytics] %>"></script>
|
27
|
+
<script>
|
28
|
+
window.dataLayer = window.dataLayer || [];
|
29
|
+
function gtag(){dataLayer.push(arguments);}
|
30
|
+
gtag('js', new Date());
|
31
|
+
gtag('config', '<%=u param[:google_analytics] %>');
|
32
|
+
</script>
|
33
|
+
<%- end -%>
|
18
34
|
</head>
|
19
35
|
<body>
|
20
36
|
<nav class="navbar navbar-expand-lg navbar-light">
|
21
37
|
<%- if param[:logo] -%>
|
22
|
-
<a class="navbar-brand" href="
|
38
|
+
<a class="navbar-brand" href="<%=h relative_path_uri(param[:base_uri], param[:base_uri]) %>"><img src="<%=h relative_path(param[:logo]) %>" height="30"></a>
|
23
39
|
<%- end -%>
|
24
40
|
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
25
41
|
<span class="navbar-toggler-icon"></span>
|
@@ -27,19 +43,24 @@
|
|
27
43
|
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
28
44
|
<ul class="navbar-nav mr-auto">
|
29
45
|
<li class="nav-item<%= ' active' if @template == "index.html.erb" %>">
|
30
|
-
<a class="nav-link" href="
|
46
|
+
<a class="nav-link" href="<%=h relative_path_uri(param[:base_uri], param[:base_uri]) %>">Home</a>
|
31
47
|
</li>
|
32
48
|
<li class="nav-item<%= ' active' if @template == "about.html.erb" %>">
|
33
|
-
<a class="nav-link" href="
|
49
|
+
<a class="nav-link" href="<%=h relative_path(param[:about_file] || "about.html") %>">About</a>
|
34
50
|
</li>
|
51
|
+
<%- if param[:additional_link] -%>
|
52
|
+
<%- param[:additional_link].each do |link| -%>
|
53
|
+
<li class="nav-item"><a class="nav-link" href="<%=h link["href"] %>"><%=h link["label"] %></a></li>
|
54
|
+
<%- end -%>
|
55
|
+
<%- end -%>
|
35
56
|
</ul>
|
36
57
|
</div>
|
37
58
|
</nav>
|
38
59
|
<%= param[:content] %>
|
39
60
|
<hr>
|
40
61
|
<footer>
|
41
|
-
<%- if param[:
|
42
|
-
|
62
|
+
<%- if param[:turtle_uri] -%>
|
63
|
+
<p class="float-right"><a href="<%=h param[:turtle_uri] %>"><img src="https://www.w3.org/RDF/icons/rdf_flyer.24" alt="<%=h t("layout.rdf-data") %>"></a></p>
|
43
64
|
<%- end -%>
|
44
65
|
<%- if param[:admin_name] -%>
|
45
66
|
<p>
|
data/templates/version.html.erb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
<dt><%=h param[:data][:date] %></dt>
|
2
2
|
<dd><%=h t("about.version-release", version: param[:data][:version]) %></dd>
|
3
|
-
<dd><%=h get_language_literal(param[:data][:description])
|
3
|
+
<dd><%=h get_language_literal(param[:data][:description]) %>
|
4
|
+
<%- if param[:data][:link] -%>
|
5
|
+
<%= t("about.version-link", link: param[:data][:link]) %>
|
6
|
+
<%- end -%>
|
7
|
+
</dd>
|
4
8
|
<%- if param[:data][:datadump] -%>
|
5
9
|
<dd><ul>
|
6
10
|
<li><a href="<%=h param[:data][:datadump] %>"><%=h File.basename(param[:data][:datadump]) %></a>
|
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: 1.3.
|
4
|
+
version: 1.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masao Takaku
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|