forked from ainsleyc/jsonresume-theme-onepage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (56 loc) · 1.5 KB
/
index.js
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
var fs = require("fs");
var Handlebars = require("handlebars");
COURSES_COLUMNS = 3;
PREPEND_SUMMARY_CATEGORIES = [
"work",
"volunteer",
"awards",
"publications"
];
function validateArray(arr) {
return arr !== undefined && arr !== null && arr instanceof Array && arr.length > 0;
}
function render(resume) {
// Split courses into 3 columns
if (validateArray(resume.education)) {
resume.education.forEach(function(block) {
if (validateArray(block.courses)) {
splitCourses = [];
columnIndex = 0;
for (var i = 0; i < COURSES_COLUMNS; i++) {
splitCourses.push([]);
}
block.courses.forEach(function(course) {
splitCourses[columnIndex].push(course);
columnIndex++;
if (columnIndex >= COURSES_COLUMNS) {
columnIndex = 0;
}
});
block.courses = splitCourses;
}
});
}
PREPEND_SUMMARY_CATEGORIES.forEach(function(category) {
if (resume[category] !== undefined) {
resume[category].forEach(function(block) {
if (block.highlights === undefined) {
block.highlights = [];
}
if (block.summary) {
block.highlights.unshift(block.summary);
delete block.summary;
}
});
}
});
var css = fs.readFileSync(__dirname + "/style.css", "utf-8");
var tpl = fs.readFileSync(__dirname + "/resume.hbs", "utf-8");
return Handlebars.compile(tpl)({
css: css,
resume: resume
});
}
module.exports = {
render: render
};