diff --git a/lib/htmllint.js b/lib/htmllint.js new file mode 100644 index 0000000..2831782 --- /dev/null +++ b/lib/htmllint.js @@ -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); + }); +}; \ No newline at end of file diff --git a/tasks/html.js b/tasks/html.js index 80afbe8..c795688 100644 --- a/tasks/html.js +++ b/tasks/html.js @@ -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); @@ -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); - }); - }); - }; diff --git a/test/html_test.js b/test/html_test.js index 2ceda2b..179bb37 100644 --- a/test/html_test.js +++ b/test/html_test.js @@ -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; }