ttl2html 2.2.2 → 2.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13f4951cbe8d12cf99dd6563a2facae07c180d8e48bbab595f3cce942cf1da0f
4
- data.tar.gz: 8232fb9eb944019274b5323cf44739ee147b032b60358d8e894a8daa36ab551f
3
+ metadata.gz: 1a699bd6e103ee6b88c617b6421fc7968fc63141c78d2dfff8aa75a64e7f271d
4
+ data.tar.gz: bfc5ccd8c37e16939d1cd1fcb2fe80a6b4902b408d2def30750f10bd71a1b1be
5
5
  SHA512:
6
- metadata.gz: c31c198f569f638e9ab5007f9776cb979144464b6be6e3f21601b07a098559af1b50d97e7eed1e77958c7240eefd3ae49e422bf7f54738a6f957ee868d9f2fd1
7
- data.tar.gz: 8ad682b50a9cd60843d52a503fa7ffbd2a4359553d254c0c7721587d1d371c36cc533da5188c9135b411ec5f0c9c5c12aa2cc23d9bf65b0448e626a264891508
6
+ metadata.gz: 88d8e9f520c749186b33001e4102b711ed75c3f9ee8c0dbcdab5c86896b68ce141d19800aa8fc6307926dfc3f65451d0ee0f674f80052ba606ef7815f32d120e
7
+ data.tar.gz: 2899b38935cc874ca678913830089f514b805ceb0ff55a64fd7cb2cda850a9238ad348b000aceb3be44bfc0bf5482e525050236d409d818eff16ec0b1019a655
data/bin/catttl CHANGED
@@ -1,18 +1,39 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "zlib"
4
+ require "getoptlong"
4
5
  require "ttl2html"
5
6
  include TTL2HTML
6
7
 
7
8
  prefix = {}
8
9
  ttl = []
10
+ noexpand_filenames = false
11
+
12
+ opts = GetoptLong.new(
13
+ ["--no-expand", "-f", GetoptLong::NO_ARGUMENT],
14
+ ["--help", "-h", GetoptLong::NO_ARGUMENT]
15
+ )
16
+
17
+ opts.each do |opt, arg|
18
+ case opt
19
+ when "--no-expand"
20
+ noexpand_filenames = true
21
+ when "--help"
22
+ puts "Usage: catttl [options] [files]"
23
+ puts "Options:"
24
+ puts " -f, --no-expand Do not expand filenames"
25
+ puts " -h, --help Show this help message"
26
+ exit
27
+ end
28
+ end
9
29
 
10
30
  ARGV.each do |file|
11
- filename = find_turtle(file)
31
+ filename = find_turtle(file, noexpand: noexpand_filenames)
12
32
  if filename.nil?
13
33
  STDERR.puts "#{file} not found. skipping."
14
34
  next
15
35
  end
36
+ STDERR.puts filename
16
37
  klass = File
17
38
  if File.extname(filename) == ".gz"
18
39
  klass = Zlib::GzipReader
@@ -29,13 +50,9 @@ ARGV.each do |file|
29
50
  end
30
51
  end
31
52
  end
32
- ARGV.each do |file|
33
- filename = find_turtle(file)
34
- STDERR.puts filename
35
- end
36
53
 
37
54
  prefix.each do |k, v|
38
- STDERR.puts "Duplicate prefixes: #{k}: #{v}" if v.uniq.size > 1
55
+ STDERR.puts "Duplicate prefixes: #{k}: #{v.uniq}" if v.uniq.size > 1
39
56
  prefix[k] = v.sort.first
40
57
  end
41
58
  dups = prefix.values.group_by{|e| e }.select{|k, v| v.size > 1 }.keys
data/bin/ttl2html CHANGED
@@ -36,6 +36,8 @@ ARGV.each do |file|
36
36
  end
37
37
  if opt_cleanup
38
38
  ttl2html.cleanup
39
+ elsif ARGV.empty?
40
+ usage
39
41
  else
40
42
  ttl2html.output_files
41
43
  end
@@ -5,6 +5,7 @@ require "pathname"
5
5
  require "erb"
6
6
  require "i18n"
7
7
  require "action_view"
8
+ require "nokogiri"
8
9
 
9
10
  module TTL2HTML
10
11
  class Template
@@ -107,6 +108,7 @@ module TTL2HTML
107
108
  required: data[property]["http://www.w3.org/ns/shacl#minCount"] ? data[property]["http://www.w3.org/ns/shacl#minCount"].first.to_i > 0 : false,
108
109
  repeatable: repeatable,
109
110
  nodeKind: data[property]["http://www.w3.org/ns/shacl#nodeKind"] ? data[property]["http://www.w3.org/ns/shacl#nodeKind"].first : nil,
111
+ class: data[property]["http://www.w3.org/ns/shacl#class"] ? data[property]["http://www.w3.org/ns/shacl#class"].first : nil,
110
112
  nodes: nodes,
111
113
  node_mode: node_mode,
112
114
  prefix: prefix_used,
@@ -158,9 +160,10 @@ module TTL2HTML
158
160
  end
159
161
  def shorten_title(title, length = 140)
160
162
  if title.to_s.length > length
161
- title.to_s[0..length] + "..."
163
+ short_title = Nokogiri::HTML::DocumentFragment.parse(title.to_s[0..length])
164
+ short_title.to_html + "..."
162
165
  else
163
- title
166
+ ERB::Util.html_escape title
164
167
  end
165
168
  end
166
169
  def get_title(data, default_title = "no title")
@@ -208,7 +211,7 @@ module TTL2HTML
208
211
  if /\Ahttps?:\/\// =~ object.to_s
209
212
  rel_path = relative_path_uri(object, param[:base_uri])
210
213
  if param[:data_global][object]
211
- result = "<a href=\"#{rel_path}\">#{get_title(param[:data_global][object]) or object}</a>"
214
+ result = "<a href=\"#{rel_path}\">#{get_title(param[:data_global][object]) or ERB::Util.html_escape(object)}</a>"
212
215
  subtitle = get_subtitle(param[:data_global][object])
213
216
  if subtitle
214
217
  result += " <small>#{subtitle}</small>"
@@ -216,7 +219,7 @@ module TTL2HTML
216
219
  result
217
220
  end
218
221
  else
219
- "<a href=\"#{rel_path}\">#{object}</a>"
222
+ "<a href=\"#{rel_path}\">#{ERB::Util.html_escape object}</a>"
220
223
  end
221
224
  elsif /\A_:/ =~ object.to_s and param[:data_global][object]
222
225
  if type[:inverse] and param[:data_inverse_global][object]
@@ -225,7 +228,7 @@ module TTL2HTML
225
228
  format_triples(param[:data_global][object], blank: true)
226
229
  end
227
230
  else
228
- object
231
+ ERB::Util.html_escape object
229
232
  end
230
233
  end
231
234
  def format_triples(triples, type = {})
@@ -1 +1 @@
1
- TTL2HTML::VERSION = "2.2.2"
1
+ TTL2HTML::VERSION = "2.3.1"
data/lib/ttl2html.rb CHANGED
@@ -82,6 +82,7 @@ module TTL2HTML
82
82
  end
83
83
  result << @data[subject.to_s].keys.sort.map do |predicate|
84
84
  str = "<#{predicate}> "
85
+ #p [subject, predicate, @data[subject.to_s][predicate]]
85
86
  str << @data[subject.to_s][predicate].sort_by do |object|
86
87
  #p [subject, predicate, object, depth]
87
88
  if object.to_s =~ /^_:/ and @data[object.to_s]
@@ -94,7 +95,7 @@ module TTL2HTML
94
95
  format_turtle(object, depth + 1)
95
96
  ]
96
97
  else
97
- object.to_s
98
+ [Float::INFINITY, Float::INFINITY, Float::INFINITY, object.to_s]
98
99
  end
99
100
  end.map do |object|
100
101
  if /^_:/ =~ object.to_s # blank node:
@@ -208,6 +209,7 @@ module TTL2HTML
208
209
  template = Template.new("index.html.erb", @config)
209
210
  param = @config.dup
210
211
  param[:class_label] = template.get_title(@data[@config[:top_class]], nil)
212
+ param[:class_label] ||= @config[:top_class].split(/[\/\#]/).last.capitalize
211
213
  param[:data_global] = @data
212
214
  param[:data_inverse_global] = @data_inverse
213
215
  param[:versions] = versions
@@ -485,12 +487,21 @@ module TTL2HTML
485
487
  if data["http://rdfs.org/ns/void#sparqlEndpoint"]
486
488
  endpoint = data["http://rdfs.org/ns/void#sparqlEndpoint"].first
487
489
  end
490
+ if data["http://www.w3.org/ns/dcat#accessService"]
491
+ service = data["http://www.w3.org/ns/dcat#accessService"].first
492
+ service_data = @data[service]
493
+ if service_data
494
+ endpoint = service_data["http://www.w3.org/ns/dcat#endpointURL"]&.first
495
+ endpoint_landingpage = service_data["http://www.w3.org/ns/dcat#landingPage"]&.first
496
+ end
497
+ end
488
498
  result = {
489
499
  uri: toplevel.to_s,
490
500
  description: data["http://purl.org/dc/terms/description"],
491
501
  license: license,
492
502
  contact: contact,
493
503
  endpoint: endpoint,
504
+ endpoint_landingpage: endpoint_landingpage,
494
505
  derivedfrom: derivedfrom,
495
506
  }
496
507
  end
@@ -546,7 +557,11 @@ module TTL2HTML
546
557
 
547
558
  def find_turtle(filename, params = {})
548
559
  if params[:noexpand] == true
549
- filename if File.exists? filename
560
+ if File.exist? filename
561
+ filename
562
+ else
563
+ nil
564
+ end
550
565
  else
551
566
  file = nil
552
567
  basename = File.basename(filename, ".ttl")
data/locales/en.yml CHANGED
@@ -23,7 +23,8 @@ en:
23
23
  past-versions: "Past versions"
24
24
  license-text: "This dataset is freely usable as <a href=\"%{url}\">%{label}</a>."
25
25
  sparql-endpoint: "SPARQL Endpoint"
26
- sparql-endpoint-text: "The SPARQL endpoint for the dataset is available at"
26
+ sparql-endpoint-text: "The SPARQL endpoint for the dataset is available at:"
27
+ sparql-endpoint-landingpage: "Search page"
27
28
  dataset:
28
29
  derivedfrom-text: "This dataset is created by editing <a href=\"%{url}\">\"%{label}\"</a>."
29
30
  license-text: "This dataset is freely usable as <a href=\"%{url}\">%{label}</a>."
data/locales/ja.yml CHANGED
@@ -23,7 +23,8 @@ ja:
23
23
  past-versions: 過去の更新履歴
24
24
  license-text: "このデータセットは<a href=\"%{url}\">%{label}</a>として自由に利用できます。"
25
25
  sparql-endpoint: "SPARQLエンドポイント"
26
- sparql-endpoint-text: "このデータセットに対するSPARQLエンドポイントは以下のURLからアクセスできます"
26
+ sparql-endpoint-text: "このデータセットに対するSPARQLエンドポイントは以下のURLからアクセスできます:"
27
+ sparql-endpoint-landingpage: "クエリ画面"
27
28
  dataset:
28
29
  derivedfrom-text: "このデータセットは<a href=\"%{url}\">「%{label}」</a>を加工して作成。"
29
30
  license-text: "<a href=\"%{url}\">%{label}</a>として自由に利用できます。"
@@ -55,9 +55,13 @@
55
55
  <%- end -%>
56
56
  <%- if param[:toplevel][:endpoint] -%>
57
57
  <h2 id="sparql-endpoint"><%=h t("index.sparql-endpoint") %> <i class="bi bi-database-add"></i></h2>
58
- <p>
59
- <%= t("index.sparql-endpoint-text") %>: <a href="<%=h param[:toplevel][:endpoint] %>"><%=h param[:toplevel][:endpoint] %></a>
60
- </p>
58
+ <p><%= t("index.sparql-endpoint-text") %></p>
59
+ <ul>
60
+ <%- if param[:toplevel][:endpoint_landingpage] -%>
61
+ <li><%= t("index.sparql-endpoint-landingpage") %>: <a href="<%=h param[:toplevel][:endpoint_landingpage] %>"><%=h param[:toplevel][:endpoint_landingpage] %></a></li>
62
+ <%- end -%>
63
+ <li><%= t("index.sparql-endpoint") %>: <a href="<%=h param[:toplevel][:endpoint] %>"><%=h param[:toplevel][:endpoint] %></a></li>
64
+ </ul>
61
65
  <%- end -%>
62
66
  <%- if param[:toplevel] and param[:toplevel][:contact] -%>
63
67
  <h2 id="contact"><%=h t("about.contact") %></h2>
@@ -1,8 +1,8 @@
1
1
  <div class="jumbotron">
2
2
  <div class="container">
3
- <h1><%=h param[:title] %></h1>
3
+ <h1><%= param[:title] %></h1>
4
4
  <%- if param[:subtitle] -%>
5
- <p class="lead"><%=h param[:subtitle] %></p>
5
+ <p class="lead"><%= param[:subtitle] %></p>
6
6
  <%- end -%>
7
7
  <p><i class="bi bi-link-45deg"></i> <a href="<%=h param[:uri] %>"><%=h param[:uri] %></a></p>
8
8
  </div>
@@ -40,11 +40,19 @@
40
40
  <%- end -%>
41
41
  </div>
42
42
  </div>
43
- <div class="col-md">
44
- <h2 id="sparql-endpoint"><%=h t("index.sparql-endpoint") %> <i class="bi bi-database-add"></i></h2>
45
- <p>
46
- <%= t("index.sparql-endpoint-text") %>: <a href="<%=h param[:toplevel][:endpoint] %>"><%=h param[:toplevel][:endpoint] %></a>
47
- </p>
43
+ <%- end -%>
44
+ <%- if param[:toplevel][:endpoint] -%>
45
+ <div class="row">
46
+ <div class="col-md">
47
+ <h2 id="sparql-endpoint"><%=h t("index.sparql-endpoint") %> <i class="bi bi-database-add"></i></h2>
48
+ <p><%= t("index.sparql-endpoint-text") %></p>
49
+ <ul>
50
+ <%- if param[:toplevel][:endpoint_landingpage] -%>
51
+ <li><%= t("index.sparql-endpoint-landingpage") %>: <a href="<%=h param[:toplevel][:endpoint_landingpage] %>"><%=h param[:toplevel][:endpoint_landingpage] %></a></li>
52
+ <%- end -%>
53
+ <li><%= t("index.sparql-endpoint") %>: <a href="<%=h param[:toplevel][:endpoint] %>"><%=h param[:toplevel][:endpoint] %></a></li>
54
+ </ul>
55
+ </div>
48
56
  </div>
49
57
  <%- end -%>
50
58
  </div>
@@ -14,10 +14,10 @@
14
14
  <%- if param[:custom_css] -%>
15
15
  <style type="text/css"><%=h param[:custom_css] %></style>
16
16
  <%- end -%>
17
- <title><%=h html_title(param) %></title>
17
+ <title><%= html_title(param) %></title>
18
18
  <meta name="twitter:card" content="summary">
19
- <meta name="twitter:title" content="<%=h html_title(param) %>">
20
- <meta property="og:title" content="<%=h html_title(param) %>">
19
+ <meta name="twitter:title" content="<%= html_title(param) %>">
20
+ <meta property="og:title" content="<%= html_title(param) %>">
21
21
  <%- if param[:ogp] and param[:ogp]["type"] -%>
22
22
  <meta property="og:type" content="<%=h param[:ogp]["type"] %>">
23
23
  <%- else -%>
@@ -18,7 +18,7 @@
18
18
  <td class="url"><code><%=h property[:shorten_path] %></code></td>
19
19
  <%- end -%>
20
20
  <td><%= property[:name] %></td>
21
- <%- if property[:nodeKind] == "http://www.w3.org/ns/shacl#IRI" -%>
21
+ <%- if property[:nodeKind] == "http://www.w3.org/ns/shacl#IRI" or property[:class] -%>
22
22
  <td class="url"><%= property[:example] %></td>
23
23
  <%- else -%>
24
24
  <td><%= property[:example] %></td>
@@ -1,4 +1,9 @@
1
- <dl class="row<%= if param[:type][:blank] then ' border' end %>">
1
+ <%- itemtypes = param[:data][RDF.type.to_s].to_a.join(" ") -%>
2
+ <%- if param[:type][:blank] -%>
3
+ <dl class="row<%= if param[:type][:blank] then ' border' end %>" itemscope<% unless itemtypes.empty? %> itemtype="<%=h itemtypes %>"<% end %>>
4
+ <%- else -%>
5
+ <dl class="row<%= if param[:type][:blank] then ' border' end %>" itemscope itemid="<%=h param[:uri] %>"<% unless itemtypes.empty? %> itemtype="<%=h itemtypes %>"<% end %>>
6
+ <%- end -%>
2
7
  <%- param[:data].sort_by{|k, v|
3
8
  order = param[:orders][k] if param[:orders] and param[:orders][k]
4
9
  order = Float::INFINITY if order.nil?
@@ -7,9 +12,12 @@
7
12
  <dt class="col-sm-3"><%=h format_property(k, param[:labels]) %></dt>
8
13
  <%- v.sort_by{|e| sort_criteria(e, param[:data_global]) }.each_with_index do |v2, idx| -%>
9
14
  <%- if v2.respond_to? :language and v2.language? -%>
10
- <dd class="col-sm-9<%= ' offset-sm-3' if idx > 0 %>" lang="<%=h v2.language %>"><%= format_object v2, param[:data], param[:type] %></dd>
15
+ <dd class="col-sm-9<%= ' offset-sm-3' if idx > 0 %>" lang="<%=h v2.language %>" itemprop="<%=h k %>"><%= format_object v2, param[:data], param[:type] %></dd>
16
+ <%- elsif /\Ahttps?:\/\// =~ v2.to_s -%>
17
+ <%- itemtypes = param[:data_global][v2.to_s] ? param[:data_global][v2.to_s][RDF.type.to_s].to_a.join(" ") : "" -%>
18
+ <dd class="col-sm-9<%= ' offset-sm-3' if idx > 0 %>" itemscope itemprop="<%=h k %>" itemid="<%=h v2.to_s %>"<% unless itemtypes.empty? %> itemtype="<%=h itemtypes %>"<% end %>><%= format_object v2, param[:data], param[:type] %></dd>
11
19
  <%- else -%>
12
- <dd class="col-sm-9<%= ' offset-sm-3' if idx > 0 %>"><%= format_object v2, param[:data], param[:type] %></dd>
20
+ <dd class="col-sm-9<%= ' offset-sm-3' if idx > 0 %>" itemprop="<%=h k %>"><%= format_object v2, param[:data], param[:type] %></dd>
13
21
  <%- end -%>
14
22
  <%- end -%>
15
23
  <%- end -%>
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.2.2
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masao Takaku
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-09-11 00:00:00.000000000 Z
10
+ date: 2026-01-24 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: nokogiri
@@ -180,9 +180,9 @@ dependencies:
180
180
  description: Static site generator for RDF/Turtle
181
181
  email: tmasao@acm.org
182
182
  executables:
183
+ - catttl
183
184
  - ttl2html
184
185
  - xlsx2shape
185
- - catttl
186
186
  extensions: []
187
187
  extra_rdoc_files: []
188
188
  files:
@@ -225,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
225
  - !ruby/object:Gem::Version
226
226
  version: '0'
227
227
  requirements: []
228
- rubygems_version: 3.6.2
228
+ rubygems_version: 4.0.3
229
229
  specification_version: 4
230
230
  summary: ttl2html
231
231
  test_files: []