-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
55 lines (46 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
var fs = require("fs");
var path = require("path");
var Handlebars = require("handlebars");
function render(resume) {
var css = fs.readFileSync(__dirname + "/style.css", "utf-8");
var template = fs.readFileSync(__dirname + "/resume.hbs", "utf-8");
var partialsDir = path.join(__dirname, 'partials');
var filenames = fs.readdirSync(partialsDir);
filenames.forEach(function (filename) {
var matches = /^([^.]+).hbs$/.exec(filename);
if (!matches) {
return;
}
var name = matches[1];
var filepath = path.join(partialsDir, filename)
var template = fs.readFileSync(filepath, 'utf8');
Handlebars.registerPartial(name, template);
});
// Nicer dates
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
Handlebars.registerHelper('date', function(date) {
const theDate = new Date(date);
return `${months[theDate.getMonth()]} ${theDate.getFullYear()}`;
});
return Handlebars.compile(template)({
css: css,
resume: resume
});
}
Handlebars.registerHelper('paragraphSplit', function(plaintext) {
var i, output = '',
lines = plaintext.split(/\r\n|\r|\n/g);
for (i = 0; i < lines.length; i++) {
if(lines[i]) {
output += '<p>' + lines[i] + '</p>';
}
}
return new Handlebars.SafeString(output);
});
Handlebars.registerHelper('ifNotEquals', function (a, b, options) {
if (a != b) { return options.fn(this); }
return options.inverse(this);
});
module.exports = {
render: render
};