From 0167aace45f11e3f42c52ed6f112cb1317b5dedf Mon Sep 17 00:00:00 2001 From: Sacha Greif Date: Wed, 13 Apr 2016 12:55:21 +0900 Subject: [PATCH] cleaning up; added raw template view for debugging --- packages/nova-comments/lib/notifications.js | 34 +------------------ packages/nova-debug/lib/components/Emails.jsx | 2 +- .../nova-email-templates/lib/server/routes.js | 10 +++++- packages/nova-email/lib/server/email.js | 12 ++++--- packages/nova-newsletter/lib/server/emails.js | 10 +++++- packages/nova-posts/lib/notifications.js | 34 +------------------ 6 files changed, 28 insertions(+), 74 deletions(-) diff --git a/packages/nova-comments/lib/notifications.js b/packages/nova-comments/lib/notifications.js index 26e5ec53e..108d66628 100644 --- a/packages/nova-comments/lib/notifications.js +++ b/packages/nova-comments/lib/notifications.js @@ -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" -// } -// }); \ No newline at end of file +}; \ No newline at end of file diff --git a/packages/nova-debug/lib/components/Emails.jsx b/packages/nova-debug/lib/components/Emails.jsx index 55c4e8cdf..c8c7d4648 100644 --- a/packages/nova-debug/lib/components/Emails.jsx +++ b/packages/nova-debug/lib/components/Emails.jsx @@ -19,7 +19,7 @@ const renderEmail = (email, key) => { return ( {key} - {email.template} + {email.template} {email.subject({})} {email.path} diff --git a/packages/nova-email-templates/lib/server/routes.js b/packages/nova-email-templates/lib/server/routes.js index 7dbececd3..2039d5886 100644 --- a/packages/nova-email-templates/lib/server/routes.js +++ b/packages/nova-email-templates/lib/server/routes.js @@ -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]); + }); + +}); \ No newline at end of file diff --git a/packages/nova-email/lib/server/email.js b/packages/nova-email/lib/server/email.js index dcd29fce8..3a68c85c1 100644 --- a/packages/nova-email/lib/server/email.js +++ b/packages/nova-email/lib/server/email.js @@ -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; diff --git a/packages/nova-newsletter/lib/server/emails.js b/packages/nova-newsletter/lib/server/emails.js index f3d49683a..370a53733 100644 --- a/packages/nova-newsletter/lib/server/emails.js +++ b/packages/nova-newsletter/lib/server/emails.js @@ -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 = '
Newsletter Enabled: '+Telescope.settings.get('enableNewsletter', true)+'
'; var mailChimpAPIKey = '
mailChimpAPIKey: '+(typeof Telescope.settings.get('mailChimpAPIKey') !== "undefined")+'
'; var mailChimpListId = '
mailChimpListId: '+(typeof Telescope.settings.get('mailChimpListId') !== "undefined")+'
'; diff --git a/packages/nova-posts/lib/notifications.js b/packages/nova-posts/lib/notifications.js index 7092ae9c0..751f9e06f 100644 --- a/packages/nova-posts/lib/notifications.js +++ b/packages/nova-posts/lib/notifications.js @@ -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" -// } -// }); \ No newline at end of file +}; \ No newline at end of file