-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathindex.js
34 lines (28 loc) · 1.06 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
const fs = require('fs');
const handlebars = require('handlebars');
const handlebarsWax = require('handlebars-wax');
const moment = require('moment');
handlebars.registerHelper({
removeProtocol: url => url.replace(/.*?:\/\//g, ''),
concat: (...args) => args.filter(arg => typeof arg !== 'object').join(''),
// Arguments: {address, city, subdivision, postalCode, countryCode}
// formatAddress: (...args) => addressFormat(args).join(' '),
formatAddress: (...args) => args.filter(arg => typeof arg !== 'object').join(' '),
formatDate: date => moment(date).format('MM/YYYY'),
lowercase: s => s.toLowerCase(),
eq: (a, b) => a === b,
});
function render(resume) {
const dir = `${__dirname}/src`;
const css = fs.readFileSync(`${dir}/style.css`, 'utf-8');
const resumeTemplate = fs.readFileSync(`${dir}/resume.hbs`, 'utf-8');
const Handlebars = handlebarsWax(handlebars);
Handlebars.partials(`${dir}/partials/**/*.{hbs,js}`);
return Handlebars.compile(resumeTemplate)({
style: `<style>${css}</style>`,
resume,
});
}
module.exports = {
render,
};