Refactor helpers and render function
This commit is contained in:
parent
f6a55bc1db
commit
c94e5ac315
40
index.js
40
index.js
|
@ -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 })
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue