2016-04-13 11:39:01 +09:00
|
|
|
_.forEach(Telescope.email.emails, (email, key) => {
|
2016-04-13 12:55:21 +09:00
|
|
|
|
|
|
|
// template live preview routes
|
2016-04-13 11:39:01 +09:00
|
|
|
Picker.route(email.path, (params, req, res) => {
|
2016-04-13 12:34:41 +09:00
|
|
|
|
|
|
|
let html;
|
|
|
|
|
|
|
|
// if email has a custom way of generating test HTML, use it
|
|
|
|
if (typeof email.getTestHTML !== "undefined") {
|
|
|
|
|
|
|
|
html = email.getTestHTML.bind(email)(params);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// else get test object (sample post, comment, user, etc.)
|
|
|
|
const testObject = email.getTestObject(params._id);
|
|
|
|
|
|
|
|
// get test object's email properties
|
|
|
|
const properties = email.getProperties(testObject);
|
|
|
|
|
|
|
|
// then apply email template to properties, and wrap it with buildTemplate
|
|
|
|
html = Telescope.email.buildTemplate(Telescope.email.getTemplate(email.template)(properties));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// return html
|
|
|
|
res.end(html);
|
|
|
|
|
2016-04-13 11:39:01 +09:00
|
|
|
});
|
2016-04-13 12:55:21 +09:00
|
|
|
|
|
|
|
// raw template
|
|
|
|
Picker.route("/email/template/:template", (params, req, res) => {
|
|
|
|
res.end(Telescope.email.templates[params.template]);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|