feature(edit) add beautify

This commit is contained in:
coderaiser 2014-10-23 07:18:11 -04:00
parent 7c6d963b6e
commit 3ee321bbce
5 changed files with 38 additions and 10 deletions

View file

@ -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").

View file

@ -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;

View file

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

View file

@ -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;

View file

@ -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",