cleaning up; added raw template view for debugging

This commit is contained in:
Sacha Greif 2016-04-13 12:55:21 +09:00
parent 127b49dcbe
commit 0167aace45
6 changed files with 28 additions and 74 deletions

View file

@ -10,36 +10,4 @@ Comments.getNotificationProperties = function (comment) {
commentUrl: Comments.getPageUrl(comment, true)
};
return properties;
};
// Telescope.notifications = Object.assign(Telescope.notifications, {
// newComment: {
// properties(data) {
// return Comments.getNotificationProperties(data.comment, data.post);
// },
// subject(properties) {
// return properties.authorName+' left a new comment on your post "' + properties.postTitle + '"';
// },
// emailTemplate: "newComment"
// },
// newReply: {
// properties(data) {
// return Comments.getNotificationProperties(data.comment, data.post);
// },
// subject(properties) {
// return properties.authorName+' replied to your comment on "'+properties.postTitle+'"';
// },
// emailTemplate: "newReply"
// },
// newCommentSubscribed: {
// properties(data) {
// return Comments.getNotificationProperties(data.comment, data.post);
// },
// subject(properties) {
// return properties.authorName+' left a new comment on "' + properties.postTitle + '"';
// },
// emailTemplate: "newComment"
// }
// });
};

View file

@ -19,7 +19,7 @@ const renderEmail = (email, key) => {
return (
<tr key={key}>
<td>{key}</td>
<td>{email.template}</td>
<td><a href={"/email/template/"+email.template} target="_blank">{email.template}</a></td>
<td>{email.subject({})}</td>
<td><a href={email.path.replace(":_id?", "")} target="_blank">{email.path}</a></td>
<td><Button onClick={sendTest} bsStyle="primary">Send Test</Button></td>

View file

@ -1,4 +1,6 @@
_.forEach(Telescope.email.emails, (email, key) => {
// template live preview routes
Picker.route(email.path, (params, req, res) => {
let html;
@ -25,4 +27,10 @@ _.forEach(Telescope.email.emails, (email, key) => {
res.end(html);
});
});
// raw template
Picker.route("/email/template/:template", (params, req, res) => {
res.end(Telescope.email.templates[params.template]);
});
});

View file

@ -109,11 +109,9 @@ Meteor.methods({
if(Users.is.adminById(this.userId)){
console.log("// testing email ["+emailName+"]");
const item = email.getTestObject();
const subject = "[Test] " + email.subject(email.getProperties(item));
let html;
let html, properties;
// if email has a custom way of generating test HTML, use it
// if email has a custom way of generating its HTML, use it
if (typeof email.getTestHTML !== "undefined") {
html = email.getTestHTML.bind(email)();
@ -123,12 +121,16 @@ Meteor.methods({
// else get test object (sample post, comment, user, etc.)
const testObject = email.getTestObject();
// get test object's email properties
const properties = email.getProperties(testObject);
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));
}
// get subject
const subject = "[Test] " + email.subject.bind(email)(properties);
Telescope.email.buildAndSendHTML(Telescope.settings.get('defaultEmail'), subject, html);
return subject;

View file

@ -4,8 +4,16 @@ import Campaign from "./campaign.js";
Telescope.email.emails.newsletter = Object.assign(Telescope.email.emails.newsletter, {
getCampaign() {
return Campaign.build(Campaign.getPosts(Telescope.settings.get('postsPerNewsletter', 5)));
},
subject() {
return this.getCampaign().subject;
},
getTestHTML() {
var campaign = Campaign.build(Campaign.getPosts(Telescope.settings.get('postsPerNewsletter', 5)));
var campaign = this.getCampaign();
var newsletterEnabled = '<div class="newsletter-enabled"><strong>Newsletter Enabled:</strong> '+Telescope.settings.get('enableNewsletter', true)+'</div>';
var mailChimpAPIKey = '<div class="mailChimpAPIKey"><strong>mailChimpAPIKey:</strong> '+(typeof Telescope.settings.get('mailChimpAPIKey') !== "undefined")+'</div>';
var mailChimpListId = '<div class="mailChimpListId"><strong>mailChimpListId:</strong> '+(typeof Telescope.settings.get('mailChimpListId') !== "undefined")+'</div>';

View file

@ -16,36 +16,4 @@ Posts.getNotificationProperties = function (post) {
properties.htmlBody = post.htmlBody;
return properties;
};
// Telescope.notifications = Object.assign(Telescope.notifications, {
// newPost: {
// properties(data) {
// return Posts.getNotificationProperties(data.post);
// },
// subject(properties) {
// return properties.postAuthorName+' has created a new post: '+properties.postTitle;
// },
// emailTemplate: "newPost"
// },
// newPendingPost: {
// properties(data) {
// return Posts.getNotificationProperties(data.post);
// },
// subject(properties) {
// return properties.postAuthorName+' has a new post pending approval: '+properties.postTitle;
// },
// emailTemplate: "newPendingPost"
// },
// postApproved: {
// properties(data) {
// return Posts.getNotificationProperties(data.post);
// },
// subject(properties) {
// return 'Your post “'+properties.postTitle+'” has been approved';
// },
// emailTemplate: "postApproved"
// }
// });
};