Skip to content

Commit

Permalink
Merge pull request #16 from valx76/master
Browse files Browse the repository at this point in the history
Added a submenu to update the W3C validation manually
  • Loading branch information
cfjedimaster committed Sep 1, 2014
2 parents fb84bd4 + 109a85e commit f67bef7
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 68 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -8,7 +8,9 @@ or the yellow warning sign (issues). Clicking the icon will open a panel with
the current issues.

Issues/Updates
=====
=====
[8/28/2014] Added a submenu (under "Edit") to update the W3C validation (fixed bug when connection lost).

[5/19/2014] Removed an annoying console message.

[4/15/2014] Requires Brackets Sprint 38. Supports sexy new async linting.
Expand Down
111 changes: 62 additions & 49 deletions main.js
Expand Up @@ -2,55 +2,68 @@
/*global define, brackets, $, window, W3CValidator */

define(function (require, exports, module) {
'use strict';

var CodeInspection = brackets.getModule("language/CodeInspection"),
AppInit = brackets.getModule("utils/AppInit");
'use strict';

require('w3cvalidator');

function _handleValidation(text, fullPath) {
var response = new $.Deferred();
var result = {errors:[]};

W3CValidator.validate(text, function (res) {
var messages = res.messages;

if (messages.length) {

messages.forEach(function (item) {
//console.log('W3CValidation messsage ',item);
var type = CodeInspection.Type.ERROR;
if (item.type === "warning") {
type = CodeInspection.Type.WARNING;
}
result.errors.push({
pos: {line:item.lastLine-1, ch:0},
message:item.message,
type:type
});

});

}
var CodeInspection = brackets.getModule("language/CodeInspection"),
AppInit = brackets.getModule("utils/AppInit"),
Menus = brackets.getModule("command/Menus"),
CommandManager = brackets.getModule("command/CommandManager"),
DocumentManager = brackets.getModule("document/DocumentManager");

var COMMAND_ID = "w3cvalidator_refresh",
PROVIDER_ID = "W3CValidation";


require('w3cvalidator');

function _handleValidation(text, fullPath) {
var response = new $.Deferred();
var result = {errors:[]};

W3CValidator.validate(text, function (res) {
var messages = res.messages;

if (messages.length) {
messages.forEach(function (item) {
//console.log('W3CValidation messsage ',item);
var type = CodeInspection.Type.ERROR;

if (item.type === "warning")
type = CodeInspection.Type.WARNING;

result.errors.push({
pos: {line:item.lastLine-1, ch:0},
message:item.message,
type:type
});

});
}

response.resolve(result);

});

return response.promise();

}

AppInit.appReady(function () {


CodeInspection.register("html", {
name: "W3CValidation",
scanFileAsync: _handleValidation
});

});


response.resolve(result);
});

return response.promise();
}

function _refreshValidation() {
var currentDoc = DocumentManager.getCurrentDocument();
currentDoc.notifySaved();
}

AppInit.appReady(function () {
CodeInspection.register("html", {
//name: "W3CValidation",
name: PROVIDER_ID,
scanFileAsync: _handleValidation
});
});


// Command
CommandManager.register("Refresh W3C validation", COMMAND_ID, _refreshValidation);

// Menu
var editMenu = Menus.getMenu(Menus.AppMenuBar.EDIT_MENU);
editMenu.addMenuItem(COMMAND_ID);
});
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -5,7 +5,7 @@
"homepage": "https://github.com/cfjedimaster/brackets-w3cvalidation",
"keywords":["lint","linting","linter"],
"categories":"linting",
"version": "2.1.1",
"version": "2.1.2",
"author": "Raymond Camden <raymondcamden@gmail.com> (http://www.raymondcamden.com)",
"license": "MIT",
"engines": {
Expand Down
30 changes: 13 additions & 17 deletions w3cvalidator.js
@@ -1,18 +1,14 @@
var W3CValidator = (function() {

var W3CURL = "http://validator.w3.org/check";

return {

validate:function(str,cb) {
$.post(W3CURL, {
"fragment":str,
"output":"json"
}, function(res,code) {
cb(res);
});
}

var W3CValidator = (function() {
var W3CURL = "http://validator.w3.org/check";

return {
validate:function(str,cb) {
$.post(W3CURL, {
"fragment":str,
"output":"json"
}, function(res,code) {
cb(res);
});
}
};

}());
}());

0 comments on commit f67bef7

Please sign in to comment.