ttl2html 1.1.1 → 1.3.2
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 +66 -6
- data/lib/ttl2html/version.rb +1 -1
- data/lib/ttl2html.rb +160 -54
- data/locales/en.yml +9 -1
- data/locales/ja.yml +9 -1
- data/templates/about.html.erb +30 -11
- data/templates/default.html.erb +25 -5
- data/templates/index.html.erb +28 -4
- data/templates/layout.html.erb +20 -12
- data/templates/triples.html.erb +22 -14
- data/templates/version.html.erb +28 -0
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 536529ac6440329179bab71d30e570dc92efb464526f5a0a019c59823f67098c
|
4
|
+
data.tar.gz: 4f251ed59bc227e77f80fe3ea88ea1e14e99c10ece1bb7b156d0b19f98518663
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e760bdb6848470e2e2327803e7f527684fa8e703f053cd0fda5eadc374bcaa7aeb837064f018a353f2e7c80b4845994db26106c8b139cdde9bf4e6c501f1254
|
7
|
+
data.tar.gz: 7cb13bd5ae523ef8ac62c843f27f1ce5f65efd70e035c35f35b6062e104b5c89e87d19c8ac4e7778ca0ce6b9881e1bbca92c5c34cda37793cc96add9679d66ff
|
data/lib/ttl2html/template.rb
CHANGED
@@ -4,15 +4,17 @@ require "fileutils"
|
|
4
4
|
require "pathname"
|
5
5
|
require "erb"
|
6
6
|
require "i18n"
|
7
|
+
require "action_view"
|
7
8
|
|
8
9
|
module TTL2HTML
|
9
10
|
class Template
|
10
11
|
attr_reader :param
|
11
12
|
include ERB::Util
|
12
13
|
include I18n::Base
|
14
|
+
include ActionView::Helpers::NumberHelper
|
13
15
|
def initialize(template, param = {})
|
14
16
|
@template = template
|
15
|
-
@param = param
|
17
|
+
@param = param.dup
|
16
18
|
@template_path = [ Dir.pwd, File.join(Dir.pwd, "templates") ]
|
17
19
|
@template_path << File.join(File.dirname(__FILE__), "..", "..", "templates")
|
18
20
|
I18n.load_path << Dir[File.join(File.dirname(__FILE__), "..", "..", "locales") + "/*.yml"]
|
@@ -113,6 +115,33 @@ module TTL2HTML
|
|
113
115
|
end
|
114
116
|
|
115
117
|
# helper method:
|
118
|
+
def uri_mapping_to_path(uri, suffix = ".html")
|
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
|
116
145
|
def relative_path(dest)
|
117
146
|
src = @param[:output_file]
|
118
147
|
src = Pathname.new(src).relative_path_from(Pathname.new(@param[:output_dir])) if @param[:output_dir]
|
@@ -123,21 +152,35 @@ module TTL2HTML
|
|
123
152
|
def relative_path_uri(dest_uri, base_uri)
|
124
153
|
if dest_uri.start_with? base_uri
|
125
154
|
dest = dest_uri.sub(base_uri, "")
|
155
|
+
dest = uri_mapping_to_path(dest, "")
|
126
156
|
relative_path(dest)
|
127
157
|
else
|
128
158
|
dest_uri
|
129
159
|
end
|
130
160
|
end
|
161
|
+
def html_title(param)
|
162
|
+
titles = []
|
163
|
+
titles << param[:title]
|
164
|
+
titles << param[:site_title]
|
165
|
+
titles.compact.join(" - ")
|
166
|
+
end
|
167
|
+
def shorten_title(title, length = 140)
|
168
|
+
if title.length > length
|
169
|
+
title[0..length] + "..."
|
170
|
+
else
|
171
|
+
title
|
172
|
+
end
|
173
|
+
end
|
131
174
|
def get_title(data, default_title = "no title")
|
132
175
|
if @param[:title_property_perclass] and data["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"]
|
133
176
|
@param[:title_property_perclass].each do |klass, property|
|
134
177
|
if data["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"].include?(klass) and data[property]
|
135
|
-
return get_language_literal(data[property])
|
178
|
+
return shorten_title(get_language_literal(data[property]))
|
136
179
|
end
|
137
180
|
end
|
138
181
|
end
|
139
182
|
if @param[:title_property] and data[@param[:title_property]]
|
140
|
-
return get_language_literal(data[@param[:title_property]])
|
183
|
+
return shorten_title(get_language_literal(data[@param[:title_property]]))
|
141
184
|
end
|
142
185
|
%w(
|
143
186
|
http://www.w3.org/2000/01/rdf-schema#label
|
@@ -146,7 +189,7 @@ module TTL2HTML
|
|
146
189
|
http://schema.org/name
|
147
190
|
http://www.w3.org/2004/02/skos/core#prefLabel
|
148
191
|
).each do |property|
|
149
|
-
return get_language_literal(data[property]) if data[property]
|
192
|
+
return shorten_title(get_language_literal(data[property])) if data[property]
|
150
193
|
end
|
151
194
|
default_title
|
152
195
|
end
|
@@ -173,7 +216,7 @@ module TTL2HTML
|
|
173
216
|
def format_object(object, data)
|
174
217
|
if object =~ /\Ahttps?:\/\//
|
175
218
|
rel_path = relative_path_uri(object, param[:base_uri])
|
176
|
-
if
|
219
|
+
if param[:data_global][object]
|
177
220
|
"<a href=\"#{rel_path}\">#{get_title(param[:data_global][object]) or object}</a>"
|
178
221
|
else
|
179
222
|
"<a href=\"#{rel_path}\">#{object}</a>"
|
@@ -184,8 +227,9 @@ module TTL2HTML
|
|
184
227
|
object
|
185
228
|
end
|
186
229
|
end
|
187
|
-
def format_triples(triples)
|
230
|
+
def format_triples(triples, type = :default)
|
188
231
|
param_local = @param.dup.merge(data: triples)
|
232
|
+
param_local[:type] = type
|
189
233
|
if @param[:labels_with_class] and triples["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"]
|
190
234
|
@param[:labels_with_class].reverse_each do |k, v|
|
191
235
|
triples["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"].each do |entity_class|
|
@@ -198,7 +242,23 @@ module TTL2HTML
|
|
198
242
|
end
|
199
243
|
end
|
200
244
|
end
|
245
|
+
if @param[:orders_with_class] and triples["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"]
|
246
|
+
@param[:orders_with_class].reverse_each do |k, v|
|
247
|
+
triples["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"].each do |entity_class|
|
248
|
+
if entity_class == k
|
249
|
+
v.each do |property, order|
|
250
|
+
param_local[:orders] ||= {}
|
251
|
+
param_local[:orders][property] = order || Float::INFINITY
|
252
|
+
end
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
201
257
|
to_html_raw("triples.html.erb", param_local)
|
202
258
|
end
|
259
|
+
def format_version_info(version)
|
260
|
+
param_local = @param.dup.merge(data: version)
|
261
|
+
to_html_raw("version.html.erb", param_local)
|
262
|
+
end
|
203
263
|
end
|
204
264
|
end
|
data/lib/ttl2html/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
TTL2HTML::VERSION = "1.
|
1
|
+
TTL2HTML::VERSION = "1.3.2"
|
data/lib/ttl2html.rb
CHANGED
@@ -11,7 +11,6 @@ require "ttl2html/template"
|
|
11
11
|
module TTL2HTML
|
12
12
|
class App
|
13
13
|
def initialize(config = "config.yml")
|
14
|
-
@template = {}
|
15
14
|
@config = load_config(config)
|
16
15
|
if not @config[:base_uri]
|
17
16
|
raise "load_config: base_uri not found"
|
@@ -67,66 +66,64 @@ module TTL2HTML
|
|
67
66
|
def format_turtle(subject, depth = 1)
|
68
67
|
turtle = RDF::Turtle::Writer.new
|
69
68
|
result = ""
|
70
|
-
if subject
|
71
|
-
result << "<#{subject}>\n#{" "*depth}"
|
72
|
-
else
|
69
|
+
if subject =~ /^_:/
|
73
70
|
result << "[\n#{" "*depth}"
|
71
|
+
else
|
72
|
+
result << "<#{subject}>\n#{" "*depth}"
|
74
73
|
end
|
75
|
-
result << @
|
74
|
+
result << @data[subject.to_s].keys.sort.map do |predicate|
|
76
75
|
str = "<#{predicate}> "
|
77
|
-
str << @
|
78
|
-
if object
|
79
|
-
@graph.query([object, nil, nil]).statements.sort_by{|e|
|
80
|
-
[ e.predicate, e.object ]
|
81
|
-
}.map{|e|
|
82
|
-
[ e.predicate, e.object ]
|
83
|
-
}
|
84
|
-
else
|
85
|
-
object
|
86
|
-
end
|
87
|
-
end.map do |object|
|
88
|
-
if object.resource? and not object.iri? # blank node:
|
76
|
+
str << @data[subject.to_s][predicate].sort.map do |object|
|
77
|
+
if object =~ /^_:/ # blank node:
|
89
78
|
format_turtle(object, depth + 1)
|
79
|
+
elsif object =~ RDF::URI::IRI
|
80
|
+
turtle.format_uri(RDF::URI.new object)
|
81
|
+
elsif object.respond_to?(:first) and object.first.kind_of?(Symbol)
|
82
|
+
turtle.format_literal(RDF::Literal.new(object[1], language: object[0]))
|
90
83
|
else
|
91
|
-
|
92
|
-
when RDF::URI
|
93
|
-
turtle.format_uri(object)
|
94
|
-
else
|
95
|
-
turtle.format_literal(object)
|
96
|
-
end
|
84
|
+
turtle.format_literal(object)
|
97
85
|
end
|
98
86
|
end.join(", ")
|
99
87
|
str
|
100
88
|
end.join(";\n#{" "*depth}")
|
101
|
-
result << " ." if subject
|
89
|
+
result << " ." if not subject =~ /^_:/
|
102
90
|
result << "\n"
|
103
|
-
result << "#{" "*(depth-1)}]" if
|
91
|
+
result << "#{" "*(depth-1)}]" if subject =~ /^_:/
|
104
92
|
result
|
105
93
|
end
|
106
94
|
def format_turtle_inverse(object)
|
107
|
-
turtle = RDF::Turtle::Writer.new
|
108
95
|
result = ""
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
96
|
+
return result if not object.start_with? @config[:base_uri]
|
97
|
+
return result if not @data_inverse.has_key? object
|
98
|
+
turtle = RDF::Turtle::Writer.new
|
99
|
+
@data_inverse[object].keys.sort.each do |predicate|
|
100
|
+
@data_inverse[object.to_s][predicate].sort.each do |subject|
|
101
|
+
next if subject =~ /^_:/
|
102
|
+
result << "<#{subject}> <#{predicate}> <#{object}>.\n"
|
103
|
+
end
|
114
104
|
end
|
115
105
|
result
|
116
106
|
end
|
117
107
|
|
118
|
-
def each_data
|
108
|
+
def each_data(label = :each_data)
|
109
|
+
progressbar = ProgressBar.create(title: label,
|
110
|
+
total: @data.size,
|
111
|
+
format: "(%t) %a %e %P% Processed: %c from %C")
|
119
112
|
@data.each do |uri, v|
|
113
|
+
progressbar.increment
|
120
114
|
next if not uri.start_with? @config[:base_uri]
|
121
115
|
yield uri, v
|
122
116
|
end
|
117
|
+
progressbar.finish
|
123
118
|
end
|
124
119
|
def output_html_files
|
125
|
-
template = Template.new("")
|
120
|
+
template = Template.new("", @config)
|
126
121
|
shapes = @graph.query([nil,
|
127
122
|
RDF::URI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
|
128
123
|
RDF::URI("http://www.w3.org/ns/shacl#NodeShape")])
|
129
124
|
labels = shapes2labels(shapes)
|
125
|
+
versions = extract_versions
|
126
|
+
toplevel = extract_toplevel
|
130
127
|
@config[:labels_with_class] ||= {}
|
131
128
|
labels.each do |klass, props|
|
132
129
|
props.each do |property, label|
|
@@ -138,18 +135,19 @@ module TTL2HTML
|
|
138
135
|
end
|
139
136
|
end
|
140
137
|
end
|
141
|
-
|
142
|
-
|
143
|
-
format: "(%t) %a %e %P% Processed: %c from %C")
|
144
|
-
each_data do |uri, v|
|
145
|
-
progressbar.increment
|
138
|
+
@config[:orders_with_class] = shapes2orders(shapes)
|
139
|
+
each_data(:output_html_files) do |uri, v|
|
146
140
|
template = Template.new("default.html.erb", @config)
|
147
141
|
param = @config.dup
|
148
142
|
param[:uri] = uri
|
143
|
+
param[:turtle_uri] = uri_mapping_to_path(uri, ".ttl")
|
149
144
|
param[:data] = v
|
150
145
|
param[:data_inverse] = @data_inverse[uri]
|
151
146
|
param[:data_global] = @data
|
152
147
|
param[:title] = template.get_title(v)
|
148
|
+
if param[:breadcrumbs]
|
149
|
+
param[:breadcrumbs_items] = build_breadcrumbs(uri, template)
|
150
|
+
end
|
153
151
|
file = uri_mapping_to_path(uri, ".html")
|
154
152
|
if @config[:output_dir]
|
155
153
|
Dir.mkdir @config[:output_dir] if not File.exist? @config[:output_dir]
|
@@ -157,7 +155,6 @@ module TTL2HTML
|
|
157
155
|
end
|
158
156
|
template.output_to(file, param)
|
159
157
|
end
|
160
|
-
progressbar.finish
|
161
158
|
index_html = "index.html"
|
162
159
|
index_html = File.join(@config[:output_dir], "index.html") if @config[:output_dir]
|
163
160
|
if @config.has_key? :top_class
|
@@ -171,6 +168,8 @@ module TTL2HTML
|
|
171
168
|
template = Template.new("index.html.erb", @config)
|
172
169
|
param = @config.dup
|
173
170
|
param[:data_global] = @data
|
171
|
+
param[:versions] = versions
|
172
|
+
param[:toplevel] = toplevel
|
174
173
|
subjects.sort.each do |subject|
|
175
174
|
param[:index_data] ||= []
|
176
175
|
param[:index_data] << subject.to_s
|
@@ -178,24 +177,32 @@ module TTL2HTML
|
|
178
177
|
template.output_to(index_html, param)
|
179
178
|
end
|
180
179
|
end
|
181
|
-
if shapes.size > 0
|
180
|
+
if shapes.size > 0 or versions.size > 0 or toplevel.size > 0
|
182
181
|
about_html = @config[:about_file] || "about.html"
|
183
182
|
about_html = File.join(@config[:output_dir], about_html) if @config[:output_dir]
|
184
183
|
template = Template.new("about.html.erb", @config)
|
185
184
|
param = @config.dup
|
186
185
|
param[:data_global] = @data
|
187
|
-
param[:
|
186
|
+
param[:versions] = versions
|
187
|
+
param[:toplevel] = toplevel
|
188
|
+
param[:shapes] = {}
|
188
189
|
shapes.subjects.each do |subject|
|
189
|
-
label = nil
|
190
|
+
label = comment = nil
|
190
191
|
target_class = @data[subject.to_s]["http://www.w3.org/ns/shacl#targetClass"]
|
191
192
|
if target_class
|
192
|
-
|
193
|
-
|
193
|
+
target_class = target_class.first
|
194
|
+
if @data[target_class]
|
195
|
+
label = template.get_title(@data[target_class], nil)
|
196
|
+
comment = template.get_language_literal(@data[target_class]["http://www.w3.org/2000/01/rdf-schema#comment"]) if @data[target_class]["http://www.w3.org/2000/01/rdf-schema#comment"]
|
197
|
+
else
|
198
|
+
label = template.format_property(target_class)
|
199
|
+
end
|
194
200
|
else
|
195
201
|
label = template.get_title(@data[subject.to_s])
|
196
202
|
end
|
197
|
-
param[:
|
203
|
+
param[:shapes][subject] = {
|
198
204
|
label: label,
|
205
|
+
comment: comment,
|
199
206
|
html: template.expand_shape(@data, subject.to_s, @prefix),
|
200
207
|
}
|
201
208
|
end
|
@@ -203,6 +210,36 @@ module TTL2HTML
|
|
203
210
|
end
|
204
211
|
end
|
205
212
|
|
213
|
+
def build_breadcrumbs(uri, template, depth = 0)
|
214
|
+
results = []
|
215
|
+
data = @data[uri]
|
216
|
+
if @config[:breadcrumbs]
|
217
|
+
if depth == 0
|
218
|
+
first_label = template.get_title(data)
|
219
|
+
first_label = data[@config[:breadcrumbs].first["label"]].first if @config[:breadcrumbs].first["label"] and data[@config[:breadcrumbs].first["label"]]
|
220
|
+
results << { label: first_label }
|
221
|
+
end
|
222
|
+
@config[:breadcrumbs].each do |e|
|
223
|
+
data_target = data
|
224
|
+
data_target = @data_inverse[uri] if e["inverse"]
|
225
|
+
if data_target and data_target[e["property"]]
|
226
|
+
data_target[e["property"]].each do |parent|
|
227
|
+
data_parent = @data[parent]
|
228
|
+
label = template.get_title(data_parent)
|
229
|
+
label = data_parent[e["label"]].first if e["label"] and data_parent[e["label"]]
|
230
|
+
results << {
|
231
|
+
uri: parent,
|
232
|
+
label: label,
|
233
|
+
}
|
234
|
+
results += build_breadcrumbs(parent, template, depth + 1)
|
235
|
+
end
|
236
|
+
return results
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
results
|
241
|
+
end
|
242
|
+
|
206
243
|
def shapes2labels(shapes)
|
207
244
|
labels = {}
|
208
245
|
shapes.subjects.each do |shape|
|
@@ -218,25 +255,94 @@ module TTL2HTML
|
|
218
255
|
end
|
219
256
|
labels
|
220
257
|
end
|
258
|
+
def shapes2orders(shapes)
|
259
|
+
orders = {}
|
260
|
+
shapes.subjects.each do |shape|
|
261
|
+
target_class = @data[shape.to_s]["http://www.w3.org/ns/shacl#targetClass"]&.first
|
262
|
+
if target_class
|
263
|
+
@data[shape.to_s]["http://www.w3.org/ns/shacl#property"].each do |property|
|
264
|
+
path = @data[property]["http://www.w3.org/ns/shacl#path"].first
|
265
|
+
order = @data[property]["http://www.w3.org/ns/shacl#order"]
|
266
|
+
orders[target_class] ||= {}
|
267
|
+
orders[target_class][path] = order&.first&.to_i
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
271
|
+
orders
|
272
|
+
end
|
273
|
+
|
274
|
+
def extract_versions
|
275
|
+
versions = []
|
276
|
+
["http://purl.org/pav/hasVersion", "http://purl.org/pav/hasCurrentVersion", "http://purl.org/dc/terms/hasVersion"].each do |prop|
|
277
|
+
objects = @graph.query([nil, RDF::URI(prop), nil]).objects
|
278
|
+
objects.each do |o|
|
279
|
+
uri = o.to_s
|
280
|
+
version = @data[uri]
|
281
|
+
next if not version
|
282
|
+
next if not version["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"].include? "http://rdfs.org/ns/void#Dataset"
|
283
|
+
description = version["http://purl.org/dc/terms/description"]
|
284
|
+
if not description
|
285
|
+
qrev = version["http://www.w3.org/ns/prov#qualifiedRevision"]&.first
|
286
|
+
if description = @data[qrev]
|
287
|
+
description = @data[qrev]["http://www.w3.org/2000/01/rdf-schema#comment"]
|
288
|
+
end
|
289
|
+
end
|
290
|
+
subset = []
|
291
|
+
if version["http://rdfs.org/ns/void#subset"]
|
292
|
+
version["http://rdfs.org/ns/void#subset"].each do |s|
|
293
|
+
subset << @data[s]["http://rdfs.org/ns/void#dataDump"].first
|
294
|
+
end
|
295
|
+
end
|
296
|
+
date = version["http://purl.org/pav/createdOn"]&.first
|
297
|
+
date = version["http://purl.org/dc/terms/issued"]&.first if date.nil?
|
298
|
+
versions << {
|
299
|
+
uri: uri,
|
300
|
+
version: version["http://purl.org/pav/version"]&.first,
|
301
|
+
triples: version["http://rdfs.org/ns/void#triples"]&.first,
|
302
|
+
datadump: version["http://rdfs.org/ns/void#dataDump"]&.first,
|
303
|
+
bytesize: version["http://www.w3.org/ns/dcat#byteSize"]&.first,
|
304
|
+
date: date,
|
305
|
+
description: description,
|
306
|
+
subset: subset,
|
307
|
+
}
|
308
|
+
end
|
309
|
+
end
|
310
|
+
versions.sort_by{|v| [ v[:date], v[:uri] ] }
|
311
|
+
end
|
312
|
+
def extract_toplevel
|
313
|
+
result = {}
|
314
|
+
toplevel = @graph.query([nil, RDF::URI("http://purl.org/pav/hasCurrentVersion"), nil]).subjects.first
|
315
|
+
data = @data[toplevel.to_s]
|
316
|
+
if toplevel
|
317
|
+
license = {}
|
318
|
+
if data["http://purl.org/dc/terms/license"]
|
319
|
+
license_data = @data[data["http://purl.org/dc/terms/license"].first]
|
320
|
+
license[:url] = license_data["http://www.w3.org/1999/02/22-rdf-syntax-ns#value"]&.first
|
321
|
+
license[:icon] = license_data["http://xmlns.com/foaf/0.1/thumbnail"]&.first
|
322
|
+
license[:label] = license_data["http://www.w3.org/2000/01/rdf-schema#label"]
|
323
|
+
end
|
324
|
+
result = {
|
325
|
+
uri: toplevel.to_s,
|
326
|
+
description: data["http://purl.org/dc/terms/description"],
|
327
|
+
license: license,
|
328
|
+
}
|
329
|
+
end
|
330
|
+
result
|
331
|
+
end
|
221
332
|
|
222
333
|
def output_turtle_files
|
223
|
-
|
224
|
-
total: @data.size,
|
225
|
-
format: "(%t) %a %e %P% Processed: %c from %C")
|
226
|
-
each_data do |uri, v|
|
227
|
-
progressbar.increment
|
334
|
+
each_data(:output_turtle_files) do |uri, v|
|
228
335
|
file = uri_mapping_to_path(uri, ".ttl")
|
229
336
|
if @config[:output_dir]
|
230
337
|
Dir.mkdir @config[:output_dir] if not File.exist? @config[:output_dir]
|
231
338
|
file = File.join(@config[:output_dir], file)
|
232
339
|
end
|
233
|
-
str = format_turtle(
|
234
|
-
str << format_turtle_inverse(
|
340
|
+
str = format_turtle(uri)
|
341
|
+
str << format_turtle_inverse(uri)
|
235
342
|
open(file, "w") do |io|
|
236
343
|
io.puts str.strip
|
237
344
|
end
|
238
345
|
end
|
239
|
-
progressbar.finish
|
240
346
|
end
|
241
347
|
def uri_mapping_to_path(uri, suffix = ".html")
|
242
348
|
path = nil
|
@@ -302,4 +408,4 @@ module TTL2HTML
|
|
302
408
|
file
|
303
409
|
end
|
304
410
|
end
|
305
|
-
end
|
411
|
+
end
|
data/locales/en.yml
CHANGED
@@ -3,11 +3,17 @@ en:
|
|
3
3
|
title: "About %{title}"
|
4
4
|
The properties for the textbook resources are as follows:
|
5
5
|
shape-note: "The properties for the %{resource} resources are as follows:"
|
6
|
+
versions: Versions
|
7
|
+
version-release: "Version %{version} released."
|
8
|
+
version-triples: "%{triples} triples"
|
6
9
|
default:
|
7
10
|
details: Details
|
8
11
|
inverse_data: Referred resources
|
9
12
|
index:
|
10
13
|
list: "List of %{resource}"
|
14
|
+
latest-news: "Latest news"
|
15
|
+
past-versions: "Past versions"
|
16
|
+
license-text: "This dataset is freely usable as <a href=\"%{url}\">%{label}</a>"
|
11
17
|
layout:
|
12
18
|
rdf-data: RDF data
|
13
19
|
shape-table:
|
@@ -23,4 +29,6 @@ en:
|
|
23
29
|
optional: "Optional"
|
24
30
|
non-repeatable: "Non repeatable"
|
25
31
|
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:"
|
32
|
+
blank-node-or-structure: "The structural contents of a blank node are either of the followings:"
|
33
|
+
triples:
|
34
|
+
inverse_refered: "Referred to as '%{property}' from:"
|
data/locales/ja.yml
CHANGED
@@ -2,11 +2,17 @@ ja:
|
|
2
2
|
about:
|
3
3
|
title: "%{title}について"
|
4
4
|
shape-note: "%{resource}リソースが持つプロパティを下表に示します"
|
5
|
+
versions: 更新履歴
|
6
|
+
version-release: "バージョン%{version}を公開。"
|
7
|
+
version-triples: "%{triples}トリプル"
|
5
8
|
default:
|
6
9
|
details: 詳細情報
|
7
10
|
inverse_data: 被参照情報
|
8
11
|
index:
|
9
12
|
list: "%{resource} 一覧"
|
13
|
+
latest-news: 最新のお知らせ
|
14
|
+
past-versions: 過去の更新履歴
|
15
|
+
license-text: "このデータセットは<a href=\"%{url}\">%{label}</a>として自由に利用できます。"
|
10
16
|
layout:
|
11
17
|
rdf-data: RDFデータ
|
12
18
|
shape-table:
|
@@ -22,4 +28,6 @@ ja:
|
|
22
28
|
optional: 省略可能
|
23
29
|
non-repeatable: 繰り返し無し
|
24
30
|
blank-node-structure: ブランクノードの内容は以下の内容からなる構造を持ちます。
|
25
|
-
blank-node-or-structure: ブランクノードの内容は以下のいずれかの内容からなる構造を持ちます。
|
31
|
+
blank-node-or-structure: ブランクノードの内容は以下のいずれかの内容からなる構造を持ちます。
|
32
|
+
triples:
|
33
|
+
inverse_refered: "'%{property}'としての参照元:"
|
data/templates/about.html.erb
CHANGED
@@ -1,25 +1,44 @@
|
|
1
1
|
<div class="jumbotron">
|
2
2
|
<div class="container">
|
3
3
|
<h1><%=h t("about.title", title: param[:site_title]) %></h1>
|
4
|
+
<%- if param[:toplevel] and param[:toplevel][:description] -%>
|
5
|
+
<p><%= get_language_literal(param[:toplevel][:description]) %></p>
|
6
|
+
<%- end -%>
|
4
7
|
</div>
|
5
8
|
</div>
|
6
9
|
<div class="container">
|
7
10
|
<div class="row">
|
8
11
|
<div class="col-md-12">
|
9
|
-
<
|
10
|
-
<
|
11
|
-
|
12
|
-
|
12
|
+
<nav aria-label="breadcrumb">
|
13
|
+
<ol class="breadcrumb">
|
14
|
+
<li class="breadcrumb-item"><a href="./"><i class="bi bi-house-door-fill"></i> Home</a></li>
|
15
|
+
<li class="breadcrumb-item active" aria-current="page"><%=h t("about.title", title: param[:site_title]) %></li>
|
16
|
+
</ol>
|
17
|
+
</nav>
|
13
18
|
</div>
|
14
19
|
</div>
|
15
|
-
|
20
|
+
<%- if param[:shapes] -%>
|
16
21
|
<div class="row">
|
17
|
-
<div class="col-md
|
18
|
-
<%- param[:
|
19
|
-
<h3><%=h param[:
|
20
|
-
<p><%= param[:
|
21
|
-
<p><%=h t("about.shape-note", resource: param[:
|
22
|
-
<%= param[:
|
22
|
+
<div class="col-md">
|
23
|
+
<%- param[:shapes].keys.sort.each do |shape| -%>
|
24
|
+
<h3><%=h param[:shapes][shape][:label] %></h3>
|
25
|
+
<p><%= param[:shapes][shape][:comment] %></p>
|
26
|
+
<p><%=h t("about.shape-note", resource: param[:shapes][shape][:label]) %></p>
|
27
|
+
<%= param[:shapes][shape][:html] -%>
|
23
28
|
<%- end -%>
|
24
29
|
</div>
|
25
30
|
</div>
|
31
|
+
<%- end -%>
|
32
|
+
<%- if param[:versions] -%>
|
33
|
+
<div class="row">
|
34
|
+
<div class="col-md">
|
35
|
+
<h2 id="versions"><%=h t("about.versions") %> <i class="bi bi-info-circle"></i></h2>
|
36
|
+
<dl>
|
37
|
+
<%- param[:versions].reverse_each do |version| -%>
|
38
|
+
<%= format_version_info(version) %>
|
39
|
+
<%- end -%>
|
40
|
+
</dl>
|
41
|
+
</div>
|
42
|
+
</div>
|
43
|
+
<%- end -%>
|
44
|
+
</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,10 @@
|
|
1
1
|
<div class="jumbotron">
|
2
2
|
<div class="container">
|
3
3
|
<h1><%=h param[:site_title] %></h1>
|
4
|
-
|
4
|
+
<%- if param[:toplevel] and param[:toplevel][:description] -%>
|
5
|
+
<p><%= get_language_literal(param[:toplevel][:description]) %></p>
|
6
|
+
<%- end -%>
|
7
|
+
<p><i class="bi bi-link-45deg"></i> <a href="<%=h param[:base_uri] %>"><%=h param[:base_uri] %></a></p>
|
5
8
|
</div>
|
6
9
|
</div>
|
7
10
|
<div class="container">
|
@@ -9,10 +12,31 @@
|
|
9
12
|
<div class="col-md-12">
|
10
13
|
<h2><%=h t("index.list", resource: param[:class_label]) %></h2>
|
11
14
|
<ul>
|
12
|
-
|
15
|
+
<%- param[:index_data].each do |e| -%>
|
13
16
|
<li><%= format_object(e, param[:data_global]) %></li>
|
14
|
-
|
17
|
+
<%- end -%>
|
15
18
|
</ul>
|
16
19
|
</div>
|
17
20
|
</div>
|
18
|
-
|
21
|
+
<%- if param[:versions].size > 0 -%>
|
22
|
+
<div class="row">
|
23
|
+
<div class="col-md">
|
24
|
+
<h2 id="versions"><%=h t("index.latest-news") %> <i class="bi bi-info-circle"></i></h2>
|
25
|
+
<dl>
|
26
|
+
<%= format_version_info(param[:versions].last) %>
|
27
|
+
</dl>
|
28
|
+
<%- if param[:versions].size > 1 -%>
|
29
|
+
<p><a href="about#versions">» <%=h t("index.past-versions") %></a></p>
|
30
|
+
<%- end -%>
|
31
|
+
<%- if param[:toplevel] and param[:toplevel][:license] -%>
|
32
|
+
<p>
|
33
|
+
<%- if param[:toplevel][:license][:icon] -%>
|
34
|
+
<a href="<%=h param[:toplevel][:license][:url] %>"><img src="<%=h param[:toplevel][:license][:icon] %>"></a>
|
35
|
+
<%- end -%>
|
36
|
+
<%= t("index.license-text", label: get_language_literal(param[:toplevel][:license][:label]), url: param[:toplevel][:license][:url]) %>
|
37
|
+
</p>
|
38
|
+
<%- end -%>
|
39
|
+
</div>
|
40
|
+
</div>
|
41
|
+
<%- end -%>
|
42
|
+
</div>
|
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.
|
8
|
-
<
|
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">
|
9
|
+
<title><%=h html_title(param) %></title>
|
9
10
|
<meta name="twitter:card" content="summary">
|
10
|
-
<meta name="twitter:title" content="
|
11
|
+
<meta name="twitter:title" content="<%=h html_title(param) %>">
|
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,24 @@
|
|
1
|
-
<dl>
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
+
<%- 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
|
+
<dt class="col-sm-3"><%=h format_property(k, param[:labels]) %></dt>
|
11
|
+
<%- end -%>
|
12
|
+
<%- if v.respond_to? :has_key? -%>
|
13
|
+
<% v.each_with_index do |v2, idx| %>
|
14
|
+
<dd class="col-sm-9<%= ' offset-sm-3' if idx > 0 %>" lang="<%=h v2[0] %>"><%= format_object v2[1], param[:data] %></dd>
|
7
15
|
<% end %>
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
<dd><%= format_object v.first, param[:data] %></dd>
|
14
|
-
|
16
|
+
<%- elsif v.size > 1 -%>
|
17
|
+
<%- 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>
|
19
|
+
<%- end -%>
|
20
|
+
<%- else -%>
|
21
|
+
<dd class="col-sm-9"><%= format_object v.first, param[:data] %></dd>
|
22
|
+
<%- end -%>
|
15
23
|
<%- end -%>
|
16
|
-
</dl>
|
24
|
+
</dl>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<dt><%=h param[:data][:date] %></dt>
|
2
|
+
<dd><%=h t("about.version-release", version: param[:data][:version]) %></dd>
|
3
|
+
<dd><%=h get_language_literal(param[:data][:description]) %></dd>
|
4
|
+
<%- if param[:data][:datadump] -%>
|
5
|
+
<dd><ul>
|
6
|
+
<li><a href="<%=h param[:data][:datadump] %>"><%=h File.basename(param[:data][:datadump]) %></a>
|
7
|
+
<%-
|
8
|
+
fileinfo = []
|
9
|
+
if param[:data][:triples]
|
10
|
+
fileinfo << t("about.version-triples", triples: number_with_delimiter(param[:data][:triples].to_i))
|
11
|
+
end
|
12
|
+
if param[:data][:bytesize]
|
13
|
+
fileinfo << number_to_human_size(param[:data][:bytesize])
|
14
|
+
end
|
15
|
+
-%>
|
16
|
+
<%- if fileinfo.size > 0 -%>
|
17
|
+
(<%=h fileinfo.join(", ") %>)
|
18
|
+
<%- end -%>
|
19
|
+
<%- if param[:data][:subset].size > 0 -%>
|
20
|
+
<ul>
|
21
|
+
<%- param[:data][:subset].each do |subset| -%>
|
22
|
+
<li><a href="<%=h subset %>"><%=h File.basename(subset) %></a></li>
|
23
|
+
<%- end -%>
|
24
|
+
</ul>
|
25
|
+
</li>
|
26
|
+
<%- end -%>
|
27
|
+
</dd>
|
28
|
+
<%- 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: 1.
|
4
|
+
version: 1.3.2
|
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-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: actionview
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: rspec
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -146,6 +160,7 @@ files:
|
|
146
160
|
- templates/layout.html.erb
|
147
161
|
- templates/shape-table.html.erb
|
148
162
|
- templates/triples.html.erb
|
163
|
+
- templates/version.html.erb
|
149
164
|
homepage: https://github.com/masao/ttl2html
|
150
165
|
licenses:
|
151
166
|
- MIT
|
@@ -165,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
180
|
- !ruby/object:Gem::Version
|
166
181
|
version: '0'
|
167
182
|
requirements: []
|
168
|
-
rubygems_version: 3.2.
|
183
|
+
rubygems_version: 3.2.32
|
169
184
|
signing_key:
|
170
185
|
specification_version: 4
|
171
186
|
summary: ttl2html
|