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

Commit

Permalink
Convert to modules
Browse files Browse the repository at this point in the history
  • Loading branch information
johanbrook committed Oct 28, 2016
1 parent 0daf4e6 commit 2a60d33
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 12 deletions.
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

"globals": {
"Mailer": true,
"Utils": true,
"juice": false,
"FlowRouter": false,
"Router": false,
Expand Down
2 changes: 1 addition & 1 deletion export.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { theModule } from './lib/mailer';
import { Mailer as theModule } from './lib/mailer';

Mailer = theModule;
2 changes: 2 additions & 0 deletions lib/mailer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Made by Johan Brook for [Lookback](https://github.com/lookback).

import RoutingMiddleware from './routing';
import TemplateHelpers from './template-helpers';
import Utils from './utils';

const TAG = 'mailer';

Expand Down
1 change: 0 additions & 1 deletion lib/mailer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Mailer from './mailer';
import { assert } from 'meteor/practicalmeteor:chai';

describe('Mailer', () => {

it('should be defined', () => {
assert.isObject(Mailer);
});
Expand Down
6 changes: 4 additions & 2 deletions lib/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// It will apply the returned data from a `data` function on the
// provided `route` prop from the template.

import Utils from './utils';

const CONTENT_TYPES = {
html: 'text/html',
text: 'text/plain'
Expand All @@ -15,7 +17,7 @@ const CONTENT_TYPES = {
const arrayOrString = (str) =>
Array.isArray(str) ? str : str.split(',');

export function Routing(template, settings, render, compile) {
export default function Routing(template, settings, render, compile) {
check(template, Object);
check(template.name, String);

Expand Down Expand Up @@ -122,7 +124,7 @@ export function Routing(template, settings, render, compile) {
res.writeHead(200);
const reallySentEmail = !!process.env.MAIL_URL;
msg = reallySentEmail
? `Sent test email to ${to}` + ((cc) ? ` and cc: ${cc}` : '') + ((bcc) ? `, and bcc: ${bcc}` : '')
? `Sent test email to ${to}` + ((cc) ? ` and cc: ${cc}` : '') + ((bcc) ? `, and bcc: ${bcc}` : '') // eslint-disable-line
: 'Sent email to STDOUT';
}

Expand Down
7 changes: 5 additions & 2 deletions lib/template-helpers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Utils from './utils';

// # Template helpers
//
// Built-in template helpers.
TemplateHelpers = {
export default {
// `baseUrl` gives you a full absolute URL from a relative path.
//
// {{ baseUrl '/some-path' }} => http://root-domain.com/some-path
Expand All @@ -17,7 +19,8 @@ TemplateHelpers = {
const theRouter = Package['iron:router'] ? Router : FlowRouter;

if (theRouter && theRouter.path) {
return Utils.joinUrl(Mailer.settings.baseUrl, theRouter.path.call(theRouter, routeName, params.hash));
return Utils.joinUrl(Mailer.settings.baseUrl,
theRouter.path.call(theRouter, routeName, params.hash));
}

Utils.Logger.warn(`We noticed that neither Iron Router nor FlowRouter is installed, thus 'emailUrlFor' can't render a path to the route '${routeName}.`);
Expand Down
7 changes: 5 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ let ROOT = privateDir && Path.join(privateDir, 'programs', 'server', 'assets', '

ROOT = ROOT || developmentPrivateDir();

Utils = {
const Utils = {
// Takes an HTML string and outputs a text version of it. Catches and logs errors.
toText(html, opts = {}) {
try {
Expand Down Expand Up @@ -196,7 +196,8 @@ Utils = {
? 'Please run `meteor npm install --save node-sass` in your app to add sass support.'
: 'Please run `meteor add chrisbutler:node-sass` to add sass support.';

Utils.Logger.warn(`Could not find sass module. Sass support is opt-in since lookback:[email protected].
Utils.Logger
.warn(`Could not find sass module. Sass support is opt-in since lookback:[email protected].
${packageToRecommend}`, TAG);
return Utils.readFile(scss);
Expand Down Expand Up @@ -228,3 +229,5 @@ ${packageToRecommend}`, TAG);
return ''; // fallback: on error, or if file does NOT exist
}
};

export default Utils;
5 changes: 2 additions & 3 deletions package.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ Package.onUse(function(api) {
], where);

api.addFiles([
'lib/utils.js',
'lib/template-helpers.js',
'export.js'
], where);

Expand All @@ -44,9 +42,10 @@ Package.onUse(function(api) {
Package.onTest(function(api) {
api.use([
'ecmascript',
'underscore',
'dispatch:mocha',
'practicalmeteor:chai',
'lookback:emails'
'lookback:emails',
], 'server');

api.mainModule('tests.js', 'server');
Expand Down

0 comments on commit 2a60d33

Please sign in to comment.