2016-02-22 06:14:17 +01:00
|
|
|
var syntaxErrors = function(code) {
|
|
|
|
|
// trivial check of bracket curlyCount
|
|
|
|
|
// should be file specific in the future
|
|
|
|
|
// and understand the syntax of config file
|
|
|
|
|
|
|
|
|
|
var normalCount = 0;
|
|
|
|
|
var squareCount = 0;
|
|
|
|
|
var curlyCount = 0;
|
|
|
|
|
|
|
|
|
|
for (var i = 0, len = code.length; i < len; i++) {
|
|
|
|
|
if (code[i] === '(') {
|
|
|
|
|
normalCount++;
|
|
|
|
|
}
|
|
|
|
|
if (code[i] === ')') {
|
|
|
|
|
normalCount--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (code[i] === '[') {
|
|
|
|
|
squareCount++;
|
|
|
|
|
}
|
|
|
|
|
if (code[i] === ']') {
|
|
|
|
|
squareCount--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (code[i] === '{') {
|
|
|
|
|
curlyCount++;
|
|
|
|
|
}
|
|
|
|
|
if (code[i] === '}') {
|
|
|
|
|
curlyCount--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var result = [];
|
|
|
|
|
if (curlyCount > 0) {
|
|
|
|
|
result.push("Missing a closing curly bracket }");
|
|
|
|
|
}
|
|
|
|
|
if (squareCount > 0) {
|
|
|
|
|
result.push("Missing a closing square bracket ]");
|
|
|
|
|
}
|
|
|
|
|
if (normalCount > 0) {
|
|
|
|
|
result.push("Missing a closing bracket )");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (curlyCount < 0) {
|
|
|
|
|
result.push("You have more closing curly brackets than needed }");
|
|
|
|
|
}
|
|
|
|
|
if (squareCount < 0) {
|
|
|
|
|
result.push("You have more closing square brackets than needed ]");
|
|
|
|
|
}
|
|
|
|
|
if (normalCount < 0) {
|
|
|
|
|
result.push("You have more closing brackets than needed )");
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var unfilledVariables = function(code) {
|
|
|
|
|
var result = [];
|
|
|
|
|
var lines = code.split("\n");
|
|
|
|
|
for (var i = 0, len = lines.length; i < len; i++) {
|
|
|
|
|
var lineNumber = '' + (i + 1);
|
|
|
|
|
var line = lines[i];
|
|
|
|
|
var matches = line.match(/::.*::/gi)
|
|
|
|
|
if(!matches) { continue; };
|
|
|
|
|
for (var j=0, lenMatches = matches.length; j < lenMatches ; j++) {
|
|
|
|
|
var match = matches[j];
|
|
|
|
|
result.push("Line " + lineNumber + " - " + match);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-21 19:17:04 +01:00
|
|
|
$(document).ready(function() {
|
|
|
|
|
var editor = ace.edit("editor");
|
|
|
|
|
//editor.setTheme("ace/theme/monokai");
|
|
|
|
|
//editor.getSession().setMode("ace/mode/javascript");
|
|
|
|
|
editor.setOptions({
|
|
|
|
|
maxLines: 40
|
|
|
|
|
});
|
2016-02-22 06:14:17 +01:00
|
|
|
|
|
|
|
|
var onEditorChange = function(e) {
|
|
|
|
|
value = editor.getValue();
|
|
|
|
|
var errors = syntaxErrors(value);
|
|
|
|
|
var message = errors.map(function(error) {
|
|
|
|
|
return '<li>' + error + '</li>';
|
|
|
|
|
}).join("");
|
|
|
|
|
if (message === "") {
|
|
|
|
|
message = " No errors! Everything is awesome!"
|
|
|
|
|
}
|
|
|
|
|
$("#syntax_errors").html(message);
|
|
|
|
|
|
|
|
|
|
var variables = unfilledVariables(value);
|
|
|
|
|
var variableMessages = variables.map(function(variable) {
|
|
|
|
|
return '<li>' + variable + '</li>';
|
|
|
|
|
}).join("");
|
|
|
|
|
if (variableMessages === "") {
|
|
|
|
|
|
|
|
|
|
variableMessages = "Everything is filled out!"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$("#unfilled_variables").html(variableMessages);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
editor.on("change", onEditorChange );
|
|
|
|
|
onEditorChange();
|
|
|
|
|
|
2016-02-21 19:17:04 +01:00
|
|
|
editor.resize();
|
|
|
|
|
|
|
|
|
|
$("#save_button").click(function() {
|
|
|
|
|
var content = editor.getValue();
|
|
|
|
|
$("#content").val(content);
|
|
|
|
|
var filePath = $("#visible_file_path").val()
|
|
|
|
|
$("#file_path").val(filePath)
|
|
|
|
|
$("#update_form").submit();
|
|
|
|
|
});
|
|
|
|
|
});
|