feature(files) add showError

This commit is contained in:
coderaiser 2014-06-17 10:19:22 -04:00
parent e265214051
commit d109ab625d

View file

@ -10,6 +10,8 @@ var Util, DOM;
function FilesProto(Util, DOM) {
var Files = this,
FILES_JSON = 'config|modules|ext',
FILES_HTML = 'file|path|link|pathLink',
funcs = [],
Data = {},
DIR_HTML = '/html/',
@ -41,38 +43,52 @@ var Util, DOM;
};
this.set = function(name, data, callback) {
var strFiles = FILES_JSON + FILES_HTML,
regExp = new RegExp(strFiles),
isFile = regExp.match(regExp);
Util.checkArgs(arguments, [name, data]);
Data[name] = data;
callback(null);
if (!isFile) {
showError(name);
} else {
Data[name] = data;
callback(null);
}
return Files;
};
function getModule(name, callback) {
var path,
json = 'config|modules|ext',
html = 'file|path|link|pathLink',
regExpHTML = new RegExp(html),
regExpJSON = new RegExp(json),
regExpHTML = new RegExp(FILES_HTML),
regExpJSON = new RegExp(FILES_JSON),
isHTML = name.match(regExpHTML),
isJSON = name.match(regExpJSON);
if (isHTML) {
path = DIR_HTML_FS + name + '.html',
getSystemFile(Data[name], path , callback);
} else if (isJSON) {
if (name === 'config') {
getConfig(callback);
} else {
path = DIR_JSON + name + '.json';
getSystemFile(Data[name], path, callback);
if (!isHTML && !isJSON)
showError(name);
else
if (isHTML) {
path = DIR_HTML_FS + name + '.html',
getSystemFile(Data[name], path , callback);
} else if (isJSON) {
if (name === 'config') {
getConfig(callback);
} else {
path = DIR_JSON + name + '.json';
getSystemFile(Data[name], path, callback);
}
}
} else {
throw(new Error('Wrong file name: ' + name));
}
}
function showError(name) {
var str = 'Wrong file name: ' + name,
error = new Error(str);
throw(error);
}
function getSystemFile(global, url, callback) {