ttl2html 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ttl2html/template.rb +9 -8
- data/lib/ttl2html/version.rb +1 -1
- data/lib/ttl2html.rb +55 -48
- data/locales/en.yml +2 -0
- data/locales/ja.yml +2 -0
- data/templates/dataset.html.erb +35 -0
- data/templates/index.html.erb +1 -1
- data/templates/triples.html.erb +4 -8
- data/templates/version.html.erb +3 -25
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3014009aab356311f3f36ff39087b63af87dc81a97d72ad34a74c4a685fd810a
|
4
|
+
data.tar.gz: 9f55838aee5811144d539ac036567803dbd34005335e6ab1762aef8c152c772b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d6756b3c78a0b13516475c11884e4c5f86e2945046101504e4810dbf83210d6d3c679eae74a8ac841d1e44cec3908e5c05364d9b5b606a1058d40af356b949f
|
7
|
+
data.tar.gz: 7b5b6c0d6c131e2a883e0781af9b11d999e1f35918e0b012a83ad926bf52621a1fd62be76620922800ebe27d0155fc547ddb5a49ff3eb1fc4f18804fd3925421
|
data/lib/ttl2html/template.rb
CHANGED
@@ -157,8 +157,8 @@ module TTL2HTML
|
|
157
157
|
titles.compact.join(" - ")
|
158
158
|
end
|
159
159
|
def shorten_title(title, length = 140)
|
160
|
-
if title.length > length
|
161
|
-
title[0..length] + "..."
|
160
|
+
if title.to_s.length > length
|
161
|
+
title.to_s[0..length] + "..."
|
162
162
|
else
|
163
163
|
title
|
164
164
|
end
|
@@ -187,14 +187,15 @@ module TTL2HTML
|
|
187
187
|
default_title
|
188
188
|
end
|
189
189
|
def get_language_literal(object)
|
190
|
-
if object.
|
191
|
-
|
192
|
-
|
190
|
+
if object.is_a? Array
|
191
|
+
object_lang = object.select do |e|
|
192
|
+
e.language? and e.language == I18n.locale
|
193
|
+
end
|
194
|
+
if not object_lang.empty?
|
195
|
+
object_lang.first
|
193
196
|
else
|
194
|
-
object.
|
197
|
+
object.first
|
195
198
|
end
|
196
|
-
elsif object.is_a? Array
|
197
|
-
object.first
|
198
199
|
else
|
199
200
|
object
|
200
201
|
end
|
data/lib/ttl2html/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
TTL2HTML::VERSION = "2.0.
|
1
|
+
TTL2HTML::VERSION = "2.0.3"
|
data/lib/ttl2html.rb
CHANGED
@@ -53,17 +53,14 @@ module TTL2HTML
|
|
53
53
|
o = statement.object
|
54
54
|
count += 1
|
55
55
|
@data[s.to_s] ||= {}
|
56
|
-
|
57
|
-
@data[s.to_s][v.to_s] ||= {}
|
58
|
-
@data[s.to_s][v.to_s][o.language] = o.to_s
|
59
|
-
else
|
60
|
-
@data[s.to_s][v.to_s] ||= []
|
61
|
-
@data[s.to_s][v.to_s] << o.to_s
|
62
|
-
end
|
56
|
+
@data[s.to_s][v.to_s] ||= []
|
63
57
|
if o.is_a? RDF::URI or o.is_a? RDF::Node
|
58
|
+
@data[s.to_s][v.to_s] << o.to_s
|
64
59
|
@data_inverse[o.to_s] ||= {}
|
65
60
|
@data_inverse[o.to_s][v.to_s] ||= []
|
66
61
|
@data_inverse[o.to_s][v.to_s] << s.to_s
|
62
|
+
else
|
63
|
+
@data[s.to_s][v.to_s] << o
|
67
64
|
end
|
68
65
|
end
|
69
66
|
@prefix.merge! reader.prefixes
|
@@ -240,10 +237,12 @@ module TTL2HTML
|
|
240
237
|
else
|
241
238
|
label = template.get_title(@data[subject.to_s])
|
242
239
|
end
|
240
|
+
html = template.expand_shape(@data, subject.to_s, @prefix)
|
241
|
+
next if html.nil?
|
243
242
|
param[:shapes][subject] = {
|
244
243
|
label: label,
|
245
244
|
comment: comment,
|
246
|
-
html:
|
245
|
+
html: html,
|
247
246
|
target_class: target_class,
|
248
247
|
order: orders,
|
249
248
|
}
|
@@ -349,6 +348,37 @@ module TTL2HTML
|
|
349
348
|
orders
|
350
349
|
end
|
351
350
|
|
351
|
+
def extract_version_metadata(data)
|
352
|
+
description = data["http://purl.org/dc/terms/description"]
|
353
|
+
link = nil
|
354
|
+
if not description
|
355
|
+
qrev = data["http://www.w3.org/ns/prov#qualifiedRevision"]&.first
|
356
|
+
if @data[qrev]
|
357
|
+
description = @data[qrev]["http://www.w3.org/2000/01/rdf-schema#comment"]
|
358
|
+
link = @data[qrev]["http://www.w3.org/2000/01/rdf-schema#seeAlso"]&.first
|
359
|
+
end
|
360
|
+
end
|
361
|
+
subset = []
|
362
|
+
if data["http://rdfs.org/ns/void#subset"]
|
363
|
+
data["http://rdfs.org/ns/void#subset"].each do |s|
|
364
|
+
abort "#{s} not found" if not @data[s]
|
365
|
+
subset << extract_version_metadata(@data[s])
|
366
|
+
end
|
367
|
+
end
|
368
|
+
date = data["http://purl.org/pav/createdOn"]&.first
|
369
|
+
date = data["http://purl.org/dc/terms/issued"]&.first if date.nil?
|
370
|
+
return {
|
371
|
+
version: data["http://purl.org/pav/version"]&.first,
|
372
|
+
triples: data["http://rdfs.org/ns/void#triples"]&.first,
|
373
|
+
datadump: data["http://rdfs.org/ns/void#dataDump"]&.first,
|
374
|
+
bytesize: data["http://www.w3.org/ns/dcat#byteSize"]&.first,
|
375
|
+
date: date,
|
376
|
+
description: description,
|
377
|
+
subset: subset,
|
378
|
+
link: link,
|
379
|
+
license: extract_license(data),
|
380
|
+
}
|
381
|
+
end
|
352
382
|
def extract_versions
|
353
383
|
versions = []
|
354
384
|
["http://purl.org/pav/hasVersion", "http://purl.org/pav/hasCurrentVersion", "http://purl.org/dc/terms/hasVersion"].each do |prop|
|
@@ -364,37 +394,24 @@ module TTL2HTML
|
|
364
394
|
next if not version
|
365
395
|
next if not version["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"]
|
366
396
|
next if not version["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"].include? "http://rdfs.org/ns/void#Dataset"
|
367
|
-
|
368
|
-
link = nil
|
369
|
-
if not description
|
370
|
-
qrev = version["http://www.w3.org/ns/prov#qualifiedRevision"]&.first
|
371
|
-
if @data[qrev]
|
372
|
-
description = @data[qrev]["http://www.w3.org/2000/01/rdf-schema#comment"]
|
373
|
-
link = @data[qrev]["http://www.w3.org/2000/01/rdf-schema#seeAlso"]&.first
|
374
|
-
end
|
375
|
-
end
|
376
|
-
subset = []
|
377
|
-
if version["http://rdfs.org/ns/void#subset"]
|
378
|
-
version["http://rdfs.org/ns/void#subset"].each do |s|
|
379
|
-
subset << @data[s]["http://rdfs.org/ns/void#dataDump"].first
|
380
|
-
end
|
381
|
-
end
|
382
|
-
date = version["http://purl.org/pav/createdOn"]&.first
|
383
|
-
date = version["http://purl.org/dc/terms/issued"]&.first if date.nil?
|
384
|
-
versions << {
|
385
|
-
uri: uri,
|
386
|
-
version: version["http://purl.org/pav/version"]&.first,
|
387
|
-
triples: version["http://rdfs.org/ns/void#triples"]&.first,
|
388
|
-
datadump: version["http://rdfs.org/ns/void#dataDump"]&.first,
|
389
|
-
bytesize: version["http://www.w3.org/ns/dcat#byteSize"]&.first,
|
390
|
-
date: date,
|
391
|
-
description: description,
|
392
|
-
subset: subset,
|
393
|
-
link: link,
|
394
|
-
}
|
397
|
+
versions << extract_version_metadata(version)
|
395
398
|
end
|
396
399
|
end
|
397
|
-
versions.sort_by{|v| [ v[:date], v[:
|
400
|
+
versions.sort_by{|v| [ v[:date], v[:version] ] }
|
401
|
+
end
|
402
|
+
def extract_license(data)
|
403
|
+
license = {}
|
404
|
+
if data["http://purl.org/dc/terms/license"]
|
405
|
+
license_data = @data[data["http://purl.org/dc/terms/license"].first]
|
406
|
+
if license_data
|
407
|
+
license[:url] = license_data["http://www.w3.org/1999/02/22-rdf-syntax-ns#value"]&.first
|
408
|
+
license[:icon] = license_data["http://xmlns.com/foaf/0.1/thumbnail"]&.first
|
409
|
+
license[:label] = license_data["http://www.w3.org/2000/01/rdf-schema#label"]
|
410
|
+
elsif data["http://purl.org/dc/terms/license"].first =~ URI::regexp
|
411
|
+
license[:url] = license[:label] = data["http://purl.org/dc/terms/license"].first
|
412
|
+
end
|
413
|
+
end
|
414
|
+
license
|
398
415
|
end
|
399
416
|
def extract_toplevel
|
400
417
|
result = {}
|
@@ -406,17 +423,7 @@ module TTL2HTML
|
|
406
423
|
end
|
407
424
|
data = @data[toplevel.to_s]
|
408
425
|
if toplevel
|
409
|
-
license =
|
410
|
-
if data["http://purl.org/dc/terms/license"]
|
411
|
-
license_data = @data[data["http://purl.org/dc/terms/license"].first]
|
412
|
-
if license_data
|
413
|
-
license[:url] = license_data["http://www.w3.org/1999/02/22-rdf-syntax-ns#value"]&.first
|
414
|
-
license[:icon] = license_data["http://xmlns.com/foaf/0.1/thumbnail"]&.first
|
415
|
-
license[:label] = license_data["http://www.w3.org/2000/01/rdf-schema#label"]
|
416
|
-
elsif data["http://purl.org/dc/terms/license"].first =~ URI::regexp
|
417
|
-
license[:url] = license[:label] = data["http://purl.org/dc/terms/license"].first
|
418
|
-
end
|
419
|
-
end
|
426
|
+
license = extract_license(data)
|
420
427
|
if data["http://purl.org/dc/terms/publisher"]
|
421
428
|
publisher_data = @data[data["http://purl.org/dc/terms/publisher"].first]
|
422
429
|
email = publisher_data["http://xmlns.com/foaf/0.1/mbox"]&.first
|
data/locales/en.yml
CHANGED
@@ -21,6 +21,8 @@ en:
|
|
21
21
|
latest-news: "Latest news"
|
22
22
|
past-versions: "Past versions"
|
23
23
|
license-text: "This dataset is freely usable as <a href=\"%{url}\">%{label}</a>"
|
24
|
+
dataset:
|
25
|
+
license-text: "This dataset is freely usable as <a href=\"%{url}\">%{label}</a>"
|
24
26
|
layout:
|
25
27
|
rdf-data: RDF data
|
26
28
|
shape-table:
|
data/locales/ja.yml
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
<%- if param[:datadump] -%>
|
2
|
+
<li><a href="<%=h param[:datadump] %>"><%=h File.basename(param[:datadump]) %></a>
|
3
|
+
<%-
|
4
|
+
fileinfo = []
|
5
|
+
if param[:triples]
|
6
|
+
fileinfo << t("about.version-triples", triples: number_with_delimiter(param[:triples].to_i))
|
7
|
+
end
|
8
|
+
if param[:bytesize]
|
9
|
+
fileinfo << number_to_human_size(param[:bytesize])
|
10
|
+
end
|
11
|
+
-%>
|
12
|
+
<%- if fileinfo.size > 0 -%>
|
13
|
+
(<%=h fileinfo.join(", ") %>)
|
14
|
+
<%- end -%>
|
15
|
+
<%- if not param[:license].empty? -%>
|
16
|
+
<span class="license">
|
17
|
+
<%- if param[:license][:icon] -%>
|
18
|
+
<a href="<%=h param[:license][:url] %>"><img src="<%=h param[:license][:icon] %>"></a>
|
19
|
+
<%- end -%>
|
20
|
+
<%= t("dataset.license-text", label: get_language_literal(param[:license][:label]), url: param[:license][:url]) %>
|
21
|
+
</span>
|
22
|
+
<%- end -%>
|
23
|
+
<%- if param[:subset].size > 0 -%>
|
24
|
+
<ul>
|
25
|
+
<%- param[:subset].each do |subset| -%>
|
26
|
+
<%= to_html_raw("dataset.html.erb", subset) %>
|
27
|
+
<%- end -%>
|
28
|
+
</ul>
|
29
|
+
<%- end -%>
|
30
|
+
</li>
|
31
|
+
<%- elsif param[:subset].size > 0 -%>
|
32
|
+
<%- param[:subset].each do |subset| -%>
|
33
|
+
<%= to_html_raw("dataset.html.erb", subset) %>
|
34
|
+
<%- end -%>
|
35
|
+
<%- end -%>
|
data/templates/index.html.erb
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
<%- if param[:versions].size > 1 -%>
|
21
21
|
<p><a href="about#versions">» <%=h t("index.past-versions") %></a></p>
|
22
22
|
<%- end -%>
|
23
|
-
<%- if param[:toplevel] and param[:toplevel][:license] -%>
|
23
|
+
<%- if param[:toplevel] and not param[:toplevel][:license].empty? -%>
|
24
24
|
<p>
|
25
25
|
<%- if param[:toplevel][:license][:icon] -%>
|
26
26
|
<a href="<%=h param[:toplevel][:license][:url] %>"><img src="<%=h param[:toplevel][:license][:icon] %>"></a>
|
data/templates/triples.html.erb
CHANGED
@@ -5,11 +5,6 @@
|
|
5
5
|
[ order, k ]
|
6
6
|
}.each do |k, v| -%>
|
7
7
|
<dt class="col-sm-3"><%=h format_property(k, param[:labels]) %></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
8
|
<%- v.sort_by{|e|
|
14
9
|
if e =~ /\A_:/ and param[:data_global][e]
|
15
10
|
param[:data_global][e].to_s
|
@@ -17,10 +12,11 @@
|
|
17
12
|
e
|
18
13
|
end
|
19
14
|
}.each_with_index do |v2, idx| -%>
|
15
|
+
<%- if v2.respond_to? :language and v2.language? -%>
|
16
|
+
<dd class="col-sm-9<%= ' offset-sm-3' if idx > 0 %>" lang="<%=h v2.language %>"><%= format_object v2, param[:data], param[:type] %></dd>
|
17
|
+
<%- else -%>
|
20
18
|
<dd class="col-sm-9<%= ' offset-sm-3' if idx > 0 %>"><%= format_object v2, param[:data], param[:type] %></dd>
|
19
|
+
<%- end -%>
|
21
20
|
<%- end -%>
|
22
|
-
<%- else -%>
|
23
|
-
<dd class="col-sm-9"><%= format_object v.first, param[:data], param[:type] %></dd>
|
24
|
-
<%- end -%>
|
25
21
|
<%- end -%>
|
26
22
|
</dl>
|
data/templates/version.html.erb
CHANGED
@@ -5,28 +5,6 @@
|
|
5
5
|
<%= t("about.version-link", link: param[:data][:link]) %>
|
6
6
|
<%- end -%>
|
7
7
|
</dd>
|
8
|
-
<%- if param[:data][:
|
9
|
-
<dd><ul>
|
10
|
-
|
11
|
-
<%-
|
12
|
-
fileinfo = []
|
13
|
-
if param[:data][:triples]
|
14
|
-
fileinfo << t("about.version-triples", triples: number_with_delimiter(param[:data][:triples].to_i))
|
15
|
-
end
|
16
|
-
if param[:data][:bytesize]
|
17
|
-
fileinfo << number_to_human_size(param[:data][:bytesize])
|
18
|
-
end
|
19
|
-
-%>
|
20
|
-
<%- if fileinfo.size > 0 -%>
|
21
|
-
(<%=h fileinfo.join(", ") %>)
|
22
|
-
<%- end -%>
|
23
|
-
<%- if param[:data][:subset].size > 0 -%>
|
24
|
-
<ul>
|
25
|
-
<%- param[:data][:subset].each do |subset| -%>
|
26
|
-
<li><a href="<%=h subset %>"><%=h File.basename(subset) %></a></li>
|
27
|
-
<%- end -%>
|
28
|
-
</ul>
|
29
|
-
</li>
|
30
|
-
<%- end -%>
|
31
|
-
</ul></dd>
|
32
|
-
<%- end -%>
|
8
|
+
<%- if param[:data][:dataDump] or param[:data][:subset] -%>
|
9
|
+
<dd><ul><%= to_html_raw("dataset.html.erb", param[:data]) %></ul></dd>
|
10
|
+
<%- end -%>
|
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: 2.0.
|
4
|
+
version: 2.0.3
|
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-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -156,6 +156,7 @@ files:
|
|
156
156
|
- locales/en.yml
|
157
157
|
- locales/ja.yml
|
158
158
|
- templates/about.html.erb
|
159
|
+
- templates/dataset.html.erb
|
159
160
|
- templates/default.html.erb
|
160
161
|
- templates/index-list.html.erb
|
161
162
|
- templates/index.html.erb
|