-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (37 loc) · 1.18 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
var fs = require('fs');
var path = require('path');
var Handlebars = require('handlebars');
groupBy = require('handlebars-group-by');
Handlebars.registerHelper(groupBy(Handlebars));
Handlebars.registerHelper('date', require('helper-date'));
Handlebars.registerHelper('dateformat', require('helper-dateformat'));
function render(resume) {
var css = fs.readFileSync(__dirname + '/style.css', 'utf-8');
var tpl = 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);
});
return Handlebars.compile(tpl)({
css: css,
resume: resume,
});
}
module.exports = {
render: render,
pdfRenderOptions: {
margin: {
top: '1cm',
bottom: '1cm',
},
mediaType: 'print',
},
};