Refactor helpers and render function

This commit is contained in:
Rafael Bardini 2020-07-05 14:54:30 +02:00
parent f6a55bc1db
commit c94e5ac315
1 changed files with 16 additions and 24 deletions

View File

@ -1,28 +1,20 @@
var fs = require('fs')
var Handlebars = require('handlebars')
const fs = require('fs')
const Handlebars = require('handlebars')
module.exports = {
render: render,
}
function render(resume) {
var css = fs.readFileSync(__dirname + '/style.css', 'utf-8')
var template = fs.readFileSync(__dirname + '/resume.hbs', 'utf-8')
return Handlebars.compile(template)({
css: css,
resume: resume,
})
}
Handlebars.registerHelper('formatDate', function (dateString) {
const date = new Date(dateString)
return date.toLocaleDateString('en', {
Handlebars.registerHelper('formatDate', dateString =>
new Date(dateString).toLocaleDateString('en', {
month: 'short',
year: 'numeric',
})
})
}),
)
Handlebars.registerHelper('join', function (arr, separator) {
separator = typeof separator === 'string' ? separator : ', '
return arr.join(separator)
})
Handlebars.registerHelper('join', (arr, separator) =>
arr.join(typeof separator === 'string' ? separator : ', '),
)
exports.render = resume => {
const template = fs.readFileSync(`${__dirname}/resume.hbs`, 'utf-8')
const css = fs.readFileSync(`${__dirname}/style.css`, 'utf-8')
return Handlebars.compile(template)({ css, resume })
}