mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 01:41:46 +03:00
abda6e6338
closes #10773 - The refactoring is a substitute for `urlService.utils` used previously throughout the codebase and now extracted into the separate module in Ghost-SDK - Added url-utils stubbing utility for test suites - Some tests had to be refactored to avoid double mocks (when url's are being reset inside of rested 'describe' groups)
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
var _ = require('lodash').runInContext(),
|
|
fs = require('fs-extra'),
|
|
path = require('path'),
|
|
htmlToText = require('html-to-text'),
|
|
urlUtils = require('../../lib/url-utils'),
|
|
templatesDir = path.resolve(__dirname, '..', 'mail', 'templates');
|
|
|
|
_.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
|
|
|
|
exports.generateContent = function generateContent(options) {
|
|
var defaults,
|
|
data;
|
|
|
|
defaults = {
|
|
siteUrl: urlUtils.urlFor('home', true)
|
|
};
|
|
|
|
data = _.defaults(defaults, options.data);
|
|
|
|
// read the proper email body template
|
|
return fs.readFile(path.join(templatesDir, options.template + '.html'), 'utf8')
|
|
.then(function (content) {
|
|
var compiled,
|
|
htmlContent,
|
|
textContent;
|
|
|
|
// insert user-specific data into the email
|
|
compiled = _.template(content);
|
|
htmlContent = compiled(data);
|
|
|
|
// generate a plain-text version of the same email
|
|
textContent = htmlToText.fromString(htmlContent);
|
|
|
|
return {
|
|
html: htmlContent,
|
|
text: textContent
|
|
};
|
|
});
|
|
};
|