Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Replace htmllint helper with htmllint lib. Still depends on grunt as …

…grunt.utils.spawn is pretty convenient
  • Loading branch information...
commit 82670f843726e7228c910ba915176315d0ed3f02 1 parent 1e443ea
Jörn Zaefferer authored

Showing 3 changed files with 24 additions and 36 deletions. Show diff stats Hide diff stats

  1. +17 0 lib/htmllint.js
  2. +4 30 tasks/html.js
  3. +3 6 test/html_test.js
17 lib/htmllint.js
... ... @@ -0,0 +1,17 @@
  1 +module.exports = function(grunt, files, done) {
  2 + var jar = __dirname + '/../vnu.jar';
  3 + grunt.utils.spawn({
  4 + cmd: 'java',
  5 + args: ['-Dnu.validator.client.quiet=yes', '-jar', jar].concat(files)
  6 + }, function(error, output) {
  7 + if (error) {
  8 + done(error);
  9 + return;
  10 + }
  11 + var result = [];
  12 + if (output.stdout) {
  13 + result = output.stdout.split('\n');
  14 + }
  15 + done(null, result);
  16 + });
  17 +};
34 tasks/html.js
@@ -6,19 +6,15 @@
6 6 * Licensed under the MIT license.
7 7 */
8 8
9   -module.exports = function(grunt) {
10   -
11   - // Please see the grunt documentation for more information regarding task and
12   - // helper creation: https://github.com/cowboy/grunt/blob/master/docs/toc.md
  9 +var htmllint = require('../lib/htmllint');
13 10
14   - // ==========================================================================
15   - // TASKS
16   - // ==========================================================================
  11 +module.exports = function(grunt) {
17 12
18 13 grunt.registerMultiTask('htmllint', 'Validate html files', function() {
19 14 var done = this.async(),
20 15 files = grunt.file.expand(this.file.src);
21   - grunt.helper('htmllint', files, function(error, result) {
  16 +
  17 + htmllint(grunt, files, function(error, result) {
22 18 if (error) {
23 19 grunt.log.error(error);
24 20 done(false);
@@ -34,26 +30,4 @@ module.exports = function(grunt) {
34 30 });
35 31 });
36 32
37   - // ==========================================================================
38   - // HELPERS
39   - // ==========================================================================
40   -
41   - grunt.registerHelper('htmllint', function(files, done) {
42   - var jar = __dirname + '/../vnu.jar';
43   - grunt.utils.spawn({
44   - cmd: 'java',
45   - args: ['-Dnu.validator.client.quiet=yes', '-jar', jar].concat(files)
46   - }, function(error, output) {
47   - if (error) {
48   - done(error);
49   - return;
50   - }
51   - var result = [];
52   - if (output.stdout) {
53   - result = output.stdout.split('\n');
54   - }
55   - done(null, result);
56   - });
57   - });
58   -
59 33 };
9 test/html_test.js
... ... @@ -1,14 +1,11 @@
1   -var grunt = require('grunt');
  1 +var grunt = require('grunt'),
  2 + htmllint = require('../lib/htmllint');
2 3
3 4 exports['htmllint'] = {
4   - setUp: function(done) {
5   - // setup here
6   - done();
7   - },
8 5 'helper': function(test) {
9 6 test.expect(1);
10 7 // tests here
11   - grunt.helper('htmllint', ['test/valid.html', 'test/invalid.html'], function(error, result) {
  8 + htmllint(grunt, ['test/valid.html', 'test/invalid.html'], function(error, result) {
12 9 if (error) {
13 10 throw error;
14 11 }

0 comments on commit 82670f8

Please sign in to comment.
Something went wrong with that request. Please try again.