dsm-portfolio-plugin 0.0.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 +7 -0
- data/lib/dsm-portfolio-plugin.rb +155 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f4bbff02d40d1010a055f83592f62d9575238933
|
4
|
+
data.tar.gz: a52f6089c72bec317aa4ddbc7a16f10229d68d41
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cc3d614a174e013baa9ad5d823742539d376f8902fc005d4962d743129478cf4d9239519337f855c362c696701badfede57d160eda057830e9ae318eb0d65096
|
7
|
+
data.tar.gz: 237ee2648f324425549471e9100024f7b22a9ff33e7e709a2b3f4c85ff8f66d8e4cc25a877e4b6137985edf6836cf3dc50392cfc26593e8157b85565b4a573e8
|
@@ -0,0 +1,155 @@
|
|
1
|
+
# TODO: Comment
|
2
|
+
module Jekyll
|
3
|
+
class ProjectGenerator < Generator
|
4
|
+
safe true
|
5
|
+
priority :highest
|
6
|
+
|
7
|
+
def generate(site)
|
8
|
+
# Select and group posts by subdirectory
|
9
|
+
postsByProject = site.posts.docs.group_by { |post| post.id[/.*(?=\/)/] }
|
10
|
+
|
11
|
+
# Iterate over groupings
|
12
|
+
postsByProject.each do |grouping|
|
13
|
+
projectId = grouping[0]
|
14
|
+
projectFiles = grouping[1]
|
15
|
+
|
16
|
+
projectUrls = {}
|
17
|
+
|
18
|
+
# Give each file one-off values and assess availability.
|
19
|
+
projectFiles.each do |file|
|
20
|
+
# Give each the project Id
|
21
|
+
file.data['project_id'] = projectId
|
22
|
+
# Give each the project title
|
23
|
+
file.data['project_title'] = file.data['title'][/.*(?=\/)/]
|
24
|
+
# Give each a type
|
25
|
+
file.data['type'] = file.basename_without_ext
|
26
|
+
|
27
|
+
projectUrls[file.data['type']] = file.url
|
28
|
+
end
|
29
|
+
|
30
|
+
# Add singling URLs based on type.
|
31
|
+
projectFiles.each do |file|
|
32
|
+
file.data['project_urls'] = projectUrls
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class CompetencyTag < Liquid::Tag
|
39
|
+
def initialize(tag_name, text, tokens)
|
40
|
+
super
|
41
|
+
|
42
|
+
# Store competency id for later.
|
43
|
+
@competencyId = text.strip.split(" ")[0]
|
44
|
+
end
|
45
|
+
|
46
|
+
def render(context)
|
47
|
+
# Find the correct competency.
|
48
|
+
competency = context.registers[:site].data['competencies'].select {|c| c['id'] == @competencyId} [0]
|
49
|
+
|
50
|
+
# Add it to vignette if one exists.
|
51
|
+
if context['active_vignette']
|
52
|
+
# Find out if the current competency has already been logged.
|
53
|
+
competencyTally = context['active_vignette'][:competencies].select {|c| c[:id] == competency['id']} [0]
|
54
|
+
|
55
|
+
if competencyTally
|
56
|
+
# Increment tally.
|
57
|
+
competencyTally[:count] += 1
|
58
|
+
else
|
59
|
+
# Add entry.
|
60
|
+
context['active_vignette'][:competencies].push({
|
61
|
+
'id': competency['id'],
|
62
|
+
'count': 1
|
63
|
+
})
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Render if available.
|
68
|
+
if competency
|
69
|
+
"<span class=\"a-pill\">#{competency['id']}</span>"
|
70
|
+
else
|
71
|
+
"<span class=\"a-pill a-pill--error\">\"#{@competencyId}\" undefined</span>"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class VignetteTag < Liquid::Block
|
77
|
+
def initialize(tag_name, markup, tokens)
|
78
|
+
super
|
79
|
+
end
|
80
|
+
|
81
|
+
def render(context)
|
82
|
+
# Check for existence of vignette iterations.
|
83
|
+
if !context['page']['vignettes']
|
84
|
+
context['page']['vignettes'] = []
|
85
|
+
|
86
|
+
# Check for project data.
|
87
|
+
if context['page']['project_code']
|
88
|
+
project = context.registers[:site].data['projects'].select {|p| p['id'] == context['page']['project_code']} [0]
|
89
|
+
|
90
|
+
# Add target competencies.
|
91
|
+
if project
|
92
|
+
context['page']['targets'] = project['targets']
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Create a new iteration.
|
98
|
+
context['active_vignette'] = {
|
99
|
+
'competencies': []
|
100
|
+
}
|
101
|
+
|
102
|
+
# Add it to the array.
|
103
|
+
context['page']['vignettes'].push(context['active_vignette'])
|
104
|
+
|
105
|
+
# Render text as normal.
|
106
|
+
rendered = super
|
107
|
+
# Wrap in page-specific markup.
|
108
|
+
classString = 'o-vignette-blocks__block'
|
109
|
+
if context['page']['vignettes'].size == 1
|
110
|
+
classString += ' o-vignette-blocks__block--active'
|
111
|
+
end
|
112
|
+
"<div class=\"#{classString}\" id=\"block-#{context['page']['vignettes'].size - 1}\">#{rendered}</div>"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
module Filters
|
117
|
+
module ApiFilter
|
118
|
+
def flatten_hash(input)
|
119
|
+
all_values = input.to_a.flatten
|
120
|
+
hash_values = all_values.select { |value| value.class == Hash }
|
121
|
+
most_nested_values = []
|
122
|
+
|
123
|
+
if hash_values.count > 0
|
124
|
+
hash_values.each do |hash_value|
|
125
|
+
most_nested_values << flatten_hash(hash_value)
|
126
|
+
end
|
127
|
+
|
128
|
+
most_nested_values.flatten
|
129
|
+
else
|
130
|
+
return input
|
131
|
+
end
|
132
|
+
end
|
133
|
+
def filter_fields(input, fields)
|
134
|
+
downcased_fields = fields
|
135
|
+
.split(",")
|
136
|
+
.map { |field| field.strip.downcase }
|
137
|
+
|
138
|
+
input.map do |entry|
|
139
|
+
entry.select do |key, value|
|
140
|
+
downcased_fields.include?(key.downcase)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# Register everything.
|
149
|
+
Liquid::Template.register_tag('c', Jekyll::CompetencyTag)
|
150
|
+
Liquid::Template.register_tag('competency', Jekyll::CompetencyTag)
|
151
|
+
|
152
|
+
Liquid::Template.register_tag('v', Jekyll::VignetteTag)
|
153
|
+
Liquid::Template.register_tag('vignette', Jekyll::VignetteTag)
|
154
|
+
|
155
|
+
Liquid::Template.register_filter(Jekyll::Filters::ApiFilter)
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dsm-portfolio-plugin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Josh Hills
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jekyll
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.8'
|
27
|
+
description: Generates site project data and declares custom tags.
|
28
|
+
email: josh@jargonify.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/dsm-portfolio-plugin.rb
|
34
|
+
homepage: https://github.com/joshhills/dsm-portfolio-plugin
|
35
|
+
licenses:
|
36
|
+
- MIT
|
37
|
+
metadata:
|
38
|
+
source_code_uri: https://github.com/joshhills/dsm-portfolio-plugin
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 2.5.2
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: Jekyll plugin necessary for dsm-portfolio-theme to function.
|
59
|
+
test_files: []
|