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

Various rolled up fixes #43

Merged
merged 6 commits into from
Feb 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,27 @@ module.exports = function(grunt) {
inlinecss: {
basic: {
options: {
extraCss: 'body { background: green; }'
extraCss: 'body { background: green; }',
},
files: {
'tmp/out.html': 'test/fixtures/in.html'
},
},
with_important: {
options: {
extraCss: 'body { background: green; }',
preserveImportant: true
},
files: {
'tmp/out_with_important.html': 'test/fixtures/in.html'
},
},
does_not_exist: {
options: {},
files: {
'tmp/out_does_not_exist.html': 'test/fixtures/in_does_not_exist.html'
},
}
},

// Unit tests.
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@
"test": "grunt test"
},
"devDependencies": {
"grunt-contrib-jshint": "~0.7.1",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-nodeunit": "~0.2.2",
"grunt": "~0.4.0"
"grunt-contrib-jshint": "~1.1.0",
"grunt-contrib-clean": "~1.0.0",
"grunt-contrib-nodeunit": "~1.0.0",
"grunt": "~1.0.1"
},
"peerDependencies": {
"grunt": "~0.4.0"
"grunt": ">=0.4.0"
},
"keywords": [
"gruntplugin"
],
"dependencies": {
"juice": "~1.2.0"
"juice": "~4.0.2"
}
}
23 changes: 16 additions & 7 deletions tasks/inline_css.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,44 @@ module.exports = function(grunt) {
var index = 0;
var count = this.files.length;

var increaseCount = function () {
index++;
if (index === count) {
done();
}
};

// Iterate over all specified file groups.
this.files.forEach(function(f) {

var filepath = f.src.toString();
if (typeof filepath !== 'string' || filepath === '') {
grunt.log.error('src must be a single string');
increaseCount();
return false;
}

if (!grunt.file.exists(filepath)) {
grunt.log.error('Source file "' + filepath + '" not found.');
increaseCount();
return false;
}

grunt.log.writeln("filepath:", filepath);

juice.juiceFile(filepath, options, function(err, html) {

if (err) {
return grunt.log.error(err);
grunt.log.error(err);
increaseCount();

return;
}

grunt.file.write(f.dest, html);
grunt.log.writeln('File "' + f.dest + '" created.');


index++;
if (index === count) {
done();
}

increaseCount();
});

});
Expand Down
2 changes: 1 addition & 1 deletion test/expected/out.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

</head>
<body style="font-family: Test, 'Segoe UI', Arial; background: green;">
<h1 style="border: 1px solid #ccc; color: blue;">Hi</h1>
<h1 style="border: 1px solid #ccc; color: blue; font-family: Arial;">Hi</h1>
<table>
<tr>
<td class="headline" style="padding: 5px; font-size: 24px;">Some Headline</td>
Expand Down
15 changes: 15 additions & 0 deletions test/expected/out_with_important.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<html>
<head>


</head>
<body style="font-family: Test, 'Segoe UI', Arial; background: green;">
<h1 style="border: 1px solid #ccc; color: blue; font-family: Arial !important;">Hi</h1>
<table>
<tr>
<td class="headline" style="padding: 5px; font-size: 24px;">Some Headline</td>
</tr>
</table>
</body>
</html>
1 change: 1 addition & 0 deletions test/fixtures/file.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ body {
}
h1 {
color: blue;
font-family: Arial !important;
}
.headline {
font-size: 24px;
Expand Down
27 changes: 27 additions & 0 deletions test/inline_css_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,32 @@ exports.inline_css = {
test.equal(actual, expected, 'should inline css');

test.done();
},

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

var actual = grunt.file.read('tmp/out_with_important.html');
var expected = grunt.file.read('test/expected/out_with_important.html');
test.equal(actual, expected, 'should inline css');

test.done();
},

does_not_exist: function(test) {
test.expect(0);

try {
var actual = grunt.file.read('tmp/out_does_not_exist.html');
} catch(err) {

if (err.origError.code === 'ENOENT') {
return test.done();
}

return test.done(new Error('Should have errored with a file not found: ' + err.code));
}

test.done(new Error('Should have errored'));
}
};