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

Commit 7bfdff6

Browse files
committed
Separate options objects in sendEmail function.
1 parent 9e75719 commit 7bfdff6

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

lib/mailer.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//`lookback:emails` is a small package for Meteor which helps you
1+
// `lookback:emails` is a small package for Meteor which helps you
22
// tremendously in the process of building, testing and debugging
33
// HTML emails in Meteor applications.
44
//
@@ -16,7 +16,8 @@ const TAG = 'mailer';
1616
// - `baseUrl` is what root domain to base relative paths from.
1717
// - `testEmail`, when testing emails, set this variable.
1818
// - `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`.
2021
// - `addRoutes`, should we add preview and send routes? Defaults to `true` in development.
2122
Mailer = {
2223
settings: {
@@ -42,7 +43,7 @@ Mailer = {
4243
middlewares: [],
4344

4445
use(middleware) {
45-
if(!_.isFunction(middleware)) {
46+
if (!_.isFunction(middleware)) {
4647
console.error('Middleware must be a function!');
4748
} else {
4849
this.middlewares.push(middleware);
@@ -175,7 +176,6 @@ const factory = (options) => {
175176
const layout = template.layout || options.layout;
176177

177178
if (layout && template.layout !== false) {
178-
179179
let preview = null;
180180
let css = null;
181181

@@ -197,7 +197,8 @@ const factory = (options) => {
197197
try {
198198
css = Utils.readFile(template.extraCSS);
199199
} 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);
201202
}
202203
}
203204

@@ -222,8 +223,8 @@ const factory = (options) => {
222223
//
223224
// The main sending-email function. Takes a set of usual email options,
224225
// including the template name and optional data object.
225-
const sendEmail = (options) => {
226-
check(options, {
226+
const sendEmail = (sendOptions) => {
227+
check(sendOptions, {
227228
to: String,
228229
subject: String,
229230
template: String,
@@ -243,12 +244,13 @@ const factory = (options) => {
243244
defaults.replyTo = settings.replyTo;
244245
}
245246

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');
247249

248250
// Render HTML with optional data context and optionally
249251
// create plain-text version from HTML.
250252
try {
251-
opts.html = render(options.template, options.data);
253+
opts.html = render(sendOptions.template, sendOptions.data);
252254
if (settings.plainText) {
253255
opts.text = Utils.toText(opts.html, settings.plainTextOpts);
254256
}
@@ -296,7 +298,7 @@ const factory = (options) => {
296298
Mailer.init = function(opts) {
297299
const obj = _.extend(this, factory(opts));
298300

299-
if(obj.settings.addRoutes) {
301+
if (obj.settings.addRoutes) {
300302
obj.use(Routing);
301303
}
302304

0 commit comments

Comments
 (0)