From d109ab625d5c304f498fb40264b86faaa27e439e Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 17 Jun 2014 10:19:22 -0400 Subject: [PATCH] feature(files) add showError --- lib/client/files.js | 52 +++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/lib/client/files.js b/lib/client/files.js index d722f38d..c01ad579 100644 --- a/lib/client/files.js +++ b/lib/client/files.js @@ -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) {