-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.rb
351 lines (294 loc) · 10.6 KB
/
config.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
###
# Compass
###
# Change Compass configuration
# compass_config do |config|
# config.output_style = :compact
# end
###
# Page options, layouts, aliases and proxies
###
# Per-page layout changes:
#
# With no layout
# page "/path/to/file.html", :layout => false
#
# With alternative layout
# page "/path/to/file.html", :layout => :otherlayout
#
# A path which all have the same layout
# with_layout :admin do
# page "/admin/*"
# end
###
# Helpers
###
# Automatic image dimensions on image_tag helper
# activate :automatic_image_sizes
# Reload the browser automatically whenever files change
configure :development do
activate :livereload
end
# Methods defined in the helpers block are available in templates
# helpers do
# def some_helper
# "Helping"
# end
# end
require 'reformat_examples'
require 'construct_context'
require 'scoped_context'
$dmwg_examples = DMWGExampleData.new('data/flattened')
# build raw json versions of the examples
$dmwg_examples.data_by_id.each do |k,v|
v_with_context = v.merge({'@context' => 'http://dataexchange.clinicalgenome.org/interpretation/json/context'})
proxy "/json/#{k}", "/templates/entity.json",
:locals => { :object => v_with_context },
:ignore => true, :layout => false, :directory_indexes => true
end
# generating entity pages
$dmwg_examples.types_by_entity_id.each do |e_id, type|
proxy "/entities/#{type['name']}.html", 'templates/entity.html',
:locals => { :entity_id => e_id, :vs => nil? },
:layout => "layout.erb",
:ignore => true,
:directory_indexes => true
end
# generating value set pages
$dmwg_examples.data_by_entity_type['ValueSet'].each do |vs|
proxy "/terminologies/#{vs['label'].delete(' ')}.html", 'templates/valueset.html',
:locals => { :entity_id => nil, :vs => vs },
:layout => "layout.erb", :ignore => true, :directory_indexes => true
end
# generates Types.json file
proxy "/json/Types", "/templates/entity.json",
:locals => { :object => $dmwg_examples.types_by_entity_id },
:ignore => true, :layout => false, :directory_indexes => true
# generates the json-ld context (v1.0 context)
proxy "/json/context", "/templates/entity.json",
:locals => { :object => construct_context() },
:ignore => true, :layout => false, :directory_indexes => true
# generates the json-ld SEPIO version of context (v1.0 sepio context)
proxy "/json/sepio_context", "/templates/entity.json",
:locals => { :object => construct_context('sepio') },
:ignore => true, :layout => false, :directory_indexes => true
# generates the json-ld context (v1.1 scoped context)
proxy "/json/scoped_context", "/templates/entity.json",
:locals => { :object => construct_scoped_context() },
:ignore => true, :layout => false, :directory_indexes => true
ignore "/templates/"
ignore "/json/" # not sure why this has to be here, but may work around a middleman bug...
after_build do |builder|
FileUtils.cp_r 'json/.', 'build/json'
end
helpers do
# Generate a link to a specific resource with text based on title
def link_to_resource(resource)
if (resource.data.id == nil)
link_to(resource.data.title, resource)
else
link_to(data.flattened.Type[resource.data.id].name, resource)
end
end
# Return the path one level above the current path
def parent_path(path)
path.chomp('/')[/(.*\/).*$/, 1]
end
def path_depth(path)
path.chomp('/').count('/')
end
def model_link(model)
# %(<li class="#{model}"><a href="/#{model}"><span class="glyphicon #{data.models[model].icon}"></span>#{model.capitalize}</a></li>)
resource = sitemap.find_resource_by_path("#{model}/index.html")
link = link_to("/#{model}") do
%(<span class="glyphicon #{data.models[model].icon}"></span> #{model.capitalize} Model)
end
%(<li class="#{model}">#{link}</li>)
end
def example_table_item(data)
if data.nil?
return ''
end
output = ''
if !data.kind_of?(Array)
data = [data]
end
data.each do |item|
if (item.kind_of?(Hash) && item['id'])
output << %(<p>#{link_to item['id'], "/entities/details/details.html", :fragment => item['id'], :relative => true}</p>)
if item['label']
output << " (#{item['label']})"
end
else
output << %(<p>#{item}</p>)
end
end
output
end
def breadcrumb(page)
li = ""
li = "<li>#{link_to(page.data.title, page)}</li>\n" if page.data.title
li = breadcrumb(page.parent) + li if page.parent
li
end
def expanded_link_with_local_index(text, path)
#resource = sitemap.find_resource_by_path("#{model}/discussion/index.html")
resource = sitemap.find_resource_by_path("#{path}/index.html")
# Count the child folders
if (path_depth(current_page.url) == 1 ||
current_page.url.include?('/#{path}/'))
index = child_index(path)
%(<li class="active">#{link_to(text, resource)}</li>#{index})
# elsif current_page.url.include?('/discussion/')
# link_with_local_index(text,path)
else
"<li>#{link_to(text, resource)}</li>#{index}"
end
end
# This is a special case needed because of bugs in the link_to method
# when using relative links (also because were playing games with the
# links from the discusison page
def child_index(path)
resource = sitemap.find_resource_by_path("#{path}/index.html")
return "" if resource.children.size == 0
resource.children.each { |e| "<li>#{link_to e.data.id, e.url}</li>" }
index = resource.children.reduce("") { |a, e| a + "<li>#{link_to e.data.title, e.url}</li>" }
"<ul>#{index}</ul>"
end
# Root links in left navbar. Expand (accordion style)
# based on selected page
def link_with_local_index(text, path)
resource = sitemap.find_resource_by_path(path)
# "<li> #{path} </li>"
output = link_to(text, resource)
if resource && current_page.url.include?(resource.url)
index = local_index(current_page.url)
%(<li class="list-group-item"><h5>#{output}</h5>#{index}</li>)
else
"<li class='list-group-item'><h5>#{output}</h5></li>"
end
end
def local_index(path)
index = ""
index = list_children(path) unless current_page.data.skip_children
unless current_page.data.skip_siblings
index = list_siblings(path, index) if path_depth(path) > 1
end
index = list_parents(path, index) if path_depth(path) > 2
index
end
def list_parents(path, nested_index = "")
parent_path = parent_path(path)
index = list_siblings(parent_path, nested_index)
index = list_parents(parent_path, index) if path_depth(parent_path) > 2
index
end
def list_siblings(path, nested_index = "")
sibling_path = parent_path(path)
depth = path_depth(path)
siblings = sitemap.resources.select do |r|
r.url.include?(sibling_path) && path_depth(r.url) == depth
end.sort_by { |r| r.path }
list = siblings.reduce("") do |a, e|
if current_page.url.include?(e.url)
a << %(<li class="active">#{link_to_resource(e)}</li>#{nested_index})
else
a << "<li>#{link_to_resource(e)}</li>"
end
end
"<ul class='list-unstyled'>#{list}</ul>"
end
# Generate nested list of current element's children
def list_children(parent_url)
depth = path_depth(parent_url)
children = sitemap.resources.select do |r|
r.url.include?(parent_url) && path_depth(r.url) == depth + 1
end.sort_by { |r| r.path }
return "" if children.size == 0
list = children.reduce("") do |a, e|
a << "<li>#{link_to_resource(e)}</li>\n"
end
"<ul class='list-unstyled'>#{list}</ul>"
end
def model_name
current_page.data.model ? current_page.data.model.capitalize : ""
end
def brief_index(path)
output = sitemap.resources.select{|r| r.url.include?(path) && path != r.url }.sort_by{ |r| r.path}.reduce("<ul>\n") do |acc, r|
acc + "<li>#{link_to r.data.title, r.url}</li>\n"
end
return output + "</ul>\n"
end
def attributes_by_entity(entityId)
$dmwg_examples.attributes_by_entity_id[entityId]
.select { |i| i['entityId'] == entityId }
.collect { |i| i.merge({'defined_in' => $dmwg_examples.types_by_entity_id[i['entityId']]['name']})}
end
def inherited_attributes_by_entity(entityId)
$dmwg_examples.attributes_by_entity_id[entityId]
.select { |i| i['entityId'] != entityId }
.collect { |i| i.merge({'defined_in' => $dmwg_examples.types_by_entity_id[i['entityId']]['name']})}
end
def examples_by_type(type)
type_name = data.flattened.Type[type]['name']
$dmwg_examples.data_by_entity_type[type_name]
end
def types_by_concepts()
types = $dmwg_examples.types_by_entity_id.values
# .map { |k, v| [k, v.group_by{ |x| x['level2'] }] } # gives the entire object
types.group_by { |x| x['level1'] }
.map { |k, v| [k || "", v.group_by{ |x| x['level2'] }.map { |k2, v2| [k2 || "", v2.collect { |e| e['name'] }] }] } # gives just the name
.to_h
end
def value_sets()
$dmwg_examples.data_by_entity_type['ValueSet']
end
def identifier_systems()
$dmwg_examples.data_by_entity_type['IdentifierSystem']
end
def types_by_entity_id()
$dmwg_examples.types_by_entity_id
end
def type_list_by_hierarchy()
def list_with_children(item)
output = "#{link_to item['name'], '/entities/' + item['name'] + '.html'}"
if not item['children'].empty?
output << "<ul>"
item['children'].sort_by { |e| e['name'] }.each { |child| output << "<li>#{list_with_children(child)}</li>" }
output << "</ul>"
end
output
end
# clone the values, since 'children' attribute will be added
types = $dmwg_examples.types_by_entity_id.map { |k, v| [k, v.clone.merge!({ "children" => [] })] }.to_h
types.values.select { |e| not e['parentType'].nil? }.each { |e| types[e['parentType']]['children'] << e }
output = "<ul>"
types.values.select { |e| e['parentType'].nil? }.sort_by { |e| e['name'] }.each do |top_level|
output << "<li>#{list_with_children(top_level)}</li>"
end
output << "</ul>"
output
end
def render_markdown(content)
Tilt['markdown'].new { content }.render
end
end
set :css_dir, 'stylesheets'
set :js_dir, 'javascripts'
set :images_dir, 'images'
# run get_examples.rb script to download latest snapshot.
### Additonal custom configuration
set :relative_links, true
# Build-specific configuration
configure :build do
# For example, change the Compass output style for deployment
# activate :minify_css
# Minify Javascript on build
# activate :minify_javascript
# Enable cache buster
# activate :asset_hash
# Use relative URLs
activate :relative_assets
# Or use a different image path
# set :http_prefix, "/Content/images/"
end