ttl2html 2.2.2 → 2.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13f4951cbe8d12cf99dd6563a2facae07c180d8e48bbab595f3cce942cf1da0f
4
- data.tar.gz: 8232fb9eb944019274b5323cf44739ee147b032b60358d8e894a8daa36ab551f
3
+ metadata.gz: 946f8e7de3a456635e40617b88ce014dcd7b54442557ded55a51ca3ad6dfb5b1
4
+ data.tar.gz: 4bbb58d451d13e71f84c2bd1efe9ca897b695691768337ebb45d97c19badbcfa
5
5
  SHA512:
6
- metadata.gz: c31c198f569f638e9ab5007f9776cb979144464b6be6e3f21601b07a098559af1b50d97e7eed1e77958c7240eefd3ae49e422bf7f54738a6f957ee868d9f2fd1
7
- data.tar.gz: 8ad682b50a9cd60843d52a503fa7ffbd2a4359553d254c0c7721587d1d371c36cc533da5188c9135b411ec5f0c9c5c12aa2cc23d9bf65b0448e626a264891508
6
+ metadata.gz: 0db603f9cd36379e948f3a5a30e65db301af01d8df0a98c59dffcdc125934a8f006af140fb318d439466020ac1a4f7cebc2987f7ab06b49f3724431b1541f2d3
7
+ data.tar.gz: 51516e8a7b73c4260ad5d7f23a440462dda00c8300ace92bf567a955b14386981f38ed427d27a9e707873c5c83699beac709aa61aa9a81a7b53ca9167a819ebb
@@ -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.0"
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:
@@ -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>
@@ -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,8 @@
1
- <dl class="row<%= if param[:type][:blank] then ' border' end %>">
1
+ <%- if param[:type][:blank] -%>
2
+ <dl class="row<%= if param[:type][:blank] then ' border' end %>" itemscope>
3
+ <%- else -%>
4
+ <dl class="row<%= if param[:type][:blank] then ' border' end %>" itemscope itemid="<%=h param[:uri] %>">
5
+ <%- end -%>
2
6
  <%- param[:data].sort_by{|k, v|
3
7
  order = param[:orders][k] if param[:orders] and param[:orders][k]
4
8
  order = Float::INFINITY if order.nil?
@@ -7,9 +11,11 @@
7
11
  <dt class="col-sm-3"><%=h format_property(k, param[:labels]) %></dt>
8
12
  <%- v.sort_by{|e| sort_criteria(e, param[:data_global]) }.each_with_index do |v2, idx| -%>
9
13
  <%- 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>
14
+ <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>
15
+ <%- elsif /\Ahttps?:\/\// =~ v2.to_s -%>
16
+ <dd class="col-sm-9<%= ' offset-sm-3' if idx > 0 %>" itemscope itemprop="<%=h k %>" itemid="<%=h v2.to_s %>"><%= format_object v2, param[:data], param[:type] %></dd>
11
17
  <%- else -%>
12
- <dd class="col-sm-9<%= ' offset-sm-3' if idx > 0 %>"><%= format_object v2, param[:data], param[:type] %></dd>
18
+ <dd class="col-sm-9<%= ' offset-sm-3' if idx > 0 %>" itemprop="<%=h k %>"><%= format_object v2, param[:data], param[:type] %></dd>
13
19
  <%- end -%>
14
20
  <%- end -%>
15
21
  <%- 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.0
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: 2025-12-22 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: nokogiri