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

Commit

Permalink
Merge branch 'release/0.2.12'
Browse files Browse the repository at this point in the history
  • Loading branch information
dwightjack committed Mar 2, 2015
2 parents a1dd944 + 6eda489 commit 6060bd4
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 14 deletions.
6 changes: 6 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ module.exports = function(grunt) {
files: {
'tmp/email-mq.html': ['<%= paths.fixtures %>/email-mq.html'],
}
},

overwrite: {
files: {
'<%= paths.fixtures %>/email-overwrite.html': ['<%= paths.fixtures %>/email-overwrite.html'],
}
}
},

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This plugin is a [Grunt](http://gruntjs.com/) wrapper around the [Premailer](ht

* Node.js >= 0.10.0 ([install wiki](https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager))
* Grunt-cli >= 0.1.7 and Grunt >=0.4.2 (`npm install grunt-cli -g`)
* Ruby >= 1.8.7 ([installers](http://www.ruby-lang.org/en/downloads/))
* Ruby >= 1.9.3 ([installers](http://www.ruby-lang.org/en/downloads/))
* Premailer >= 1.8.0 (`gem install premailer` and, most of the time, `gem install hpricot`)

## Getting Started
Expand Down Expand Up @@ -169,6 +169,8 @@ In lieu of a formal styleguide, take care to maintain the existing coding style.

## Release History

0.2.12 Dependencies updated. Fixing a bug when source and destination files are the same (#25)

0.2.11 Fixing EventEmitter error (#21)

0.2.10 Merging #20 (thanks to @Iszak)
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grunt-premailer",
"description": "Grunt wrapper task for premailer",
"version": "0.2.11",
"version": "0.2.12",
"homepage": "https://github.com/dwightjack/grunt-premailer",
"author": {
"name": "Marco Solazzi",
Expand All @@ -23,14 +23,14 @@
],
"main": "Gruntfile.js",
"engines": {
"node": ">= 0.8.0"
"node": ">= 0.10.0"
},
"scripts": {
"test": "grunt test",
"postinstall": "node lib/postinstall.js"
},
"devDependencies": {
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-jshint": "~0.11.0",
"grunt-contrib-clean": "~0.6.0",
"grunt-contrib-nodeunit": "~0.4.1",
"grunt": "~0.4.5"
Expand All @@ -43,10 +43,10 @@
],
"dependencies": {
"async": "~0.9.0",
"chalk": "~0.5.1",
"dargs": "~3.0.0",
"chalk": "~1.0.0",
"dargs": "~4.0.0",
"is-utf8": "^0.2.0",
"lodash": "~2.4.1",
"semver": "~4.1.0"
"lodash": "~3.3.1",
"semver": "~4.3.1"
}
}
23 changes: 19 additions & 4 deletions tasks/premailer.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ module.exports = function(grunt) {
// Concat specified files.
var srcFile,
batchArgs,
premailer;

grunt.file.write(f.dest,''); // Create empty destination file
premailer,
tmpFile;

srcFile = f.src.filter(function (f) {
return grunt.file.isFile(f);
Expand All @@ -109,14 +108,24 @@ module.exports = function(grunt) {
grunt.log.writeln('Input file not found');
next(null);
}

if (!isUtf8(fs.readFileSync(srcFile))) {
//skip!
grunt.log.writeln('Input file must have utf8 encoding');
next(null);
}

if (srcFile === f.dest) {
//generate a temp dest file
tmpFile = path.join(path.dirname(f.dest), _.uniqueId('.premailer-') + '.tmp');
grunt.file.write(tmpFile, '');
grunt.verbose.writeln('Creating temporary file ' + tmpFile);
} else {
grunt.file.write(f.dest, ''); // Create empty destination file
}

// Premailer expects absolute paths
batchArgs = args.concat(['--file-in', path.resolve(srcFile.toString()), '--file-out', path.resolve(f.dest.toString())]);
batchArgs = args.concat(['--file-in', path.resolve(srcFile.toString()), '--file-out', path.resolve((tmpFile || f.dest).toString())]);

premailer = grunt.util.spawn({
cmd: cmd,
Expand All @@ -125,6 +134,12 @@ module.exports = function(grunt) {
if (err) {
grunt.fail.fatal(err);
}
if (tmpFile) {
grunt.file.copy(tmpFile, f.dest);
grunt.file.delete(tmpFile);
grunt.verbose.writeln('Removing temporary file ' + tmpFile);

}

next(err);
});
Expand Down
27 changes: 27 additions & 0 deletions test/fixtures/email-overwrite.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="UTF-8">
<title>Test Email</title>


</head>

<body style="color: red">
<style type="text/css">
body {
color: red;
}
</style>





<div id="test-el">test message</div>

<p>Message with accentéd chàrs</p>

</body>
</html>
13 changes: 11 additions & 2 deletions test/premailer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ exports.premailer = {
test.expect(1);

var actual = grunt.file.read('tmp/email.html');
test.ok(actual.indexOf('<body style="color: red;">') !== -1, 'Test CSS style is inline.');
test.ok(actual.indexOf('<body style="color: red') !== -1, 'Test CSS style is inline.');

test.done();
},
Expand Down Expand Up @@ -96,5 +96,14 @@ exports.premailer = {
test.ok(actual.indexOf('@media only screen and (max-width: 600px)') > 0, "Media Queries are preserved");
test.ok(actual.indexOf('@media only screen and (min-width: 400px)') > 0, "Media Queries from external files are preserved");
test.done();
}
},

overwrite: function(test) {
test.expect(1);

var actual = grunt.file.read('test/fixtures/email-overwrite.html');
test.ok(actual.indexOf('<body style="color: red') !== -1, 'Content is preserved.');

test.done();
},
};

0 comments on commit 6060bd4

Please sign in to comment.