Skip to content

Commit

Permalink
Replace htmllint helper with htmllint lib. Still depends on grunt as …
Browse files Browse the repository at this point in the history
…grunt.utils.spawn is pretty convenient
  • Loading branch information
jzaefferer committed Oct 12, 2012
1 parent 1e443ea commit 82670f8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 36 deletions.
17 changes: 17 additions & 0 deletions lib/htmllint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = function(grunt, files, done) {
var jar = __dirname + '/../vnu.jar';
grunt.utils.spawn({
cmd: 'java',
args: ['-Dnu.validator.client.quiet=yes', '-jar', jar].concat(files)
}, function(error, output) {
if (error) {
done(error);
return;
}
var result = [];
if (output.stdout) {
result = output.stdout.split('\n');
}
done(null, result);
});
};
34 changes: 4 additions & 30 deletions tasks/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@
* Licensed under the MIT license.
*/

module.exports = function(grunt) {

// Please see the grunt documentation for more information regarding task and
// helper creation: https://github.com/cowboy/grunt/blob/master/docs/toc.md
var htmllint = require('../lib/htmllint');

// ==========================================================================
// TASKS
// ==========================================================================
module.exports = function(grunt) {

grunt.registerMultiTask('htmllint', 'Validate html files', function() {
var done = this.async(),
files = grunt.file.expand(this.file.src);
grunt.helper('htmllint', files, function(error, result) {

htmllint(grunt, files, function(error, result) {
if (error) {
grunt.log.error(error);
done(false);
Expand All @@ -34,26 +30,4 @@ module.exports = function(grunt) {
});
});

// ==========================================================================
// HELPERS
// ==========================================================================

grunt.registerHelper('htmllint', function(files, done) {
var jar = __dirname + '/../vnu.jar';
grunt.utils.spawn({
cmd: 'java',
args: ['-Dnu.validator.client.quiet=yes', '-jar', jar].concat(files)
}, function(error, output) {
if (error) {
done(error);
return;
}
var result = [];
if (output.stdout) {
result = output.stdout.split('\n');
}
done(null, result);
});
});

};
9 changes: 3 additions & 6 deletions test/html_test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
var grunt = require('grunt');
var grunt = require('grunt'),
htmllint = require('../lib/htmllint');

exports['htmllint'] = {
setUp: function(done) {
// setup here
done();
},
'helper': function(test) {
test.expect(1);
// tests here
grunt.helper('htmllint', ['test/valid.html', 'test/invalid.html'], function(error, result) {
htmllint(grunt, ['test/valid.html', 'test/invalid.html'], function(error, result) {
if (error) {
throw error;
}
Expand Down

0 comments on commit 82670f8

Please sign in to comment.