email-templates
Advanced tools
Comparing version 2.0.0-beta.4 to 2.0.0
{ | ||
"name": "email-templates", | ||
"description": "Node.js module for rendering beautiful emails with ejs, jade, swig, hbs, or handlebars templates and email-friendly inline CSS using juice.", | ||
"version": "2.0.0-beta.4", | ||
"version": "2.0.0", | ||
"author": "Nick Baugh <niftylettuce@gmail.com>", | ||
@@ -54,5 +54,5 @@ "contributors": [ | ||
"prepublish": "npm run compile && npm prune", | ||
"compile": "babel src --modules common --out-dir lib", | ||
"watch": "babel src --watch --modules common --out-dir lib --source-maps true", | ||
"test": "mocha", | ||
"compile": "node_modules/.bin/babel src --modules common --out-dir lib", | ||
"watch": "node_modules/.bin/babel src --watch --modules common --out-dir lib --source-maps true", | ||
"test": "node_modules/.bin/standard && node_modules/.bin/mocha", | ||
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot", | ||
@@ -88,2 +88,3 @@ "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly" | ||
"sinon-chai": "^2.7.0", | ||
"standard": "^4.5.2", | ||
"styl": "^0.2.7", | ||
@@ -93,2 +94,8 @@ "stylus": "^0.51.1", | ||
}, | ||
"standard": { | ||
"ignore": [ | ||
"lib", | ||
"examples" | ||
] | ||
}, | ||
"license": "MIT", | ||
@@ -95,0 +102,0 @@ "bugs": { |
125
Readme.md
@@ -85,10 +85,9 @@ | ||
- `ejs@^2.0.0` | ||
- `jade@^1.9.0` | ||
- `swig@^1.4.2` | ||
- `jade@^1.0.0` | ||
- `swig@^1.0.0` | ||
- `handlebars@^3.0.0` | ||
- `dust-linkedin@^2.7.0` | ||
- `less@^2.5.0` | ||
- `stylus@^^0.51.0` | ||
- `styl@^0.2.9` | ||
- `dust-linkedin@^2.0.0` | ||
- `less@^2.0.0` | ||
- `stylus@^0.51.0` | ||
- `styl@^0.2.0` | ||
- `node-sass@^3.0.0` | ||
@@ -125,24 +124,28 @@ | ||
```javascript | ||
emailTemplates(templatesDir, { delimiter: '?' }, function (err, template) { | ||
new EmailTemplate(templateDir, { delimiter: '?' }) | ||
``` | ||
> You can also pass <a href="https://github.com/mde/ejs#options" target="_blank">other options from EJS's documentation</a>. | ||
> You can also directly modify the template engine | ||
Want to add a helper or partial to Handlebars? | ||
```js | ||
```javascript | ||
// ... | ||
emailTemplates(templatesDir, { | ||
helpers: { | ||
uppercase: function(context) { | ||
return context.toUpperCase() | ||
} | ||
}, partials: { | ||
// ... | ||
} | ||
Handlebars.registerPartial('name', '{{name.first}} {{name.last}}') | ||
Handlebars.registerHelper('capitalize', function (context) { | ||
return context.toUpperCase() | ||
}) | ||
new EmailTemplate(templateDir) | ||
// ... | ||
``` | ||
You can also pass a `juiceOptions` object to configure the output from [juice][juice] | ||
```javascript | ||
new EmailTemplate(templateDir, {juiceOptions: { | ||
preserveMediaQueries: false, | ||
removeStyleTags: false | ||
}}) | ||
``` | ||
You can check all the options in [juice's documentation](https://github.com/automattic/juice#options) | ||
## Examples | ||
@@ -154,3 +157,3 @@ | ||
```js | ||
```javascript | ||
var EmailTemplate = require('email-templates').EmailTemplate | ||
@@ -185,60 +188,38 @@ var path = require('path') | ||
Render a template for a single email or render multiple (having only loaded the template once). | ||
Render a template for a single email or render multiple (having only loaded the template once) using Promises. | ||
```js | ||
var path = require('path') | ||
var templatesDir = path.join(__dirname, 'templates') | ||
var emailTemplates = require('email-templates'); | ||
var templateDir = path.join(__dirname, 'templates', 'pasta-dinner') | ||
var EmailTemplate = require('email-templates').EmailTemplate | ||
emailTemplates(templatesDir, function(err, template) { | ||
// Render a single email with one template | ||
var locals = { pasta: 'Spaghetti' }; | ||
template('pasta-dinner', locals, function(err, html, text) { | ||
// ... | ||
}); | ||
// Render multiple emails with one template | ||
var locals = [ | ||
{ pasta: 'Spaghetti' }, | ||
{ pasta: 'Rigatoni' } | ||
]; | ||
var Render = function(locals) { | ||
this.locals = locals; | ||
this.send = function(err, html, text) { | ||
// ... | ||
}; | ||
this.batch = function(batch) { | ||
batch(this.locals, templatesDir, this.send); | ||
}; | ||
}; | ||
// An example users object | ||
var users = [ | ||
{ | ||
email: 'pappa.pizza@spaghetti.com', | ||
name: { | ||
first: 'Pappa', | ||
last: 'Pizza' | ||
} | ||
}, | ||
{ | ||
email: 'mister.geppetto@spaghetti.com', | ||
name: { | ||
first: 'Mister', | ||
last: 'Geppetto' | ||
} | ||
var template = new EmailTemplate(templateDir) | ||
var users = [ | ||
{ | ||
email: 'pappa.pizza@spaghetti.com', | ||
name: { | ||
first: 'Pappa', | ||
last: 'Pizza' | ||
} | ||
]; | ||
template('pasta-dinner', true, function(err, batch) { | ||
for(var user in users) { | ||
var render = new Render(users[user]); | ||
render.batch(batch); | ||
}, | ||
{ | ||
email: 'mister.geppetto@spaghetti.com', | ||
name: { | ||
first: 'Mister', | ||
last: 'Geppetto' | ||
} | ||
}); | ||
} | ||
] | ||
}); | ||
var templates = users.map(function (user) { | ||
return template.render(user) | ||
}) | ||
Promise.all(templates) | ||
.then(function (results) { | ||
console.log(results[0].html) | ||
console.log(results[0].text) | ||
console.log(results[1].html) | ||
console.log(results[1].text) | ||
}) | ||
``` | ||
@@ -245,0 +226,0 @@ |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
238241
22
280