Skip to content
This repository was archived by the owner on Jun 5, 2019. It is now read-only.

Commit 268a21f

Browse files
committed
First Release
0 parents  commit 268a21f

File tree

7 files changed

+261
-0
lines changed

7 files changed

+261
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
test/
3+
build/
4+
package-lock.json

gulpfile.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
const gulp = require('gulp'),
4+
composer = require('gulp-uglify/composer'),
5+
zip = require('gulp-zip');
6+
const del = require('del'),
7+
exec = require('child_process').exec,
8+
uglifyes = require('uglify-es'),
9+
merge = require('event-stream').merge;
10+
const pkgInfo = require('./package.json'),
11+
uglify = composer(uglifyes, console);
12+
13+
gulp.task('clean', () => del(['build/']));
14+
15+
gulp.task('resolve:node-deps', () => exec('cd ./node && npm install && npm update'));
16+
17+
gulp.task('build', ['clean', 'resolve:node-deps'], () => {
18+
let copy = gulp.src(['package.json', 'node/node_modules/**/*'], {base: '.'}).pipe(gulp.dest('build'));
19+
let minify = gulp.src(['main.js', 'node/*.js'], {base: '.'})
20+
.pipe(uglify({}))
21+
.pipe(gulp.dest('build'));
22+
23+
return merge(copy, minify).on('end', () =>
24+
gulp.src('build/**/*', {base: 'build'})
25+
.pipe(zip(`${pkgInfo.name}-${pkgInfo.version}.zip`))
26+
.pipe(gulp.dest('build/dist')));
27+
});
28+
29+
gulp.task('default', ['build']);

main.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
2+
/*global define, brackets, $ */
3+
4+
define(function (require, exports, module) {
5+
'use strict';
6+
7+
const NodeDomain = brackets.getModule('utils/NodeDomain'),
8+
ExtensionUtils = brackets.getModule('utils/ExtensionUtils'),
9+
CodeInspection = brackets.getModule('language/CodeInspection'),
10+
AppInit = brackets.getModule('utils/AppInit'),
11+
Menus = brackets.getModule('command/Menus'),
12+
CommandManager = brackets.getModule('command/CommandManager'),
13+
DocumentManager = brackets.getModule('document/DocumentManager');
14+
15+
const w3cvalidatorSever = new NodeDomain('w3cvalidator', ExtensionUtils.getModulePath(module, 'node/ValidationServer'));
16+
17+
const COMMAND_ID = 'w3cvalidator.refresh',
18+
PROVIDER_ID = 'w3cvalidator';
19+
20+
//var Strings = require("strings");
21+
22+
/**
23+
* Validation Server launcher in standalone
24+
*/
25+
function runServer() {
26+
w3cvalidatorSever.exec('runServer');
27+
}
28+
29+
/**
30+
* Validation handler as a client
31+
*/
32+
function handleValidation(text, fullPath) {
33+
let response = $.Deferred();
34+
let result = {
35+
errors: []
36+
};
37+
38+
$.ajax({
39+
url: "http://localhost:8888/?out=json",
40+
type: 'POST',
41+
contentType: 'text/html; charset=utf-8',
42+
data: text,
43+
cache: false,
44+
processData: false
45+
}).done(function (data, textStatus, jqXHR) {
46+
let messages = data.messages;
47+
48+
if (messages.length) {
49+
messages.forEach(function (item) {
50+
let type;
51+
switch (item.type) {
52+
case 'warning':
53+
type = CodeInspection.Type.WARNING;
54+
break;
55+
case 'error':
56+
type = CodeInspection.Type.ERROR;
57+
break;
58+
}
59+
60+
result.errors.push({
61+
pos: {
62+
line: item.lastLine - 1,
63+
ch: 0
64+
},
65+
message: item.message,
66+
type: type
67+
});
68+
});
69+
}
70+
71+
response.resolve(result);
72+
});
73+
74+
return response.promise();
75+
}
76+
77+
// Listen a file saved event
78+
function refreshValidation() {
79+
DocumentManager.getCurrentDocument().notifySaved();
80+
}
81+
82+
// Register the HTML Linting
83+
AppInit.appReady(function () {
84+
CodeInspection.register("html", {
85+
name: PROVIDER_ID,
86+
scanFileAsync: handleValidation
87+
});
88+
});
89+
90+
// Command
91+
//CommandManager.register(Strings.REFRESH_W3C_VALIDATION, COMMAND_ID, _refreshValidation);
92+
CommandManager.register("Refresh W3C validation", COMMAND_ID, refreshValidation);
93+
94+
// Menu
95+
const editMenu = Menus.getMenu(Menus.AppMenuBar.EDIT_MENU);
96+
editMenu.addMenuItem(COMMAND_ID, "F9");
97+
98+
// Server launcher when extension is loaded
99+
runServer();
100+
});

node/ValidationServer.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50, node: true */
2+
/*global $, require */
3+
4+
(function () {
5+
'use strict';
6+
7+
const exec = require('child_process').exec,
8+
vnu = require('vnu-jar');
9+
10+
/**
11+
* @private
12+
* Handler function for the w3cvalidator.validate command.
13+
*/
14+
function runServer() {
15+
exec(`java -Xss1m -cp ${vnu} nu.validator.servlet.Main 8888`);
16+
}
17+
18+
/**
19+
* Initializes the test domain with several test commands.
20+
* @param {DomainManager} domainManager The DomainManager for the server
21+
*/
22+
function init(domainManager) {
23+
if (!domainManager.hasDomain('w3cvalidator')) {
24+
domainManager.registerDomain('w3cvalidator', {
25+
major: 0,
26+
minor: 1
27+
});
28+
}
29+
30+
domainManager.registerCommand(
31+
'w3cvalidator',
32+
'runServer',
33+
runServer,
34+
false,
35+
'Runs the validation server in standalone.'
36+
);
37+
}
38+
39+
exports.init = init;
40+
}());

node/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"private": true,
3+
"dependencies": {
4+
"vnu-jar": "latest"
5+
}
6+
}

node/w3cvalidator.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50, node: true */
2+
/*global */
3+
4+
(function () {
5+
'use strict';
6+
7+
const exec = require('child_process').execSync,
8+
vnu = require('vnu-jar');
9+
10+
/**
11+
* @private
12+
* Handler function for the w3cvalidator.validate command.
13+
* @param {string} the file path for verification
14+
* @return {string} the validation report
15+
*/
16+
function validate(path) {
17+
exec(`java -Xss2m -jar ${vnu} --format text --skip-non-html ${path}`, (error, stdout, stderr) => {
18+
console.log('stdout: ' + stdout);
19+
console.log('stderror: ' + stderr);
20+
21+
return stderr;
22+
});
23+
}
24+
25+
/**
26+
* Initializes the test domain with several test commands.
27+
* @param {DomainManager} domainManager The DomainManager for the server
28+
*/
29+
function init(domainManager) {
30+
if (!domainManager.hasDomain('w3cvalidator')) {
31+
domainManager.registerDomain('w3cvalidator', {
32+
major: 0,
33+
minor: 1
34+
});
35+
}
36+
37+
domainManager.registerCommand(
38+
'w3cvalidator',
39+
'validate',
40+
validate,
41+
true,
42+
'Returns the validation report of a file', [{
43+
name: 'path',
44+
type: 'string',
45+
description: 'the file path for verification'
46+
}], [{
47+
name: 'report',
48+
type: 'string',
49+
description: 'validation report in JSON format'
50+
}]
51+
);
52+
}
53+
54+
exports.init = init;
55+
}());

package.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "umoxfo.w3cvalidation",
3+
"title": "W3C Validation (by Umoxfo)",
4+
"version": "1.0.0",
5+
"description": "Adds W3C validation support to Brackets.",
6+
"homepage": "",
7+
"keywords": [
8+
"html",
9+
"lint",
10+
"linting",
11+
"linter"
12+
],
13+
"categories": "linting",
14+
"author": "Makoto Sakaguchi <[email protected]>",
15+
"license": "MIT",
16+
"engines": {
17+
"brackets": ">=0.24.0"
18+
},
19+
"devDependencies": {
20+
"gulp": "latest",
21+
"gulp-uglify": "latest",
22+
"gulp-zip": "latest",
23+
"del": "latest",
24+
"uglify-es": "latest",
25+
"event-stream": "latest"
26+
}
27+
}

0 commit comments

Comments
 (0)