Skip to content

Commit

Permalink
Added a submenu to update the W3C validation manually
Browse files Browse the repository at this point in the history
  • Loading branch information
valx76 committed Aug 28, 2014
1 parent fb84bd4 commit dccedda
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 44 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
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
61 changes: 37 additions & 24 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,67 @@

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

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

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;
}
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();

}
response.resolve(result);
});

return response.promise();
}

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

AppInit.appReady(function () {


CodeInspection.register("html", {
name: "W3CValidation",
//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
Original file line number Diff line number Diff line change
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
32 changes: 14 additions & 18 deletions w3cvalidator.js
Original file line number Diff line number Diff line change
@@ -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 dccedda

Please sign in to comment.