mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-17 11:11:04 +01:00
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:
committed by
Barış Soner Uşaklı
parent
415940af02
commit
4fcedc6f31
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user