ttl2html 2.1.2 → 2.2.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 +62 -23
- data/lib/ttl2html/version.rb +1 -1
- data/lib/ttl2html.rb +3 -0
- data/templates/default.html.erb +3 -0
- 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: 221f8ca33a9e3988ed12acf79e6c028a04e67e7733916611d2795e2c34a64056
|
4
|
+
data.tar.gz: 5ac1d7e52e7e65c016ed285d640d5bb03890cfc52048ce91801b949480a34252
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf90d497ed178964e0f950f5c91902061347417e2e911ed965d4d61af00c11d5835d7d0360364c0874c1e70412e9e11a3069ef8dfcf7e5aadffd33bb5301dffe
|
7
|
+
data.tar.gz: 5ed644ef6b70846d6a355b7405df15950b5061d28085ab341794edeb3f188393525849c732449dfcec70e866c49a9562d32561f38435fed396358a269be98a7c
|
data/lib/ttl2html/template.rb
CHANGED
@@ -164,27 +164,20 @@ module TTL2HTML
|
|
164
164
|
end
|
165
165
|
end
|
166
166
|
def get_title(data, default_title = "no title")
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
http://purl.org/dc/elements/1.1/title
|
182
|
-
http://schema.org/name
|
183
|
-
http://www.w3.org/2004/02/skos/core#prefLabel
|
184
|
-
).each do |property|
|
185
|
-
return shorten_title(get_language_literal(data[property])) if data[property]
|
186
|
-
end
|
187
|
-
default_title
|
167
|
+
resolve_title(data,
|
168
|
+
default: default_title,
|
169
|
+
use_default: true,
|
170
|
+
property_key: :title_property,
|
171
|
+
perclass_key: :title_property_perclass
|
172
|
+
)
|
173
|
+
end
|
174
|
+
def get_subtitle(data, default_title = nil)
|
175
|
+
resolve_title(data,
|
176
|
+
default: default_title,
|
177
|
+
use_default: false,
|
178
|
+
property_key: :subtitle_property,
|
179
|
+
perclass_key: :subtitle_property_perclass
|
180
|
+
)
|
188
181
|
end
|
189
182
|
def get_language_literal(object)
|
190
183
|
if object.is_a? Array
|
@@ -215,7 +208,13 @@ module TTL2HTML
|
|
215
208
|
if /\Ahttps?:\/\// =~ object.to_s
|
216
209
|
rel_path = relative_path_uri(object, param[:base_uri])
|
217
210
|
if param[:data_global][object]
|
218
|
-
"<a href=\"#{rel_path}\">#{get_title(param[:data_global][object]) or object}</a>"
|
211
|
+
result = "<a href=\"#{rel_path}\">#{get_title(param[:data_global][object]) or object}</a>"
|
212
|
+
subtitle = get_subtitle(param[:data_global][object])
|
213
|
+
if subtitle
|
214
|
+
result += " <small>#{subtitle}</small>"
|
215
|
+
else
|
216
|
+
result
|
217
|
+
end
|
219
218
|
else
|
220
219
|
"<a href=\"#{rel_path}\">#{object}</a>"
|
221
220
|
end
|
@@ -281,5 +280,45 @@ module TTL2HTML
|
|
281
280
|
param_local = @param.dup.merge(data: version)
|
282
281
|
to_html_raw("version.html.erb", param_local)
|
283
282
|
end
|
283
|
+
|
284
|
+
private
|
285
|
+
|
286
|
+
def resolve_title(data, default:, use_default:, property_key:, perclass_key:)
|
287
|
+
return default if data.nil?
|
288
|
+
# rdf:type
|
289
|
+
type_key = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
|
290
|
+
# 1. クラスごとのプロパティ指定がある場合
|
291
|
+
if @param[perclass_key].is_a?(Hash) && data[type_key]
|
292
|
+
Array(data[type_key]).each do |klass|
|
293
|
+
if @param[perclass_key][klass]
|
294
|
+
prop = @param[perclass_key][klass]
|
295
|
+
if valid_value?(data[prop])
|
296
|
+
return shorten_title(get_language_literal(data[prop]))
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
301
|
+
# 2. 一般プロパティ
|
302
|
+
if @param[property_key] && valid_value?(data[@param[property_key]])
|
303
|
+
return shorten_title(get_language_literal(data[@param[property_key]]))
|
304
|
+
end
|
305
|
+
# 3. デフォルト候補を順にチェック
|
306
|
+
if use_default
|
307
|
+
[
|
308
|
+
"http://www.w3.org/2000/01/rdf-schema#label",
|
309
|
+
"http://purl.org/dc/terms/title",
|
310
|
+
"http://purl.org/dc/elements/1.1/title",
|
311
|
+
"http://schema.org/name",
|
312
|
+
"http://www.w3.org/2004/02/skos/core#prefLabel"
|
313
|
+
].each do |prop|
|
314
|
+
return shorten_title(get_language_literal(data[prop])) if valid_value?(data[prop])
|
315
|
+
end
|
316
|
+
end
|
317
|
+
# 4. fallback
|
318
|
+
default
|
319
|
+
end
|
320
|
+
def valid_value?(value)
|
321
|
+
value && !(value.respond_to?(:empty?) && value.empty?)
|
322
|
+
end
|
284
323
|
end
|
285
|
-
end
|
324
|
+
end
|
data/lib/ttl2html/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
TTL2HTML::VERSION = "2.
|
1
|
+
TTL2HTML::VERSION = "2.2.0"
|
data/lib/ttl2html.rb
CHANGED
@@ -172,6 +172,9 @@ module TTL2HTML
|
|
172
172
|
param[:data_inverse_global] = @data_inverse
|
173
173
|
param[:data_global] = @data
|
174
174
|
param[:title] = template.get_title(v)
|
175
|
+
if @config[:subtitle_property] or @config[:subtitle_property_perclass]
|
176
|
+
param[:subtitle] = template.get_subtitle(v)
|
177
|
+
end
|
175
178
|
if param[:breadcrumbs]
|
176
179
|
param[:breadcrumbs_items] = build_breadcrumbs(uri, template)
|
177
180
|
end
|
data/templates/default.html.erb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
<div class="jumbotron">
|
2
2
|
<div class="container">
|
3
3
|
<h1><%=h param[:title] %></h1>
|
4
|
+
<%- if param[:subtitle] -%>
|
5
|
+
<p class="lead"><%=h param[:subtitle] %></p>
|
6
|
+
<%- end -%>
|
4
7
|
<p><i class="bi bi-link-45deg"></i> <a href="<%=h param[:uri] %>"><%=h param[:uri] %></a></p>
|
5
8
|
</div>
|
6
9
|
</div>
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ttl2html
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masao Takaku
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-06-07 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: nokogiri
|