Skip to content

Commit 58d7df4

Browse files
author
codepad
committed
0.9.3
1 parent 69c66f8 commit 58d7df4

File tree

180 files changed

+30455
-436
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+30455
-436
lines changed

.npmignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.gitignore
2+
.ep_initialized
3+
highlight.js
4+
themes-disabled
5+
publish.sh

README.md

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Turn etherpad into codepad - a collaborative open development enviroment.
22

3-
Status: Beta - ~bugfixes only until 1.0.0
3+
Status: Beta - ~bugfixes mostly until 1.0.0 - bug reports welcome.
44

55
This etherpad-lite plugin merges functionality of a few simple plugins, and adds tons of functionality on its own.
66

77
- File Tree view, open files into pads and save them back.
8-
- Syntaxhighlighting for 27 popular lanuges - based on alexgorbatchev/syntaxhighlighter
9-
- Adds tons of themes, properly implemented with css, and a theme generator
8+
- Syntaxhighlighting for 92 popular languages - based on highlight.js
9+
- Adds themes, properly implemented with css, and a theme generator
1010
- beutify html/css/javascript code with jsBeutify
1111
- Syntax-check javascipt with jsHint, and display results
1212
- save/commit/push (F2) and play
@@ -56,13 +56,9 @@ Codepad is designed to work together with fedora "srvctl", an LXC container and
5656
https://githubub.com/LaKing/Fedora-scripts
5757

5858
Known issues:
59-
- multiline comments in pads don't get highlighted, codepad processes everything line-by-line
60-
- ejs stops etherpad sometimes with an error complaining about missing toolbar
59+
- while editing, multiline comments in pads don't get highlighted as expected
6160
- log-view can crash after a while
6261

63-
Syntaxhighlighter bugs:
64-
- <t> and <l> tags with the XML brush break the pad
65-
- view does not always work as it should be
6662

6763
Please feel free to send comments, bug-reports, ...
6864
.. and/or in case of professional, or commercial use please donate to support open source software developers.

ep.json

+2-6
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@
4040
"hooks": {
4141
"padCreate": "ep_codepad:padCreate"
4242
}
43-
}, {
44-
"name": "ep_codepad_editorfixes",
45-
"client_hooks": {
46-
"aceEditorCSS": "ep_codepad/static/js/ace:aceEditorCSS"
47-
}
4843
}, {
4944
"name": "ep_codepad_defaults",
5045
"client_hooks": {
@@ -89,11 +84,12 @@
8984
"clientVars": "ep_codepad/themes_index:clientVars"
9085
},
9186
"client_hooks": {
87+
"aceEditEvent": "ep_codepad/static/js/syntax:aceEditEvent",
9288
"aceKeyEvent": "ep_codepad/static/js/syntax:aceKeyEvent",
9389
"aceEditorCSS": "ep_codepad/static/js/aceTheme.js",
9490
"acePostWriteDomLineHTML": "ep_codepad/static/js/syntax:acePostWriteDomLineHTML",
9591
"aceInitInnerdocbodyHead": "ep_codepad/static/js/syntax:aceInitInnerdocbodyHead",
9692
"disableAuthorColorsForThisLine": "ep_codepad/static/js/syntax:disableAuthorColorsForThisLine"
9793
}
9894
}]
99-
}
95+
}

extensions.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ var findExtension = function(ext) {
5353
// Ruby
5454
if (['ruby', 'rails', 'ror', 'rb'].indexOf(ext) > -1) return 'ruby';
5555
// Xml
56-
if (['xml', 'xhtml', 'xslt', 'html', 'htm', 'plist', 'ejs'].indexOf(ext) > -1) return 'xml';
56+
if (['xml', 'xhtml', 'xslt', 'html', 'htm', 'plist', 'ejs', 'rss', 'atom', 'xsl'].indexOf(ext) > -1) return 'xml';
5757

5858
// plain text
5959
if (['txt', 'text', 'md', 'htaccess', 'log', 'err', 'nfo', 'bak', "coffee", "npmignore", "gitignore", "yml"].indexOf(ext) > -1) return 'plain';
@@ -76,4 +76,4 @@ exports.getBrush = function(filename) {
7676
var i = filename.lastIndexOf('.');
7777
var ext = (i < 0) ? 'plain' : filename.substr(i + 1).toLowerCase();
7878
return findExtension(ext);
79-
};
79+
};

handleButtonMessage.js

+77-70
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ var crypto = require('crypto');
22
var padManager = require("ep_etherpad-lite/node/db/PadManager");
33
var fs = require('fs');
44

5-
6-
7-
// read base project folder from settings.json
85
var settings = require('ep_etherpad-lite/node/utils/Settings');
96
var authorManager = require('ep_etherpad-lite/node/db/AuthorManager');
107
var sessionManager = require('ep_etherpad-lite/node/db/SessionManager');
118

9+
// this should be overridden in codepad conf
1210
var project_path = '/tmp/';
1311

1412
if (!settings.ep_codepad) {
@@ -35,16 +33,29 @@ var getBrush = require('./extensions.js').getBrush;
3533

3634
// code syntax checker
3735
var jshint = require('jshint').JSHINT;
38-
36+
var cb = function() {};
3937
var padMessageHandler = require("ep_etherpad-lite/node/handler/PadMessageHandler");
4038

39+
var send_ok = function(padid)
40+
{
41+
var ok_msg = {
42+
type: 'COLLABROOM',
43+
data: {
44+
type: "CUSTOM",
45+
payload: {
46+
padId: padid,
47+
from: "codepad",
48+
errors: null
49+
}
50+
}
51+
};
52+
padMessageHandler.handleCustomObjectMessage(ok_msg, undefined, cb);
53+
};
4154

4255
exports.handleMessage = function(hook_name, context, callback) {
4356

4457
if (context.message && context.message.data) {
4558

46-
var cb = function() {};
47-
4859
var msg = context.message.data.type;
4960
console.log("MSG: " + msg);
5061

@@ -58,13 +69,28 @@ exports.handleMessage = function(hook_name, context, callback) {
5869

5970
fs.readFile(path, function(err, data) {
6071
if (err) {
72+
// notify user about the read error
6173
console.log("codepad-read-error " + path);
62-
}
63-
64-
var adat = data.toString();
65-
if (adat !== text) {
66-
value.setText(adat);
67-
padMessageHandler.updatePadClients(value, cb);
74+
var err_msg = {
75+
type: 'COLLABROOM',
76+
data: {
77+
type: "CUSTOM",
78+
payload: {
79+
padId: padid,
80+
from: "fs",
81+
errors: err
82+
}
83+
}
84+
};
85+
padMessageHandler.handleCustomObjectMessage(err_msg, undefined, cb);
86+
callback(null);
87+
} else {
88+
var adat = data.toString();
89+
if (adat !== text) {
90+
value.setText(adat);
91+
padMessageHandler.updatePadClients(value, cb);
92+
}
93+
send_ok(padid);
6894
}
6995
});
7096
});
@@ -79,7 +105,7 @@ exports.handleMessage = function(hook_name, context, callback) {
79105
var folder = '';
80106

81107
// since EEXISTS is an error, we skip that error
82-
// TODO, use mkdirP ?
108+
// there will be a message if the write failes anyway
83109
mkdir_err = function(err) {};
84110

85111
// create subfolders
@@ -94,25 +120,21 @@ exports.handleMessage = function(hook_name, context, callback) {
94120
// get the file extension/brush
95121
var ext = getBrush(padid);
96122

97-
// the beutified text of the pad
123+
// if all ok, send only one OK message.
124+
var all_is_ok = true;
98125

126+
// the beutified or the raw text of the pad
99127
// remove newline character from the end of the string.
100-
var beat = value.atext.text.slice(0, -1);
101-
102-
128+
var text = value.atext.text.slice(0, -1);
129+
var beat = text;
130+
103131
// if .js file beautify
104132
if (ext == 'js') {
105-
if (msg == msg_push) beat = beautify(beat, {
106-
indent_size: 4
107-
});
108-
109-
110-
//padMessageHandler.updatePadClients(value, cb);
111-
112-
if (!jshint(beat)) {
133+
//check for missing semiciolons forst
134+
if (msg == msg_push && !jshint(text)) {
113135

114136
// determine if semicolons should be added at the end of line
115-
check = function(errors, line, length) {
137+
var check = function(errors, line, length) {
116138
var count = 0;
117139
var chpos = 0;
118140
errors.forEach(function(err) {
@@ -121,18 +143,18 @@ exports.handleMessage = function(hook_name, context, callback) {
121143
if (err.line == line + 1) {
122144
count++;
123145
if (err.code == 'W033') chpos = err.character;
146+
// TODO ... maybe it should abort the whole process if there was another error
124147
}
125148
}
126149
});
127150

128-
129-
if (count == 1 && chpos !== 0 && length < chpos) return true;
151+
if (count === 1 && chpos !== 0 && length < chpos) return true;
130152
else return false;
131153
};
132154

133155

134156
// Add the semicolons
135-
var lines = beat.split('\n');
157+
var lines = text.split('\n');
136158
beat = '';
137159

138160
for (var i = 0; i < lines.length; i++) {
@@ -142,9 +164,16 @@ exports.handleMessage = function(hook_name, context, callback) {
142164
else beat += lines[i] + '\n';
143165
}
144166
}
167+
168+
// if push and jshint said ok, then beautify text for real
169+
if (msg == msg_push && jshint(text)) beat = beautify(text, {
170+
indent_size: 4
171+
});
172+
145173
// re-check the new beautified code
146174
if (!jshint(beat)) {
147175

176+
// still has errors, we put them to the console log on the server
148177
jshint.errors.forEach(function(err) {
149178
if (err) {
150179
console.info(" ! " + padid + ":" + err.line + ":" + err.character + " " + err.reason + "|" + err.evidence);
@@ -153,6 +182,7 @@ exports.handleMessage = function(hook_name, context, callback) {
153182
}
154183
});
155184

185+
all_is_ok = false;
156186
var err_msg = {
157187
type: 'COLLABROOM',
158188
data: {
@@ -166,46 +196,33 @@ exports.handleMessage = function(hook_name, context, callback) {
166196
};
167197
padMessageHandler.handleCustomObjectMessage(err_msg, undefined, cb);
168198

169-
} else {
170-
var ok_msg = {
171-
type: 'COLLABROOM',
172-
data: {
173-
type: "CUSTOM",
174-
payload: {
175-
padId: padid,
176-
from: "jshint",
177-
errors: null
178-
}
179-
}
180-
};
181-
padMessageHandler.handleCustomObjectMessage(ok_msg, undefined, cb);
182-
}
183-
184-
if (msg == msg_push) value.setText(beat);
185-
padMessageHandler.updatePadClients(value, cb);
199+
}
186200
}
187201

188202
// if .css file beautify
189203
if (ext == 'css' && msg == msg_push) {
190-
beat = beautify_css(beat, {
204+
beat = beautify_css(text, {
191205
indent_size: 4
192206
});
193-
value.setText(beat);
194-
padMessageHandler.updatePadClients(value, cb);
195207
}
196208

197209
// if .html file beautify
198210
if (ext == 'xml' && msg == msg_push) {
199-
beat = beautify_html(beat, {
211+
beat = beautify_html(text, {
200212
indent_size: 4
201213
});
214+
}
215+
216+
// text and beat may be different, depending on jsHint and the beutifier
217+
if (text !== beat) {
202218
value.setText(beat);
203219
padMessageHandler.updatePadClients(value, cb);
204220
}
205221

206222
// WRITE to the FILE
207223
fs.writeFile(path, beat, function(err) {
208224
if (err) {
225+
all_is_ok = false;
209226
console.log("Failed to write text to " + path);
210227
var err_msg = {
211228
type: 'COLLABROOM',
@@ -221,42 +238,31 @@ exports.handleMessage = function(hook_name, context, callback) {
221238
padMessageHandler.handleCustomObjectMessage(err_msg, undefined, cb);
222239
} else {
223240
console.log("Wrote pad contents to " + path);
224-
var ok_msg = {
225-
type: 'COLLABROOM',
226-
data: {
227-
type: "CUSTOM",
228-
payload: {
229-
padId: padid,
230-
from: "fs",
231-
errors: null
232-
}
233-
}
234-
};
235-
padMessageHandler.handleCustomObjectMessage(ok_msg, undefined, cb);
241+
236242
// if push_action is defined in settings.json, it will run here, use it for git/svn/hg ... or whatever.
237243
if (settings.ep_codepad && msg == msg_push) {
238244
if (settings.ep_codepad.push_action) {
239245
exec(settings.ep_codepad.push_action, function(exec_err, stdout, stderr) {
246+
if (stdout) console.log("[codepad] push_action stdout: " + stdout);
247+
if (stderr) console.log("[codepad] push_action stderr: " + stderr);
240248
if (exec_err) {
241-
console.log('codepad-push-error: ', exec_err);
249+
console.log('[codepad] push_action !error: ', exec_err);
242250
var err_msg = {
243251
type: 'COLLABROOM',
244252
data: {
245253
type: "CUSTOM",
246254
payload: {
247255
padId: padid,
248-
from: "fs",
256+
from: "exec",
249257
errors: exec_err
250258
}
251259
}
252260
};
253261
padMessageHandler.handleCustomObjectMessage(err_msg, undefined, cb);
254-
}
255-
if (stdout) console.log("codepad-push-stdout: " + stdout);
256-
if (stderr) console.log("codepad-push-stderr: " + stderr);
262+
} else if (all_is_ok) send_ok(padid);
257263
});
258-
}
259-
}
264+
} else if (all_is_ok) send_ok(padid);
265+
} else if (all_is_ok) send_ok(padid);
260266
}
261267
});
262268
});
@@ -278,4 +284,5 @@ exports.handleMessage = function(hook_name, context, callback) {
278284
"scope": "(main)",
279285
"reason": "Missing semicolon."
280286
281-
*****/
287+
*****/
288+

highlight.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 5b6f61ac8f05003663fc96675adfd6cd86b906c7

0 commit comments

Comments
 (0)