forked from yanStartapp/startapp-email-service
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtemplate.service.js
More file actions
38 lines (28 loc) · 905 Bytes
/
template.service.js
File metadata and controls
38 lines (28 loc) · 905 Bytes
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
35
36
37
38
'use strict';
var swig = require('swig'),
path = require('path');
class EmailTemplateService {
constructor() {}
/**
* Method to get a specific rendered template by name
* @param template - {Template Object} template from config
* @param templateData - {Object} options to render with
* @returns {Promise}
*/
getHtml(template, templateData) {
return new Promise((resolve, reject) => {
// validate exists
if (!template) {
return reject(new Error('Template is not defined'));
}
// render it
swig.renderFile(path.resolve(template.path), templateData, function (err, output) {
if (err) {
return reject(err);
}
resolve(output);
});
});
}
}
module.exports = new EmailTemplateService();