Vulcan/packages/vulcan-email/lib/server/routes.js

54 lines
1.3 KiB
JavaScript
Raw Normal View History

import { Picker } from 'meteor/meteorhacks:picker';
import VulcanEmail from '../namespace.js';
2016-06-23 16:42:06 +09:00
Meteor.startup(function () {
2017-03-24 10:35:19 +09:00
_.forEach(VulcanEmail.emails, (email, key) => {
2016-04-13 12:34:41 +09:00
// template live preview routes
Picker.route(email.path, (params, req, res) => {
2016-04-13 12:34:41 +09:00
let html;
2016-04-13 12:34:41 +09:00
// if email has a custom way of generating test HTML, use it
if (typeof email.getTestHTML !== "undefined") {
2016-04-13 12:34:41 +09:00
html = email.getTestHTML.bind(email)(params);
2016-04-13 12:34:41 +09:00
} else {
2016-04-13 12:34:41 +09:00
// else get test object (sample post, comment, user, etc.)
const testObject = email.getTestObject(params._id);
2016-04-13 12:34:41 +09:00
// get test object's email properties
const properties = email.getProperties(testObject);
2016-04-13 12:34:41 +09:00
// then apply email template to properties, and wrap it with buildTemplate
2017-03-24 10:35:19 +09:00
html = VulcanEmail.buildTemplate(VulcanEmail.getTemplate(email.template)(properties));
2016-04-13 12:34:41 +09:00
html += `
<div style="border: 1px solid #999; padding: 20px; margin: 20px;">
<pre>
<code>
${JSON.stringify(properties, null, '\t')}
</code>
</pre>
</div>
`
}
// return html
res.end(html);
});
// raw template
Picker.route("/email/template/:template", (params, req, res) => {
2017-03-24 10:35:19 +09:00
res.end(VulcanEmail.templates[params.template]);
});
});
});