ttl2html 1.2.0 → 1.3.0
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 +13 -5
- data/lib/ttl2html/version.rb +1 -1
- data/lib/ttl2html.rb +44 -4
- data/locales/en.yml +3 -1
- data/locales/ja.yml +3 -1
- data/templates/about.html.erb +8 -10
- data/templates/default.html.erb +25 -5
- data/templates/index.html.erb +1 -1
- data/templates/layout.html.erb +18 -10
- data/templates/triples.html.erb +18 -14
- 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: 6d6db7238da3700fba83d389bdab577f9bacc2c5da65f993612731716ac4899a
|
4
|
+
data.tar.gz: 1804e3b40f344e00618699202d331e03e2e5324519626df62389fc739925fe82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bbcc86b1acc04ad04c8a5f98b11fe020366630b7fc3ad99067e7de19853afd3311e7534fe80facc150490a784d2e96600b20e43e66f6da7aa1380a1fe8c2163
|
7
|
+
data.tar.gz: c93964d3ef71fa6e300e8634ae49a3dd5f083f737ac3d0ae3224c9493b5d7bdb8846f6a95b1803110eab1b16971b951a38c802522c0a1099f30c16d11910632f
|
data/lib/ttl2html/template.rb
CHANGED
@@ -156,16 +156,23 @@ module TTL2HTML
|
|
156
156
|
dest_uri
|
157
157
|
end
|
158
158
|
end
|
159
|
+
def shorten_title(title, length = 140)
|
160
|
+
if title.length > length
|
161
|
+
title[0..length] + "..."
|
162
|
+
else
|
163
|
+
title
|
164
|
+
end
|
165
|
+
end
|
159
166
|
def get_title(data, default_title = "no title")
|
160
167
|
if @param[:title_property_perclass] and data["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"]
|
161
168
|
@param[:title_property_perclass].each do |klass, property|
|
162
169
|
if data["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"].include?(klass) and data[property]
|
163
|
-
return get_language_literal(data[property])
|
170
|
+
return shorten_title(get_language_literal(data[property]))
|
164
171
|
end
|
165
172
|
end
|
166
173
|
end
|
167
174
|
if @param[:title_property] and data[@param[:title_property]]
|
168
|
-
return get_language_literal(data[@param[:title_property]])
|
175
|
+
return shorten_title(get_language_literal(data[@param[:title_property]]))
|
169
176
|
end
|
170
177
|
%w(
|
171
178
|
http://www.w3.org/2000/01/rdf-schema#label
|
@@ -174,7 +181,7 @@ module TTL2HTML
|
|
174
181
|
http://schema.org/name
|
175
182
|
http://www.w3.org/2004/02/skos/core#prefLabel
|
176
183
|
).each do |property|
|
177
|
-
return get_language_literal(data[property]) if data[property]
|
184
|
+
return shorten_title(get_language_literal(data[property])) if data[property]
|
178
185
|
end
|
179
186
|
default_title
|
180
187
|
end
|
@@ -212,8 +219,9 @@ module TTL2HTML
|
|
212
219
|
object
|
213
220
|
end
|
214
221
|
end
|
215
|
-
def format_triples(triples)
|
222
|
+
def format_triples(triples, type = :default)
|
216
223
|
param_local = @param.dup.merge(data: triples)
|
224
|
+
param_local[:type] = type
|
217
225
|
if @param[:labels_with_class] and triples["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"]
|
218
226
|
@param[:labels_with_class].reverse_each do |k, v|
|
219
227
|
triples["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"].each do |entity_class|
|
@@ -229,4 +237,4 @@ module TTL2HTML
|
|
229
237
|
to_html_raw("triples.html.erb", param_local)
|
230
238
|
end
|
231
239
|
end
|
232
|
-
end
|
240
|
+
end
|
data/lib/ttl2html/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
TTL2HTML::VERSION = "1.
|
1
|
+
TTL2HTML::VERSION = "1.3.0"
|
data/lib/ttl2html.rb
CHANGED
@@ -136,10 +136,14 @@ module TTL2HTML
|
|
136
136
|
template = Template.new("default.html.erb", @config)
|
137
137
|
param = @config.dup
|
138
138
|
param[:uri] = uri
|
139
|
+
param[:turtle_uri] = uri_mapping_to_path(uri, ".ttl")
|
139
140
|
param[:data] = v
|
140
141
|
param[:data_inverse] = @data_inverse[uri]
|
141
142
|
param[:data_global] = @data
|
142
143
|
param[:title] = template.get_title(v)
|
144
|
+
if param[:breadcrumbs]
|
145
|
+
param[:breadcrumbs_items] = build_breadcrumbs(uri, template)
|
146
|
+
end
|
143
147
|
file = uri_mapping_to_path(uri, ".html")
|
144
148
|
if @config[:output_dir]
|
145
149
|
Dir.mkdir @config[:output_dir] if not File.exist? @config[:output_dir]
|
@@ -176,16 +180,22 @@ module TTL2HTML
|
|
176
180
|
param[:data_global] = @data
|
177
181
|
param[:content] = {}
|
178
182
|
shapes.subjects.each do |subject|
|
179
|
-
label = nil
|
183
|
+
label = comment = nil
|
180
184
|
target_class = @data[subject.to_s]["http://www.w3.org/ns/shacl#targetClass"]
|
181
185
|
if target_class
|
182
|
-
|
183
|
-
|
186
|
+
target_class = target_class.first
|
187
|
+
if @data[target_class]
|
188
|
+
label = template.get_title(@data[target_class], nil)
|
189
|
+
comment = @data[target_class]["http://www.w3.org/2000/01/rdf-schema#comment"]&.first
|
190
|
+
else
|
191
|
+
label = template.format_property(target_class)
|
192
|
+
end
|
184
193
|
else
|
185
194
|
label = template.get_title(@data[subject.to_s])
|
186
195
|
end
|
187
196
|
param[:content][subject] = {
|
188
197
|
label: label,
|
198
|
+
comment: comment,
|
189
199
|
html: template.expand_shape(@data, subject.to_s, @prefix),
|
190
200
|
}
|
191
201
|
end
|
@@ -193,6 +203,36 @@ module TTL2HTML
|
|
193
203
|
end
|
194
204
|
end
|
195
205
|
|
206
|
+
def build_breadcrumbs(uri, template, depth = 0)
|
207
|
+
results = []
|
208
|
+
data = @data[uri]
|
209
|
+
if @config[:breadcrumbs]
|
210
|
+
if depth == 0
|
211
|
+
first_label = template.get_title(data)
|
212
|
+
first_label = data[@config[:breadcrumbs].first["label"]].first if @config[:breadcrumbs].first["label"] and data[@config[:breadcrumbs].first["label"]]
|
213
|
+
results << { label: first_label }
|
214
|
+
end
|
215
|
+
@config[:breadcrumbs].each do |e|
|
216
|
+
data_target = data
|
217
|
+
data_target = @data_inverse[uri] if e["inverse"]
|
218
|
+
if data_target and data_target[e["property"]]
|
219
|
+
data_target[e["property"]].each do |parent|
|
220
|
+
data_parent = @data[parent]
|
221
|
+
label = template.get_title(data_parent)
|
222
|
+
label = data_parent[e["label"]].first if e["label"] and data_parent[e["label"]]
|
223
|
+
results << {
|
224
|
+
uri: parent,
|
225
|
+
label: label,
|
226
|
+
}
|
227
|
+
results += build_breadcrumbs(parent, template, depth + 1)
|
228
|
+
end
|
229
|
+
return results
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
results
|
234
|
+
end
|
235
|
+
|
196
236
|
def shapes2labels(shapes)
|
197
237
|
labels = {}
|
198
238
|
shapes.subjects.each do |shape|
|
@@ -292,4 +332,4 @@ module TTL2HTML
|
|
292
332
|
file
|
293
333
|
end
|
294
334
|
end
|
295
|
-
end
|
335
|
+
end
|
data/locales/en.yml
CHANGED
@@ -23,4 +23,6 @@ en:
|
|
23
23
|
optional: "Optional"
|
24
24
|
non-repeatable: "Non repeatable"
|
25
25
|
blank-node-structure: "The structural contents of a blank node are as follows:"
|
26
|
-
blank-node-or-structure: "The structural contents of a blank node are either of the followings:"
|
26
|
+
blank-node-or-structure: "The structural contents of a blank node are either of the followings:"
|
27
|
+
triples:
|
28
|
+
inverse_refered: "Referred to as '%{property}' from:"
|
data/locales/ja.yml
CHANGED
@@ -22,4 +22,6 @@ ja:
|
|
22
22
|
optional: 省略可能
|
23
23
|
non-repeatable: 繰り返し無し
|
24
24
|
blank-node-structure: ブランクノードの内容は以下の内容からなる構造を持ちます。
|
25
|
-
blank-node-or-structure: ブランクノードの内容は以下のいずれかの内容からなる構造を持ちます。
|
25
|
+
blank-node-or-structure: ブランクノードの内容は以下のいずれかの内容からなる構造を持ちます。
|
26
|
+
triples:
|
27
|
+
inverse_refered: "'%{property}'としての参照元:"
|
data/templates/about.html.erb
CHANGED
@@ -3,18 +3,15 @@
|
|
3
3
|
<h1><%=h t("about.title", title: param[:site_title]) %></h1>
|
4
4
|
</div>
|
5
5
|
</div>
|
6
|
+
<nav aria-label="breadcrumb">
|
7
|
+
<ol class="breadcrumb">
|
8
|
+
<li class="breadcrumb-item"><a href="./"><i class="bi bi-house-door-fill"></i> Home</a></li>
|
9
|
+
<li class="breadcrumb-item active" aria-current="page"><%=h t("about.title", title: param[:site_title]) %></li>
|
10
|
+
</ol>
|
11
|
+
</nav>
|
6
12
|
<div class="container">
|
7
13
|
<div class="row">
|
8
|
-
<div class="col-md
|
9
|
-
<ol class="breadcrumb">
|
10
|
-
<li><a href="./"><span class="glyphicon glyphicon-home" aria-hidden="true"></span> Home</a></li>
|
11
|
-
<li class="active"><%=h t("about.title", title: param[:site_title]) %></li>
|
12
|
-
</ol>
|
13
|
-
</div>
|
14
|
-
</div>
|
15
|
-
|
16
|
-
<div class="row">
|
17
|
-
<div class="col-md-10">
|
14
|
+
<div class="col-md">
|
18
15
|
<%- param[:content].keys.sort.each do |shape| -%>
|
19
16
|
<h3><%=h param[:content][shape][:label] %></h3>
|
20
17
|
<p><%= param[:content][shape][:comment] %></p>
|
@@ -23,3 +20,4 @@
|
|
23
20
|
<%- end -%>
|
24
21
|
</div>
|
25
22
|
</div>
|
23
|
+
</div>
|
data/templates/default.html.erb
CHANGED
@@ -1,22 +1,42 @@
|
|
1
1
|
<div class="jumbotron">
|
2
2
|
<div class="container">
|
3
3
|
<h1><%=h param[:title] %></h1>
|
4
|
-
<p><
|
4
|
+
<p><i class="bi bi-link-45deg"></i> <a href="<%=h param[:uri] %>"><%=h param[:uri] %></a></p>
|
5
5
|
</div>
|
6
6
|
</div>
|
7
7
|
<div class="container">
|
8
|
+
<%- if param[:breadcrumbs] -%>
|
9
|
+
<div class="row">
|
10
|
+
<div class="col-md-12">
|
11
|
+
<nav aria-label="breadcrumb">
|
12
|
+
<ol class="breadcrumb">
|
13
|
+
<li class="breadcrumb-item"><a href="./"><i class="bi bi-house-door-fill"></i> Home</a></li>
|
14
|
+
<%- param[:breadcrumbs_items].reverse.each_with_index do |e, i| -%>
|
15
|
+
<li class="breadcrumb-item<%= ' active' if i == param[:breadcrumbs_items].size-1 %>" aria-current="page">
|
16
|
+
<%- if e[:uri] -%>
|
17
|
+
<a href="<%=h e[:uri] %>"><%=h e[:label] %></a>
|
18
|
+
<%- else -%>
|
19
|
+
<%=h e[:label] %>
|
20
|
+
<%- end -%>
|
21
|
+
</li>
|
22
|
+
<%- end -%>
|
23
|
+
</ol>
|
24
|
+
</nav>
|
25
|
+
</div>
|
26
|
+
</div>
|
27
|
+
<%- end -%>
|
8
28
|
<div class="row">
|
9
29
|
<div class="col-md-12">
|
10
30
|
<h2><%=h t("default.details") %></h2>
|
11
31
|
<%= format_triples(param[:data]) %>
|
12
32
|
</div>
|
13
33
|
</div>
|
14
|
-
|
34
|
+
<%- if param[:data_inverse] -%>
|
15
35
|
<div class="row inverse">
|
16
36
|
<div class="col-md-12">
|
17
37
|
<h2><%=h t("default.inverse_data") %></h2>
|
18
|
-
<%= format_triples(param[:data_inverse]) %>
|
38
|
+
<%= format_triples(param[:data_inverse], :inverse) %>
|
19
39
|
</div>
|
20
40
|
</div>
|
21
|
-
|
22
|
-
</div>
|
41
|
+
<%- end -%>
|
42
|
+
</div>
|
data/templates/index.html.erb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
<div class="jumbotron">
|
2
2
|
<div class="container">
|
3
3
|
<h1><%=h param[:site_title] %></h1>
|
4
|
-
<p><
|
4
|
+
<p><i class="bi bi-link-45deg"></i> <a href="<%=h param[:base_uri] %>"><%=h param[:base_uri] %></a></p>
|
5
5
|
</div>
|
6
6
|
</div>
|
7
7
|
<div class="container">
|
data/templates/layout.html.erb
CHANGED
@@ -4,17 +4,25 @@
|
|
4
4
|
<meta charset="utf-8">
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
6
6
|
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
|
7
|
-
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.
|
7
|
+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
|
8
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.1/font/bootstrap-icons.css">
|
8
9
|
<title><% if param[:title] %><%=h param[:title] %><% end %><% if param[:site_title] %> - <%=h param[:site_title] %><% end %></title>
|
9
10
|
<meta name="twitter:card" content="summary">
|
10
11
|
<meta name="twitter:title" content="<% if param[:title] %><%=h param[:title] %><% end %><% if param[:site_title] %> - <%=h param[:site_title] %><% end %>">
|
11
12
|
</head>
|
12
13
|
<body>
|
13
|
-
<nav class="navbar navbar-
|
14
|
-
<
|
15
|
-
<
|
16
|
-
|
17
|
-
|
14
|
+
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
15
|
+
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
16
|
+
<span class="navbar-toggler-icon"></span>
|
17
|
+
</button>
|
18
|
+
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
19
|
+
<ul class="navbar-nav mr-auto">
|
20
|
+
<li class="nav-item<%= ' class="active"' if param[:active] == :home %>">
|
21
|
+
<a class="navbar-brand" href="/">Home</a>
|
22
|
+
</li>
|
23
|
+
<li class="nav-item<%= ' class="active"' if param[:active] == :about %>">
|
24
|
+
<a class="navbar-brand" href="/about">About</a>
|
25
|
+
</li>
|
18
26
|
</ul>
|
19
27
|
</div>
|
20
28
|
</nav>
|
@@ -22,13 +30,13 @@
|
|
22
30
|
<hr>
|
23
31
|
<footer>
|
24
32
|
<%- if param[:uri] -%>
|
25
|
-
<p class="
|
33
|
+
<p class="text-right"><a href="<%=h relative_path(param[:turtle_uri]) %>"><img src="https://www.w3.org/RDF/icons/rdf_flyer.24" alt="<%=h t("layout.rdf-data") %>"></a></p>
|
26
34
|
<%- end -%>
|
27
35
|
</footer>
|
28
36
|
|
29
37
|
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
30
|
-
<script src="https://code.jquery.com/jquery-3.
|
31
|
-
<script src="https://
|
32
|
-
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.
|
38
|
+
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
|
39
|
+
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
|
40
|
+
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
|
33
41
|
</body>
|
34
42
|
</html>
|
data/templates/triples.html.erb
CHANGED
@@ -1,16 +1,20 @@
|
|
1
|
-
<dl>
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
<dl class="row">
|
2
|
+
<%- param[:data].each do |k, v| -%>
|
3
|
+
<%- if param[:type] == :inverse -%>
|
4
|
+
<dt class="col-sm-3"><%=h t('triples.inverse_refered', property: format_property(k, param[:labels])) %></dt>
|
5
|
+
<%- else -%>
|
6
|
+
<dt class="col-sm-3"><%=h format_property(k, param[:labels]) %></dt>
|
7
|
+
<%- end -%>
|
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] %></dd>
|
7
11
|
<% end %>
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
<dd><%= format_object v.first, param[:data] %></dd>
|
14
|
-
|
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] %></dd>
|
15
|
+
<%- end -%>
|
16
|
+
<%- else -%>
|
17
|
+
<dd class="col-sm-9"><%= format_object v.first, param[:data] %></dd>
|
18
|
+
<%- end -%>
|
15
19
|
<%- end -%>
|
16
|
-
</dl>
|
20
|
+
</dl>
|
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.
|
4
|
+
version: 1.3.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: 2021-
|
11
|
+
date: 2021-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|