diff --git a/HELP.md b/HELP.md index ef9ffab6..a2dd46a9 100644 --- a/HELP.md +++ b/HELP.md @@ -156,6 +156,7 @@ Edit | `Ctrl + f` | find | `Ctrl + h` | replace | `Ctrl + g` | go to line +| `Ctrl + b` | beautify js, css or html | `Esc` | close For more details see [Ace keyboard shortcuts](https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts "Ace keyboard shortcuts"). diff --git a/lib/client/edit.js b/lib/client/edit.js index ab32c3db..a940fd61 100644 --- a/lib/client/edit.js +++ b/lib/client/edit.js @@ -239,6 +239,14 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI exec : save }); + Ace.commands.addCommand({ + name : 'beautify', + bindKey : { win: 'Ctrl-B', mac: 'Command-B' }, + exec : function() { + Edit.beautify(); + } + }); + ace.require('ace/ext/language_tools'); Modelist = ace.require('ace/ext/modelist'); @@ -400,6 +408,9 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI 'Delete Del' : function() { Ace.remove('right'); }, + 'Beautify Ctrl+B' : function() { + Edit.beautify(); + }, 'Close Esc' : Edit.hide }; @@ -471,7 +482,15 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI } } - function onDrop(event) { + Edit.beautify = function() { + var path = Info.path; + + RESTful.read(path + '?beautify', function(data) { + Ace.setValue(data); + }); + }; + + function onDrop(event) { var reader, files, onLoad = function(event) { var data = event.target.result; diff --git a/lib/client/rest.js b/lib/client/rest.js index 37b79749..8ef6b173 100644 --- a/lib/client/rest.js +++ b/lib/client/rest.js @@ -48,7 +48,8 @@ var Util, DOM, CloudFunc, CloudCmd; }; this.read = function(url, dataType, callback) { - var isQuery = Util.isContainStr(url, '?'), + var isQuery = /.?/.test(url), + isBeautify = /.?beautify$/.test(url), isFunc = Util.type.function(dataType); if (!callback && isFunc) { @@ -60,7 +61,7 @@ var Util, DOM, CloudFunc, CloudCmd; method : 'GET', url : CloudFunc.FS + url, callback : callback, - notLog : !isQuery, + notLog : !isQuery || isBeautify, dataType : dataType }); }; diff --git a/lib/server/rest/fs/get.js b/lib/server/rest/fs/get.js index 8d00882a..eeab3ebe 100644 --- a/lib/server/rest/fs/get.js +++ b/lib/server/rest/fs/get.js @@ -8,23 +8,29 @@ flop = require(DIR_SERVER + 'flop'), Hash = require(DIR_SERVER + 'hash'), mellow = require(DIR_SERVER + 'mellow'), + beautify = require(DIR_SERVER + 'beautify'), Util = require(DIR + 'util'); module.exports = function(query, name, callback) { - var hash, error, - func = Util.exec.ret(callback); + var hash, error; + + Util.checkArgs(arguments, ['query', 'name', 'callback']); switch (query) { default: - mellow.read(name, func); + mellow.read(name, callback); break; case 'size': - flop.read(name, 'size', func); + flop.read(name, 'size', callback); break; case 'time': - flop.read(name, 'time', func); + flop.read(name, 'time', callback); + break; + + case 'beautify': + beautify(name, callback); break; case 'hash': @@ -32,7 +38,7 @@ if (!hash) { error = 'hash: not suported, try update node'; - func(new Error(error)); + callback(Error(error)); } else pipe.create(name, hash, function (error) { var hex; @@ -40,7 +46,7 @@ if (!error) hex = hash.get(); - func(error, hex); + callback(error, hex); }); break; diff --git a/package.json b/package.json index b79d92c9..7b1eb061 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "express": "~4.9.0", "fstream": "~1.0.2", "http-auth": "2.1.x", + "js-beautify": "~1.5.4", "marked": "~0.3.2", "minify": "~1.0.0", "mkdirp": "~0.5.0",