1
- //`lookback:emails` is a small package for Meteor which helps you
1
+ // `lookback:emails` is a small package for Meteor which helps you
2
2
// tremendously in the process of building, testing and debugging
3
3
// HTML emails in Meteor applications.
4
4
//
@@ -16,7 +16,8 @@ const TAG = 'mailer';
16
16
// - `baseUrl` is what root domain to base relative paths from.
17
17
// - `testEmail`, when testing emails, set this variable.
18
18
// - `logger`, optionally inject an external logger. Defaults to `console`.
19
- // - `disabled`, optionally disable the actual email sending. Useful for E2E testing. Defaults to `false`.
19
+ // - `disabled`, optionally disable the actual email sending. Useful for E2E testing.
20
+ // Defaults to `false`.
20
21
// - `addRoutes`, should we add preview and send routes? Defaults to `true` in development.
21
22
Mailer = {
22
23
settings : {
@@ -42,7 +43,7 @@ Mailer = {
42
43
middlewares : [ ] ,
43
44
44
45
use ( middleware ) {
45
- if ( ! _ . isFunction ( middleware ) ) {
46
+ if ( ! _ . isFunction ( middleware ) ) {
46
47
console . error ( 'Middleware must be a function!' ) ;
47
48
} else {
48
49
this . middlewares . push ( middleware ) ;
@@ -175,7 +176,6 @@ const factory = (options) => {
175
176
const layout = template . layout || options . layout ;
176
177
177
178
if ( layout && template . layout !== false ) {
178
-
179
179
let preview = null ;
180
180
let css = null ;
181
181
@@ -197,7 +197,8 @@ const factory = (options) => {
197
197
try {
198
198
css = Utils . readFile ( template . extraCSS ) ;
199
199
} catch ( ex ) {
200
- Utils . Logger . error ( `Could not add extra CSS when rendering ${ templateName } : ${ ex . message } ` , TAG ) ;
200
+ Utils . Logger . error (
201
+ `Could not add extra CSS when rendering ${ templateName } : ${ ex . message } ` , TAG ) ;
201
202
}
202
203
}
203
204
@@ -222,8 +223,8 @@ const factory = (options) => {
222
223
//
223
224
// The main sending-email function. Takes a set of usual email options,
224
225
// including the template name and optional data object.
225
- const sendEmail = ( options ) => {
226
- check ( options , {
226
+ const sendEmail = ( sendOptions ) => {
227
+ check ( sendOptions , {
227
228
to : String ,
228
229
subject : String ,
229
230
template : String ,
@@ -243,12 +244,13 @@ const factory = (options) => {
243
244
defaults . replyTo = settings . replyTo ;
244
245
}
245
246
246
- const opts = _ . extend ( { } , defaults , options ) ;
247
+ // `template` isn't part of Meteor's `Email.send()` API, so omit this.
248
+ const opts = _ . omit ( _ . extend ( { } , defaults , sendOptions ) , 'template' , 'data' ) ;
247
249
248
250
// Render HTML with optional data context and optionally
249
251
// create plain-text version from HTML.
250
252
try {
251
- opts . html = render ( options . template , options . data ) ;
253
+ opts . html = render ( sendOptions . template , sendOptions . data ) ;
252
254
if ( settings . plainText ) {
253
255
opts . text = Utils . toText ( opts . html , settings . plainTextOpts ) ;
254
256
}
@@ -296,7 +298,7 @@ const factory = (options) => {
296
298
Mailer . init = function ( opts ) {
297
299
const obj = _ . extend ( this , factory ( opts ) ) ;
298
300
299
- if ( obj . settings . addRoutes ) {
301
+ if ( obj . settings . addRoutes ) {
300
302
obj . use ( Routing ) ;
301
303
}
302
304
0 commit comments