Comparing version 1.1.1 to 1.2.0
@@ -5,13 +5,11 @@ 'use strict'; | ||
var emailService = require('./src/emailService.js'); | ||
var consoleProvider = require('./src/providers/console.js'); | ||
var mandrillProvider = require('./src/providers/mandrill.js'); | ||
var nodemailerProvider = require('./src/providers/nodemailer.js'); | ||
var terminal = require('./src/providers/terminal.js'); | ||
var mandrill = require('./src/providers/mandrill.js'); | ||
var nodemailer = require('./src/providers/nodemailer.js'); | ||
var mustache = require('./src/templateEngines/mustache.js'); | ||
function api (options) { | ||
if (!options.provider) { | ||
options.provider = mandrillProvider(options); | ||
} | ||
if (!options.layout) { | ||
options.layout = api.defaultLayout; | ||
} | ||
options.provider = options.provider || mandrill(options); | ||
options.templateEngine = options.templateEngine || mustache; | ||
options.layout = options.layout || options.templateEngine.defaultLayout; | ||
@@ -21,9 +19,12 @@ return emailService(options); | ||
api.defaultLayout = path.join(__dirname, 'templates/layout.mu'); | ||
api.providers = { | ||
console: consoleProvider, | ||
mandrill: mandrillProvider, | ||
nodemailer: nodemailerProvider | ||
terminal: terminal, | ||
mandrill: mandrill, | ||
nodemailer: nodemailer | ||
}; | ||
api.templateEngines = { | ||
mustache: mustache | ||
}; | ||
module.exports = api; |
@@ -1,5 +0,13 @@ | ||
# 1.1.1 | ||
# 1.2.0 Spark Plugs | ||
- Setting `trap` to true will now simply not send any emails, period. | ||
- Support for plugging in templating engines other than `mustache`. | ||
**BREAKING** | ||
- Renamed `console` client as `terminal`. | ||
# 1.1.1 Real Eel | ||
- Setting `trap` to `true` will now simply not send any emails, period. | ||
# 1.1.0 Providing for the family | ||
@@ -6,0 +14,0 @@ |
@@ -14,3 +14,3 @@ { | ||
}, | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"licenses": "MIT", | ||
@@ -17,0 +17,0 @@ "keywords": [ |
@@ -7,3 +7,3 @@ ![campaign.png][9] ![ga](https://ga-beacon.appspot.com/UA-35043128-6/campaign/readme?pixel) | ||
It uses [Mustache][6] to fill out templates, and [Mandrill][1] <sub>_(by default)_</sub> to send emails, although providing your own [`provider`](#providers), to send emails through something else, is [pretty easy](#creating-custom-providers). | ||
It uses [Mustache][6] <sub>_(by default)_</sub> to fill out templates, but it can be [replaced with some other](#template-engines) templating engine. [Mandrill][1] is used <sub>_(by default)_</sub> to send emails, although providing your own [`provider`](#providers), to send emails through something else, is [pretty easy](#creating-custom-providers). | ||
@@ -22,2 +22,4 @@ # Reference | ||
- [Providers](#providers) | ||
- [Template Engines](#template-engines) | ||
- [Contribute!](#contributing) | ||
- [License](#license) | ||
@@ -70,5 +72,6 @@ | ||
"provider": "<default>", | ||
"templateEngine": "<default>", | ||
"trap": false, | ||
"headerImage": "<not provided>", | ||
"layout": "<defaults>" | ||
"layout": "<default>" | ||
} | ||
@@ -99,2 +102,6 @@ ``` | ||
### `templateEngine` | ||
You can use other template engines, [creating your own](#template-engines). You'll need to create a custom `engine` object with both `render` and `renderString` methods. Note that template engines govern the default layouts. If you implement your own engine, you'll have to provide a default layout, as well. | ||
### `headerImage` | ||
@@ -110,3 +117,3 @@ | ||
A default layout `template` is provided. You can provide a different one, just set `layout` to the absolute path of a [Mustache][6] template file. For information about the model passed to the layout, see the **Templates** section. | ||
A default layout `template` is provided. You can provide a different one, just set `layout` to the absolute path of a [Mustache][6] template <sub>_(or the template type supported by your engine)_</sub> file. For information about the model passed to the layout, see the **Templates** section. | ||
@@ -216,3 +223,3 @@ # Email Sending Options | ||
The `layout` has one fundamental requirement in order to be mildly functional, it should have a `{{{body}}}` in it, so that the actual email's content can be rendered. Luckily the default `layout` is good enough that **you shouldn't need to touch it**. | ||
The `layout` has one fundamental requirement in order to be mildly functional, it should have a `{{{body}}}` in it, so that the actual email's content can be rendered. Luckily the default `layout` is good enough that **you shouldn't need to touch it**. If you're building a custom layout, `{{{body}}} should be whatever expression is needed to render the unescaped `<body>` HTML. | ||
@@ -258,2 +265,4 @@ Purposely, the layout template isn't passed the full model, but only a subset, containing: | ||
Custom layouts should either abide by these style rule names, or provide entirely new ones. | ||
### Unsubscribe Facilities | ||
@@ -290,3 +299,3 @@ | ||
var client = campaign({ | ||
provider: campaign.providers.console() | ||
provider: campaign.providers.terminal() | ||
}); | ||
@@ -301,3 +310,3 @@ | ||
There are a few different providers you can use. The default provider sends mails through [Mandrill][1]. There is also a `console` logging provider, [explained above](#debugging), and a `nodemailer` provider, detailed below. | ||
There are a few different providers you can use. The default provider sends mails through [Mandrill][1]. There is also a `terminal` logging provider, [explained above](#debugging), and a `nodemailer` provider, detailed below. | ||
@@ -353,4 +362,27 @@ ### Using `nodemailer` | ||
If you decide to go for your own provider, `campaign` will still prove useful thanks to its templating features. | ||
If you decide to go for your own provider, `campaign` will still prove useful thanks to its templating features, which you can also extend! | ||
# Template Engines | ||
The default provider included with `campaign` allows us to render layouts and views using [`mustache`][6], but this behavior can be altered to use a custom templating engine. | ||
To create your own template engine, you'll need to implement the two methods below. | ||
```js | ||
{ | ||
render: function (file, model, done) { | ||
}, | ||
renderString: function (template, model, done) { | ||
} | ||
} | ||
``` | ||
The `done` callback takes an error as the first argument, and the resulting HTML as the second argument. | ||
# Contributing | ||
You're welcome to contribute to the development of `campaign`! Additional template engines and providers would be nice, and I'd encourage creating packages that solely contain that engine or email provider. For instance, you could create `campaign-jade`, or `campaign-postmark`. | ||
Hmmm, yeah. That'd be great! | ||
# License | ||
@@ -357,0 +389,0 @@ |
@@ -7,3 +7,3 @@ 'use strict'; | ||
var templateService = require('./templateService.js')(options.layout); | ||
var templateService = require('./templateService.js')(options.templateEngine, options.layout); | ||
var validation = require('./validationService.js')(options.trap); | ||
@@ -10,0 +10,0 @@ var hydrate = require('./hydrationService.js'); |
'use strict'; | ||
var moment = require('moment'); | ||
var mustacheService = require('./mustacheService.js'); | ||
module.exports = function (layout) { | ||
module.exports = function (engine, layout) { | ||
@@ -25,3 +24,3 @@ function getCallback (model, done) { | ||
mustacheService.render(layout, layoutModel, done); | ||
engine.render(layout, layoutModel, done); | ||
}; | ||
@@ -32,8 +31,8 @@ } | ||
render: function (file, model, done) { | ||
mustacheService.render(file, model, getCallback(model, done)); | ||
engine.render(file, model, getCallback(model, done)); | ||
}, | ||
renderString: function (template, model, done) { | ||
mustacheService.renderString(template, model, getCallback(model, done)); | ||
engine.renderString(template, model, getCallback(model, done)); | ||
} | ||
}; | ||
}; |
@@ -5,17 +5,15 @@ 'use strict'; | ||
var client = campaign({ | ||
from: 'nicolasbevacqua@gmail.com', | ||
trap: 'nicolasbevacqua@gmail.com', | ||
provider: campaign.providers.console() | ||
provider: campaign.providers.terminal() | ||
}); | ||
var template = '<p>Some {{data}}</p>'; | ||
var template = '<p>Your password reset key is: {{reset}}</p>'; | ||
var model = { | ||
to: 'foo@bar.com', | ||
subject: 'Awesome Things', | ||
data: 'interesting stuff' | ||
to: 'someone@important.com', | ||
subject: 'Password Reset', | ||
reset: 'q12jFbwJsCKm' | ||
}; | ||
client.sendString(template, model, done); | ||
function done () { | ||
console.log('Done!'); | ||
console.log('Done.'); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42445
395
392