email-templates
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -29,2 +29,6 @@ 'use strict'; | ||
var _assign = require('lodash/assign'); | ||
var _assign2 = _interopRequireDefault(_assign); | ||
var _util = require('./util'); | ||
@@ -172,7 +176,11 @@ | ||
if (_this5.options.sassOptions) { | ||
locals = (0, _assign2.default)({}, locals, _this5.options.sassOptions); | ||
} | ||
debug('Rendering stylesheet'); | ||
(0, _util.renderFile)(_this5.files.style, locals).then(function (style) { | ||
resolve((0, _util.renderFile)(_this5.files.style, locals)).then(function (style) { | ||
_this5.style = style; | ||
debug('Finished rendering stylesheet'); | ||
resolve(style); | ||
return style; | ||
}); | ||
@@ -179,0 +187,0 @@ }); |
@@ -116,4 +116,9 @@ 'use strict'; | ||
locals.data = source; | ||
locals.includePaths = [locals.templatePath]; | ||
if (locals.includePaths) { | ||
locals.includePaths = locals.includePaths.concat([locals.templatePath]); | ||
} else { | ||
locals.includePaths = [locals.templatePath]; | ||
} | ||
return new _bluebird2.default(function (done, reject) { | ||
@@ -120,0 +125,0 @@ sass.render(locals, function (err, data) { |
{ | ||
"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.1.0", | ||
"version": "2.2.0", | ||
"author": "Nick Baugh <niftylettuce@gmail.com>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -114,3 +114,3 @@ | ||
If your want to configure your template engine, just pass options. | ||
If you want to configure your template engine, just pass options. | ||
@@ -146,2 +146,10 @@ Want to use different opening and closing tags instead of the EJS's default `<%` and `%>`?. | ||
You can add includePaths for [sass][sass] using sassOptions. | ||
```javascript | ||
new EmailTemplate(templateDir, {sassOptions: { | ||
includePaths: ['~/someproject/sass'] | ||
}}) | ||
``` | ||
## Examples | ||
@@ -161,3 +169,3 @@ | ||
var user = {name: 'Joe', pasta: 'spaghetti'} | ||
newsletter.render(user, function (err, results) { | ||
newsletter.render(user, function (err, result) { | ||
// result.html | ||
@@ -174,3 +182,3 @@ // result.text | ||
async.each(users, function (user, next) { | ||
newsletter.render(user, function (err, results) { | ||
newsletter.render(user, function (err, result) { | ||
if (err) return next(err) | ||
@@ -177,0 +185,0 @@ // result.html |
@@ -6,2 +6,3 @@ import P from 'bluebird' | ||
import isFunction from 'lodash/isFunction' | ||
import assign from 'lodash/assign' | ||
import {ensureDirectory, readContents, renderFile} from './util' | ||
@@ -124,8 +125,12 @@ | ||
if (this.options.sassOptions) { | ||
locals = assign({}, locals, this.options.sassOptions) | ||
} | ||
debug('Rendering stylesheet') | ||
renderFile(this.files.style, locals) | ||
resolve(renderFile(this.files.style, locals)) | ||
.then((style) => { | ||
this.style = style | ||
debug('Finished rendering stylesheet') | ||
resolve(style) | ||
return style | ||
}) | ||
@@ -132,0 +137,0 @@ }) |
@@ -101,4 +101,9 @@ /** | ||
locals.data = source | ||
locals.includePaths = [locals.templatePath] | ||
if (locals.includePaths) { | ||
locals.includePaths = locals.includePaths.concat([locals.templatePath]) | ||
} else { | ||
locals.includePaths = [locals.templatePath] | ||
} | ||
return new P(function (done, reject) { | ||
@@ -105,0 +110,0 @@ sass.render(locals, function (err, data) { |
@@ -9,2 +9,3 @@ /* global describe it beforeEach afterEach */ | ||
var templatePath = path.join(__dirname, '..', '.test-templates', 'test-template') | ||
var sassPath = path.join(__dirname, '..', '.test-templates', '.sass-files') | ||
var P = require('bluebird') | ||
@@ -122,3 +123,56 @@ | ||
}) | ||
describe('when include sass from another directory', function () { | ||
beforeEach(function (done) { | ||
// Setup the sass directory structure. | ||
mkdirp(sassPath, done) | ||
}) | ||
afterEach(function (done) { | ||
// Destroy the sass directory structure. | ||
rimraf(sassPath, done) | ||
}) | ||
it('html with the included sass directory', function (done) { | ||
var html = '<h4><%= item %></h4>' | ||
var includeCss = 'h4 { color: red; }' | ||
var css = '@import "includes.scss"' | ||
fs.writeFileSync(path.join(templatePath, 'html.ejs'), html) | ||
fs.writeFileSync(path.join(sassPath, 'includes.scss'), includeCss) | ||
fs.writeFileSync(path.join(templatePath, 'style.scss'), css) | ||
var et = new EmailTemplate(templatePath, { | ||
sassOptions: { includePaths: [sassPath] } | ||
}) | ||
et.render({ item: 'test' }) | ||
.then(function (results) { | ||
expect(results.html).to.equal( | ||
'<h4 style=\"color: red;\">test</h4>') | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
}) | ||
it('should reject if the style can’t be compiled', function (done) { | ||
var html = '<h4><%= item %></h4>' | ||
var css = 'h4 { <%=color: blue; }' | ||
fs.writeFileSync(path.join(templatePath, 'html.ejs'), html) | ||
fs.writeFileSync(path.join(templatePath, 'style.ejs'), css) | ||
var et = new EmailTemplate(templatePath, { | ||
juiceOptions: { removeStyleTags: false } | ||
}) | ||
et.render({ item: 'test' }) | ||
.then(function (results) { | ||
done(new Error('Should not be reached')) | ||
}, function () { | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) |
@@ -7,2 +7,3 @@ /* global describe it beforeEach afterEach */ | ||
var tmpDir = path.join(__dirname, '..', '.test-templates') | ||
var tmpSassDir = path.join(__dirname, '..', '.test-sass') | ||
var mkdirp = require('mkdirp') | ||
@@ -15,3 +16,5 @@ var rimraf = require('rimraf') | ||
// Setup a tmp directory for test files. | ||
mkdirp(tmpDir, done) | ||
mkdirp(tmpDir, () => { | ||
mkdirp(tmpSassDir, done) | ||
}) | ||
}) | ||
@@ -21,3 +24,5 @@ | ||
// Destroy all test files. | ||
rimraf(tmpDir, done) | ||
rimraf(tmpDir, () => { | ||
rimraf(tmpSassDir, done) | ||
}) | ||
}) | ||
@@ -215,2 +220,22 @@ | ||
it('should allow a custom include path for rendering sass', function (done) { | ||
var testMainSassFile = path.join(tmpDir, 'main.scss') | ||
var testIncludesFile = path.join(tmpSassDir, 'includes.scss') | ||
// Write out some test SASS files. | ||
fs.writeFileSync(testMainSassFile, '@import "includes.scss";') | ||
fs.writeFileSync(testIncludesFile, 'body { color: #333}') | ||
var file = { | ||
filename: testMainSassFile, | ||
content: fs.readFileSync(testMainSassFile).toString() | ||
} | ||
tm.render(file, {includePaths: ['.test-sass']}, function (err, res) { | ||
expect(err).to.be.null | ||
expect(res).to.equal('body {\n color: #333; }\n') | ||
done() | ||
}) | ||
}) | ||
it('should render css', function (done) { | ||
@@ -217,0 +242,0 @@ var file = { |
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
239646
1908
281