126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
# File 'lib/ttl2html.rb', line 126
def output_html_files
template = Template.new("", @config)
shapes = []
@data.each do |s, v|
if v[RDF.type.to_s] and @data[s][RDF.type.to_s].include?("http://www.w3.org/ns/shacl#NodeShape")
shapes << s
end
end
labels = shapes2labels(shapes)
versions =
toplevel =
@config[:labels_with_class] ||= {}
labels.each do |klass, props|
props.each do |property, label|
@config[:labels_with_class][klass] ||= {}
if @config[:labels_with_class][klass][property]
next
else
@config[:labels_with_class][klass][property] = template.get_language_literal(label)
end
end
end
@config[:orders_with_class] = shapes2orders(shapes)
each_data(:output_html_files) do |uri, v|
template = Template.new("default.html.erb", @config)
param = @config.dup
param[:uri] = uri
param[:turtle_uri] = uri + ".ttl"
param[:data] = v
param[:data_inverse] = @data_inverse[uri]
param[:data_inverse_global] = @data_inverse
param[:data_global] = @data
param[:title] = template.get_title(v)
if param[:breadcrumbs]
param[:breadcrumbs_items] = build_breadcrumbs(uri, template)
end
file = uri_mapping_to_path(uri, @config, ".html")
if @config[:output_dir]
Dir.mkdir @config[:output_dir] if not File.exist? @config[:output_dir]
file = File.join(@config[:output_dir], file)
end
if template.find_template_path("_default.html.erb")
param[:additional_content] = template.to_html_raw("_default.html.erb", param)
end
template.output_to(file, param)
end
index_html = "index.html"
index_html = File.join(@config[:output_dir], "index.html") if @config[:output_dir]
if @config.has_key? :top_class
subjects = []
@data.each do |s, v|
if @data[s][RDF.type.to_s] and @data[s][RDF.type.to_s].include?(@config[:top_class])
subjects << s
end
end
if subjects.empty?
STDERR.puts "WARN: top_class parameter specified as [#{@config[:top_class]}], but there is no instance data."
else
template = Template.new("index.html.erb", @config)
param = @config.dup
param[:class_label] = template.get_title(@data[@config[:top_class]], nil)
param[:data_global] = @data
param[:data_inverse_global] = @data_inverse
param[:versions] = versions
param[:toplevel] = toplevel
subjects.sort.each do |subject|
objects = []
if @config.has_key? :top_additional_property
@config[:top_additional_property].each do |property|
if @data[subject][property]
objects += @data[subject][property]
end
end
end
param[:index_data] ||= []
param[:index_data] << {
subject.to_s => objects
}
end
param[:output_file] = index_html
param[:index_list] = template.to_html_raw("index-list.html.erb", param)
template.output_to(index_html, param)
end
end
if template.find_template_path("about.html") or shapes.size > 0 or versions.size > 0 or toplevel.size > 0
about_html = @config[:about_file] || "about.html"
about_html = File.join(@config[:output_dir], about_html) if @config[:output_dir]
template = Template.new("about.html.erb", @config)
param = @config.dup
param[:content] = template.to_html_raw("about.html", {}) if template.find_template_path("about.html")
param[:data_global] = @data
param[:versions] = versions
param[:toplevel] = toplevel
param[:shapes] = {}
shapes.each do |subject|
orders = []
if param[:shape_orders]
param[:shape_orders].index(subject)
orders << ( param[:shape_orders].index(subject) or Float::INFINITY )
end
orders << subject
label = = nil
target_class = @data[subject.to_s]["http://www.w3.org/ns/shacl#targetClass"]
if target_class
target_class = target_class.first
if @data[target_class]
label = template.get_title(@data[target_class], nil)
= 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"]
else
label = template.format_property(target_class)
end
else
label = template.get_title(@data[subject.to_s])
end
html = template.expand_shape(@data, subject.to_s, @prefix)
next if html.nil?
param[:shapes][subject] = {
label: label,
comment: ,
html: html,
target_class: target_class,
order: orders,
}
end
template.output_to(about_html, param)
end
end
|