Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit eb08247

Browse files
committed
refactor server-side email template routes
1 parent f32cdb0 commit eb08247

10 files changed

Lines changed: 265 additions & 50 deletions

File tree

lib/router/server.js

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,49 +20,6 @@ Meteor.startup(function (){
2020
}
2121
});
2222

23-
// Notification email
24-
25-
Router.route('/email/notification/:id?', {
26-
name: 'notification',
27-
where: 'server',
28-
action: function() {
29-
var notification = Notifications.findOne(this.params.id);
30-
var notificationContents = buildEmailNotification(notification);
31-
this.response.write(notificationContents.html);
32-
this.response.end();
33-
}
34-
});
35-
36-
// New user email
37-
38-
Router.route('/email/new-user/:id?', {
39-
name: 'newUser',
40-
where: 'server',
41-
action: function() {
42-
var user = Meteor.users.findOne(this.params.id);
43-
var emailProperties = {
44-
profileUrl: getProfileUrl(user),
45-
username: getUserName(user)
46-
};
47-
html = getEmailTemplate('emailNewUser')(emailProperties);
48-
this.response.write(buildEmailTemplate(html));
49-
this.response.end();
50-
}
51-
});
52-
53-
// New post email
54-
55-
Router.route('/email/new-post/:id?', {
56-
name: 'newPost',
57-
where: 'server',
58-
action: function() {
59-
var post = Posts.findOne(this.params.id);
60-
html = Handlebars.templates[getTemplate('emailNewPost')](getPostProperties(post));
61-
this.response.write(buildEmailTemplate(html));
62-
this.response.end();
63-
}
64-
});
65-
6623
// Account approved email
6724

6825
Router.route('/email/account-approved/:id?', {

packages/telescope-email/lib/server/email.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11

22
var htmlToText = Npm.require('html-to-text');
33

4+
// check if server-side template has been customized, and return the correct template
45
getEmailTemplate = function (template) {
5-
return Handlebars.templates[getTemplate(template)];
6+
var emailTemplate = Handlebars.templates[getTemplate(template)];
7+
if(typeof emailTemplate === 'function'){
8+
return Handlebars.templates[getTemplate(template)];
9+
} else {
10+
console.log('Cannot find template '+getTemplate(template)+', defaulting to '+template);
11+
return Handlebars.templates[template];
12+
}
613
}
714

815
buildEmailTemplate = function (htmlContent) {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Meteor.startup(function () {
2+
3+
// New user email
4+
5+
Router.route('/email/new-user/:id?', {
6+
name: 'newUser',
7+
where: 'server',
8+
action: function() {
9+
var user = Meteor.users.findOne(this.params.id);
10+
var emailProperties = {
11+
profileUrl: getProfileUrl(user),
12+
username: getUserName(user)
13+
};
14+
html = getEmailTemplate('emailNewUser')(emailProperties);
15+
this.response.write(buildEmailTemplate(html));
16+
this.response.end();
17+
}
18+
});
19+
20+
// New post email
21+
22+
Router.route('/email/new-post/:id?', {
23+
name: 'newPost',
24+
where: 'server',
25+
action: function() {
26+
var post = Posts.findOne(this.params.id);
27+
console.log(templates)
28+
if (!!post) {
29+
html = getEmailTemplate('emailNewPost')(getPostProperties(post));
30+
} else {
31+
html = "<h3>No post found.</h3>"
32+
}
33+
this.response.write(buildEmailTemplate(html));
34+
this.response.end();
35+
}
36+
});
37+
38+
39+
});

packages/telescope-email/package.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,19 @@ Npm.depends({
1010

1111
Package.onUse(function (api) {
1212

13+
api.use([
14+
'iron:router',
15+
'telescope-base',
16+
'telescope-lib'
17+
], ['client', 'server']);
18+
1319
api.use([
1420
'cmather:handlebars-server'
1521
], ['server']);
1622

1723
api.add_files([
1824
'lib/server/email.js',
25+
'lib/server/routes.js',
1926
'lib/server/templates/emailAccountApproved.handlebars',
2027
'lib/server/templates/emailInvite.handlebars',
2128
'lib/server/templates/emailNewComment.handlebars',

packages/telescope-email/versions.json

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,208 @@
11
{
22
"dependencies": [
3+
[
4+
"application-configuration",
5+
"1.0.3"
6+
],
7+
[
8+
"base64",
9+
"1.0.1"
10+
],
11+
[
12+
"binary-heap",
13+
"1.0.1"
14+
],
15+
[
16+
"blaze",
17+
"2.0.3"
18+
],
19+
[
20+
"blaze-tools",
21+
"1.0.1"
22+
],
23+
[
24+
"boilerplate-generator",
25+
"1.0.1"
26+
],
27+
[
28+
"callback-hook",
29+
"1.0.1"
30+
],
31+
[
32+
"check",
33+
"1.0.2"
34+
],
335
[
436
"cmather:handlebars-server",
537
"2.0.0"
638
],
39+
[
40+
"ddp",
41+
"1.0.11"
42+
],
43+
[
44+
"deps",
45+
"1.0.5"
46+
],
47+
[
48+
"ejson",
49+
"1.0.4"
50+
],
51+
[
52+
"follower-livedata",
53+
"1.0.2"
54+
],
55+
[
56+
"geojson-utils",
57+
"1.0.1"
58+
],
759
[
860
"handlebars",
961
"1.0.1"
1062
],
63+
[
64+
"html-tools",
65+
"1.0.2"
66+
],
67+
[
68+
"htmljs",
69+
"1.0.2"
70+
],
71+
[
72+
"id-map",
73+
"1.0.1"
74+
],
75+
[
76+
"iron:controller",
77+
"1.0.0"
78+
],
79+
[
80+
"iron:core",
81+
"1.0.0"
82+
],
83+
[
84+
"iron:dynamic-template",
85+
"1.0.0"
86+
],
87+
[
88+
"iron:layout",
89+
"1.0.0"
90+
],
91+
[
92+
"iron:location",
93+
"1.0.1"
94+
],
95+
[
96+
"iron:middleware-stack",
97+
"1.0.0"
98+
],
99+
[
100+
"iron:router",
101+
"1.0.1"
102+
],
103+
[
104+
"iron:url",
105+
"1.0.0"
106+
],
107+
[
108+
"jquery",
109+
"1.0.1"
110+
],
111+
[
112+
"json",
113+
"1.0.1"
114+
],
115+
[
116+
"logging",
117+
"1.0.5"
118+
],
11119
[
12120
"meteor",
13121
"1.1.3"
14122
],
123+
[
124+
"minifiers",
125+
"1.1.2"
126+
],
127+
[
128+
"minimongo",
129+
"1.0.5"
130+
],
131+
[
132+
"mongo",
133+
"1.0.8"
134+
],
135+
[
136+
"observe-sequence",
137+
"1.0.3"
138+
],
139+
[
140+
"ordered-dict",
141+
"1.0.1"
142+
],
143+
[
144+
"random",
145+
"1.0.1"
146+
],
147+
[
148+
"reactive-dict",
149+
"1.0.4"
150+
],
151+
[
152+
"reactive-var",
153+
"1.0.3"
154+
],
155+
[
156+
"retry",
157+
"1.0.1"
158+
],
159+
[
160+
"routepolicy",
161+
"1.0.2"
162+
],
163+
[
164+
"spacebars",
165+
"1.0.3"
166+
],
167+
[
168+
"spacebars-compiler",
169+
"1.0.3"
170+
],
171+
[
172+
"telescope-base",
173+
"0.0.0"
174+
],
175+
[
176+
"telescope-i18n",
177+
"0.0.0"
178+
],
179+
[
180+
"telescope-lib",
181+
"0.2.9"
182+
],
183+
[
184+
"templating",
185+
"1.0.9"
186+
],
187+
[
188+
"tracker",
189+
"1.0.3"
190+
],
191+
[
192+
"ui",
193+
"1.0.4"
194+
],
15195
[
16196
"underscore",
17197
"1.0.1"
198+
],
199+
[
200+
"webapp",
201+
"1.1.4"
202+
],
203+
[
204+
"webapp-hashing",
205+
"1.0.1"
18206
]
19207
],
20208
"pluginDependencies": [],

packages/telescope-newsletter/lib/server/cron.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ getSchedule = function (parser) {
2929
SyncedCron.getNext = function (jobName) {
3030
var scheduledAt;
3131
try {
32-
this._entries.some(function(entry) {
32+
_.some(this._entries, function(entry) {
3333
if(entry.name === jobName){
3434
var schedule = entry.schedule(Later.parse);
3535
scheduledAt = Later.schedule(schedule).next(1);

packages/telescope-newsletter/lib/server/templates/emailPostItem.handlebars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
{{#if body}}
2525
<div class="post-body-excerpt">
26-
{{{body}}}
26+
{{{htmlBody}}}
2727
<a href="{{postPageLink}}" class="comment-link" target="_blank">Read more</a>
2828
</div>
2929
{{/if}}

packages/telescope-newsletter/package.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ Package.onUse(function (api) {
1515
'telescope-lib',
1616
'telescope-base',
1717
'aldeed:simple-schema',
18+
'iron:router',
1819
'mrt:mailchimp'
1920
], ['client', 'server']);
2021

2122
api.use([
2223
'jquery',
2324
'underscore',
24-
'iron:router',
2525
'templating',
2626
'mrt:cookies'
2727
], 'client');
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Meteor.startup(function () {
2+
3+
// Notification email
4+
5+
Router.route('/email/notification/:id?', {
6+
name: 'notification',
7+
where: 'server',
8+
action: function() {
9+
var notification = Notifications.findOne(this.params.id);
10+
var notificationContents = buildEmailNotification(notification);
11+
this.response.write(notificationContents.html);
12+
this.response.end();
13+
}
14+
});
15+
16+
});

0 commit comments

Comments
 (0)