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') const fs = require('fs')
var Handlebars = require('handlebars') const Handlebars = require('handlebars')
module.exports = { Handlebars.registerHelper('formatDate', dateString =>
render: render, new Date(dateString).toLocaleDateString('en', {
}
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', {
month: 'short', month: 'short',
year: 'numeric', year: 'numeric',
}) }),
}) )
Handlebars.registerHelper('join', function (arr, separator) { Handlebars.registerHelper('join', (arr, separator) =>
separator = typeof separator === 'string' ? separator : ', ' arr.join(typeof separator === 'string' ? separator : ', '),
return arr.join(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 })
}