Skip to content

Commit

Permalink
Allow passing options to juice
Browse files Browse the repository at this point in the history
  • Loading branch information
kewisch committed Mar 14, 2015
1 parent d9a5016 commit dbf7a35
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/main.js
Expand Up @@ -74,8 +74,12 @@ var EmailTemplate = function(templateDirectory, defaults, done) {
text = results[1]
stylesheet = results[2]

// Make a copy of the juiceOptions object so we can add the stylesheet.
var juiceOptions = (typeof locals.juiceOptions === 'object' ? _.assign({}, locals.juiceOptions) : {})
juiceOptions.extraCss = (juiceOptions.extraCss || "") + stylesheet

// Inject available styles into HTML.
html = (stylesheet) ? juice(html, {extraCss: stylesheet}) : html
html = (stylesheet) ? juice(html, juiceOptions) : html

// Return a compressed buffer if needed.
if (isBuffer) {
Expand Down
21 changes: 21 additions & 0 deletions test/integration.js
Expand Up @@ -81,6 +81,27 @@ describe('Email templates', function() {
})
})

it('html with style element and juiceOptions', function(done) {
var html = '<style> h4 { color: red; }</style><h4><%= item%></h4>'
, css = 'h4 { color: blue; }';
fs.writeFileSync(path.join(templateDir, templateName, 'html.ejs'), html)
fs.writeFileSync(path.join(templateDir, templateName, 'style.ejs'), css)

var defaults = {
juiceOptions: { removeStyleTags: false }
}

emailTemplates(templateDir, defaults, function(err, template) {
template(templateName, { item: 'test' }, function(err, html, text) {
expect(err).to.be.null
expect(text).to.be.false
expect(html).to.equal(
'<style> h4 { color: red; }</style><h4 style=\"color: blue;\">test</h4>')
done()
});
});
});

it('html with inline CSS(ejs) and text file', function(done) {
var html = '<h4><%= item%></h4>'
, text = '<%= item%>'
Expand Down

0 comments on commit dbf7a35

Please sign in to comment.