forked from hectorguo/jsonresume-theme-material
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·146 lines (124 loc) · 3.43 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
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
const fs = require("fs");
const path = require("path");
const Handlebars = require("handlebars");
Handlebars.registerHelper("join", function (array, sep) {
return array
.map(function (item) {
return item;
})
.join(sep);
});
// comparison helpers
Handlebars.registerHelper("eq", function (a, b) {
return a === b;
});
Handlebars.registerHelper("gt", function (a, b) {
return a > b;
});
Handlebars.registerHelper("gte", function (a, b) {
return a >= b;
});
Handlebars.registerHelper("lt", function (a, b) {
return a < b;
});
Handlebars.registerHelper("lte", function (a, b) {
return a <= b;
});
Handlebars.registerHelper("ne", function (a, b) {
return a !== b;
});
// score prefix helper
Handlebars.registerHelper("scorePrefix", function (string) {
return string.toString().endsWith("%") ? "Percentage" : "CGPA";
});
function render(resume) {
if (resume.work && resume.work.length) {
resume.workEnabled = true;
} else {
resume.workEnabled = false;
}
if (resume.volunteer && resume.volunteer.length) {
resume.volunteerEnabled = true;
} else {
resume.volunteerEnabled = false;
}
if (resume.projects && resume.projects.length) {
resume.projectsEnabled = true;
} else {
resume.projectsEnabled = false;
}
if (resume.education && resume.education.length) {
resume.educationEnabled = true;
} else {
resume.educationEnabled = false;
}
if (resume.awards && resume.awards.length) {
resume.awardsEnabled = true;
} else {
resume.awardsEnabled = false;
}
if (resume.publications && resume.publications.length) {
resume.publicationsEnabled = true;
} else {
resume.publicationsEnabled = false;
}
if (resume.skills && resume.skills.length) {
resume.skillsEnabled = true;
} else {
resume.skillsEnabled = false;
}
if (resume.interests && resume.interests.length) {
resume.interestsEnabled = true;
} else {
resume.interestsEnabled = false;
}
if (resume.languages && resume.languages.length) {
resume.languagesEnabled = true;
} else {
resume.languagesEnabled = false;
}
if (resume.references && resume.references.length) {
resume.referencesEnabled = true;
} else {
resume.referencesEnabled = false;
}
// use an ugly hack to set PDF/export-related options
if (process.argv.slice(2)[0] !== "export") {
const exportToPDF = {
network: "Export to PDF",
username: "",
url: "javascript:window.print();",
};
if (resume.basics.profiles && resume.basics.profiles.length) {
resume.basics.profiles[resume.basics.profiles.length] = exportToPDF;
} else {
resume.basics.profiles[0] = exportToPDF;
}
resume.linksEnabled = true;
} else {
resume.linksEnabled = false;
}
const css = fs.readFileSync(__dirname + "/style.css", "utf-8");
const tpl = fs.readFileSync(__dirname + "/main.hbs", "utf-8");
const partialsDir = path.join(__dirname, "partials");
if (fs.existsSync(partialsDir)) {
const filenames = fs.readdirSync(partialsDir);
filenames.forEach(function (filename) {
const matches = /^([^.]+).hbs$/.exec(filename);
if (!matches) {
return;
}
const name = matches[1];
const filepath = path.join(partialsDir, filename);
const template = fs.readFileSync(filepath, "utf8");
Handlebars.registerPartial(name, template);
});
}
return Handlebars.compile(tpl)({
css,
resume,
});
}
module.exports = {
render,
};