Enable imports in custom email templates (#6052)

* Enable imports in custom email templates

* Compile emails on config change

* Add error logging

* Add emailer tests

* Fix tests

* Only build when config changes
This commit is contained in:
Peter Jaszkowiak
2017-11-21 08:51:20 -07:00
committed by Barış Soner Uşaklı
parent 415940af02
commit 4fcedc6f31
5 changed files with 300 additions and 92 deletions

View File

@@ -1,12 +1,8 @@
'use strict';
var async = require('async');
var nconf = require('nconf');
var fs = require('fs');
var path = require('path');
var meta = require('../../meta');
var file = require('../../file');
var emailer = require('../../emailer');
var settingsController = module.exports;
@@ -26,42 +22,8 @@ settingsController.get = function (req, res, next) {
function renderEmail(req, res, next) {
var emailsPath = path.join(nconf.get('views_dir'), 'emails');
async.parallel({
emails: function (cb) {
async.waterfall([
function (next) {
file.walk(emailsPath, next);
},
function (emails, next) {
// exclude .js files
emails = emails.filter(function (email) {
return !email.endsWith('.js');
});
async.map(emails, function (email, next) {
var path = email.replace(emailsPath, '').substr(1).replace('.tpl', '');
async.waterfall([
function (next) {
fs.readFile(email, 'utf8', next);
},
function (original, next) {
var text = meta.config['email:custom:' + path] ? meta.config['email:custom:' + path] : original;
next(null, {
path: path,
fullpath: email,
text: text,
original: original,
});
},
], next);
}, next);
},
], cb);
},
emails: async.apply(emailer.getTemplates, meta.config),
services: emailer.listServices,
}, function (err, results) {
if (err) {