dsm-portfolio-plugin 0.1.1 → 1.0.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 +4 -4
- data/lib/dsm-portfolio-plugin.rb +180 -17
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e052e5801e7aca121bfc03139b143f1d6046d24
|
4
|
+
data.tar.gz: 935b8a0d017d6e1544525ae546388f6e45b26985
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c792cb7e60c200d185556e3ac5d22eae0f8b82eb3abdb08fe2a48bdee44fecba19425287394fb57ce20e6e6d5f7d3f36bc4a16231eb825566c62c28c0a5fc21f
|
7
|
+
data.tar.gz: d239dbb1751ca4d6781a062e59c4b341946a0f6a34edc399852623201039d8da82dde266cfcc8cdaa0b98853f88aba220f5d93e88645c10bbf04beb851730d78
|
data/lib/dsm-portfolio-plugin.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# TODO: Comment!
|
2
1
|
module Jekyll
|
3
2
|
# Define custom commands.
|
4
3
|
module Commands
|
@@ -99,6 +98,7 @@ module Jekyll
|
|
99
98
|
|
100
99
|
if !file.data['project_code'].nil?
|
101
100
|
projectCode = file.data['project_code']
|
101
|
+
end
|
102
102
|
|
103
103
|
projectUrls[file.data['type']] = file.url
|
104
104
|
end
|
@@ -166,6 +166,11 @@ module Jekyll
|
|
166
166
|
end
|
167
167
|
|
168
168
|
def render(context)
|
169
|
+
# Edge case - work around to prevent excerpt rendering from producing extra page meta.
|
170
|
+
if caller.any? { |trace| trace.include? 'jekyll/excerpt' }
|
171
|
+
return
|
172
|
+
end
|
173
|
+
|
169
174
|
# Check for existence of vignette iterations.
|
170
175
|
if !context['page']['vignettes']
|
171
176
|
context['page']['vignettes'] = []
|
@@ -202,32 +207,190 @@ module Jekyll
|
|
202
207
|
|
203
208
|
module Filters
|
204
209
|
module ApiFilter
|
205
|
-
def
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
210
|
+
def include_fields_from_document(input, fields)
|
211
|
+
filter_fields_from_document(input, fields, false)
|
212
|
+
end
|
213
|
+
|
214
|
+
def strip_fields_from_document(input, fields)
|
215
|
+
filter_fields_from_document(input, fields, true)
|
216
|
+
end
|
217
|
+
|
218
|
+
def filter_fields_from_document(input, fields, exclude)
|
219
|
+
downcased_fields = fields
|
220
|
+
.split(",")
|
221
|
+
.map { |field| field.strip.downcase }
|
222
|
+
|
223
|
+
temp = {}
|
224
|
+
|
225
|
+
input.map do |entry|
|
226
|
+
if exclude
|
227
|
+
if !downcased_fields.include?(entry.downcase)
|
228
|
+
temp[entry] = input[entry]
|
229
|
+
end
|
230
|
+
else
|
231
|
+
if downcased_fields.include?(entry.downcase)
|
232
|
+
temp[entry] = input[entry]
|
233
|
+
end
|
234
|
+
end
|
218
235
|
end
|
219
|
-
|
220
|
-
|
236
|
+
|
237
|
+
temp
|
238
|
+
end
|
239
|
+
|
240
|
+
def include_fields(input, fields)
|
241
|
+
filter_fields(input, fields, false)
|
242
|
+
end
|
243
|
+
|
244
|
+
def strip_fields(input, fields)
|
245
|
+
filter_fields(input, fields, true)
|
246
|
+
end
|
247
|
+
|
248
|
+
def filter_fields(input, fields, exclude)
|
221
249
|
downcased_fields = fields
|
222
250
|
.split(",")
|
223
251
|
.map { |field| field.strip.downcase }
|
224
252
|
|
225
253
|
input.map do |entry|
|
254
|
+
puts entry.inspect
|
226
255
|
entry.select do |key, value|
|
227
|
-
|
256
|
+
if exclude
|
257
|
+
!downcased_fields.include?(key.downcase)
|
258
|
+
else
|
259
|
+
downcased_fields.include?(key.downcase)
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
def wrap_with_key(input, key)
|
266
|
+
{
|
267
|
+
key => input,
|
268
|
+
:status => "OK",
|
269
|
+
:last_updated => Date.today
|
270
|
+
}
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
class GeneratedPage < Page
|
276
|
+
def initialize(site, base, dir, name, template, data=nil)
|
277
|
+
@site = site
|
278
|
+
@base = base
|
279
|
+
@dir = dir
|
280
|
+
@name = name
|
281
|
+
|
282
|
+
self.process(@name)
|
283
|
+
self.read_yaml(template, @name)
|
284
|
+
|
285
|
+
if data
|
286
|
+
self.data["payload"] = data
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
class PageGenerator < Generator
|
292
|
+
priority :normal
|
293
|
+
|
294
|
+
def generate(site)
|
295
|
+
pagesToGenerate = Dir.glob(File.join(site.source, '_layouts/generate/**/*.*'))
|
296
|
+
generateBasePath = File.join(site.source, '_layouts/generate')
|
297
|
+
|
298
|
+
pagesToGenerate.each do |filePath|
|
299
|
+
basename = File.basename(filePath)
|
300
|
+
outDirectory = filePath.sub(generateBasePath, '').sub(basename, '')
|
301
|
+
|
302
|
+
data = {}
|
303
|
+
|
304
|
+
# If there is a specific payload that needs to be sent...
|
305
|
+
if basename == "progression.json" || basename == "progression.html"
|
306
|
+
data = build_progression_payload(site)
|
307
|
+
end
|
308
|
+
|
309
|
+
site.pages << GeneratedPage.new(
|
310
|
+
site,
|
311
|
+
site.source,
|
312
|
+
outDirectory,
|
313
|
+
basename,
|
314
|
+
filePath.sub(basename, ''),
|
315
|
+
data
|
316
|
+
)
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
def build_progression_payload(site)
|
321
|
+
categories = site.data['competencies'].group_by {|c| c['categories'][0]}
|
322
|
+
num_competencies = site.data['competencies'].size
|
323
|
+
|
324
|
+
a_projects = site.data['projects']
|
325
|
+
u_vignettes = site.posts.docs.select {|p| p['type'] == 'vignette'}
|
326
|
+
|
327
|
+
project_rows = []
|
328
|
+
|
329
|
+
for a_project in a_projects
|
330
|
+
project_row = {}
|
331
|
+
|
332
|
+
# Set project meta.
|
333
|
+
project_row['projectId'] = a_project['id']
|
334
|
+
project_row['projectTitle'] = a_project['title']
|
335
|
+
project_row['deadline'] = a_project['deadline']
|
336
|
+
|
337
|
+
# Find related user-submitted post.
|
338
|
+
linked_vignettes = u_vignettes.select {|v| v.data['project_code'] == a_project['id']}
|
339
|
+
project_row['submitted'] = linked_vignettes.size > 0
|
340
|
+
|
341
|
+
# There should only be one...
|
342
|
+
vignette = linked_vignettes[0]
|
343
|
+
|
344
|
+
if project_row['submitted']
|
345
|
+
# Generators run before 'render', so it is necessary to
|
346
|
+
# render this document early to access meta-information
|
347
|
+
# computed from tags during.
|
348
|
+
Jekyll::Renderer.new(site, vignette, site.site_payload).run
|
349
|
+
# It now has 'data' Hash.
|
350
|
+
end
|
351
|
+
|
352
|
+
# Compute values for each competency.
|
353
|
+
project_row['competencies'] = []
|
354
|
+
|
355
|
+
num_targets_met = 0
|
356
|
+
|
357
|
+
# Iterate over competencies.
|
358
|
+
for category in categories
|
359
|
+
for competency in category[1]
|
360
|
+
computed_competency = {}
|
361
|
+
|
362
|
+
computed_competency['competencyId'] = competency['id']
|
363
|
+
|
364
|
+
# Find out if it was a target of the project.
|
365
|
+
computed_competency['target'] = a_project['targets'].include? competency['id']
|
366
|
+
|
367
|
+
# Find out if it was included in the user's final vignette iteration.
|
368
|
+
if project_row['submitted']
|
369
|
+
final_vignette = vignette.data['vignettes'].last
|
370
|
+
computed_competency['included'] = final_vignette[:competencies].any? {|c| c[:id] == competency['id']}
|
371
|
+
else
|
372
|
+
computed_competency['included'] = false
|
373
|
+
end
|
374
|
+
|
375
|
+
# If it was a target that was met
|
376
|
+
if computed_competency['target'] && computed_competency['included']
|
377
|
+
num_targets_met += 1
|
378
|
+
end
|
379
|
+
|
380
|
+
project_row['competencies'].push(computed_competency)
|
228
381
|
end
|
229
382
|
end
|
383
|
+
|
384
|
+
project_row['allTargetsHit'] = num_targets_met == a_project['targets'].size
|
385
|
+
|
386
|
+
project_rows.push(project_row)
|
230
387
|
end
|
388
|
+
|
389
|
+
return {
|
390
|
+
"project_rows" => project_rows,
|
391
|
+
"categories" => categories,
|
392
|
+
"num_competencies" => num_competencies
|
393
|
+
}
|
231
394
|
end
|
232
395
|
end
|
233
396
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dsm-portfolio-plugin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Hills
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|