|
@ -3,6 +3,7 @@ |
|
|
var _ = require('lodash'); |
|
|
var _ = require('lodash'); |
|
|
var $ = require('preconditions').singleton(); |
|
|
var $ = require('preconditions').singleton(); |
|
|
var async = require('async'); |
|
|
var async = require('async'); |
|
|
|
|
|
var Mustache = require('mustache'); |
|
|
var log = require('npmlog'); |
|
|
var log = require('npmlog'); |
|
|
log.debug = log.verbose; |
|
|
log.debug = log.verbose; |
|
|
var fs = require('fs'); |
|
|
var fs = require('fs'); |
|
@ -98,8 +99,8 @@ EmailService.prototype._readTemplate = function(filename, cb) { |
|
|
} |
|
|
} |
|
|
var lines = template.split('\n'); |
|
|
var lines = template.split('\n'); |
|
|
return cb(null, { |
|
|
return cb(null, { |
|
|
subject: _.template(lines[0]), |
|
|
subject: lines[0], |
|
|
body: _.template(_.rest(lines).join('\n')), |
|
|
body: _.rest(lines).join('\n'), |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}; |
|
|
}; |
|
@ -107,7 +108,7 @@ EmailService.prototype._readTemplate = function(filename, cb) { |
|
|
EmailService.prototype._applyTemplate = function(template, data, cb) { |
|
|
EmailService.prototype._applyTemplate = function(template, data, cb) { |
|
|
var result = _.mapValues(template, function(t) { |
|
|
var result = _.mapValues(template, function(t) { |
|
|
try { |
|
|
try { |
|
|
return t(data); |
|
|
return Mustache.render(t, data); |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
log.error('Could not apply data to template', e); |
|
|
log.error('Could not apply data to template', e); |
|
|
return cb(e); |
|
|
return cb(e); |
|
|