Newer
Older
const fs = require('fs')
const handlebars = require('handlebars')
Sebastian Mihalache
committed
const getNotificationBody = ({ replacements }) => {
handlePartial('header', replacements)
handlePartial('footer', replacements)
handlePartial('signature', replacements)
Sebastian Mihalache
committed
if (replacements.hasLink) handlePartial('button', replacements)
handlePartial('body', replacements)
Sebastian Mihalache
committed
return getMainTemplate({ fileName: 'notification', context: replacements })
Sebastian Mihalache
committed
const getInvitationBody = ({ replacements }) => {
handlePartial('invHeader', replacements)
handlePartial('footer', replacements)
Sebastian Mihalache
committed
handlePartial('invUpperContent', replacements)
handlePartial('invButtons', replacements)
handlePartial('invManuscriptData', replacements)
handlePartial('signature', replacements)
Sebastian Mihalache
committed
handlePartial('invLowerContent', replacements)
Sebastian Mihalache
committed
return getMainTemplate({ fileName: 'invitation', context: replacements })
}
const readFile = path =>
fs.readFileSync(path, { encoding: 'utf-8' }, (err, file) => {
if (err) {
throw err
} else {
return file
}
})
const handlePartial = (partialName = 'signature', context = {}) => {
let partial = readFile(`${__dirname}/templates/partials/${partialName}.hbs`)
const template = handlebars.compile(partial)
partial = template(context)
handlebars.registerPartial(partialName, partial)
}
Sebastian Mihalache
committed
const getMainTemplate = ({ fileName, context }) => {
const htmlFile = readFile(`${__dirname}/templates/${fileName}.html`)