codemirror-rails 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. data/codemirror-rails-0.0.0.gem +0 -0
  2. data/codemirror-rails-0.1.gem +0 -0
  3. data/lib/codemirror/rails/version.rb +2 -2
  4. data/vendor/assets/javascripts/codemirror.js +122 -63
  5. data/vendor/assets/javascripts/codemirror/modes/clike.js +221 -0
  6. data/vendor/assets/javascripts/codemirror/modes/css.js +124 -0
  7. data/vendor/assets/javascripts/codemirror/modes/diff.js +13 -0
  8. data/vendor/assets/javascripts/codemirror/modes/haskell.js +242 -0
  9. data/vendor/assets/javascripts/codemirror/modes/htmlmixed.js +79 -0
  10. data/vendor/assets/javascripts/codemirror/modes/javascript.js +348 -0
  11. data/vendor/assets/javascripts/codemirror/modes/lua.js +138 -0
  12. data/vendor/assets/javascripts/codemirror/modes/php.js +111 -0
  13. data/vendor/assets/javascripts/codemirror/modes/plsql.js +217 -0
  14. data/vendor/assets/javascripts/codemirror/modes/python.js +321 -0
  15. data/vendor/assets/javascripts/codemirror/modes/rst.js +333 -0
  16. data/vendor/assets/javascripts/codemirror/modes/scheme.js +181 -0
  17. data/vendor/assets/javascripts/codemirror/modes/smalltalk.js +122 -0
  18. data/vendor/assets/javascripts/codemirror/modes/stex.js +167 -0
  19. data/vendor/assets/javascripts/codemirror/modes/xml.js +227 -0
  20. data/vendor/assets/javascripts/codemirror/modes/yaml.js +95 -0
  21. data/vendor/assets/javascripts/codemirror/overlay.js +51 -0
  22. data/vendor/assets/javascripts/codemirror/runmode.js +27 -0
  23. data/vendor/assets/stylesheets/codemirror.css +3 -0
  24. data/vendor/assets/stylesheets/codemirror/modes/clike.css +7 -0
  25. data/vendor/assets/stylesheets/codemirror/modes/diff.css +3 -0
  26. data/vendor/assets/stylesheets/codemirror/modes/rst.css +75 -0
  27. metadata +25 -3
  28. data/codemirror-rails-0.1.1.gem +0 -0
@@ -0,0 +1,333 @@
1
+ CodeMirror.defineMode('rst', function(config, options) {
2
+ function setState(state, fn, ctx) {
3
+ state.fn = fn;
4
+ setCtx(state, ctx);
5
+ }
6
+
7
+ function setCtx(state, ctx) {
8
+ state.ctx = ctx || {};
9
+ }
10
+
11
+ function setNormal(state, ch) {
12
+ if (ch && (typeof ch !== 'string')) {
13
+ var str = ch.current();
14
+ ch = str[str.length-1];
15
+ }
16
+
17
+ setState(state, normal, {back: ch});
18
+ }
19
+
20
+ function hasMode(mode) {
21
+ if (mode) {
22
+ var modes = CodeMirror.listModes();
23
+
24
+ for (var i in modes) {
25
+ if (modes[i] == mode) {
26
+ return true;
27
+ }
28
+ }
29
+ }
30
+
31
+ return false;
32
+ }
33
+
34
+ function getMode(mode) {
35
+ if (hasMode(mode)) {
36
+ return CodeMirror.getMode(config, mode);
37
+ } else {
38
+ return null;
39
+ }
40
+ }
41
+
42
+ var verbatimMode = getMode(options.verbatim);
43
+ var pythonMode = getMode('python');
44
+
45
+ var reSection = /^[!"#$%&'()*+,-./:;<=>?@[\\\]^_`{|}~]/;
46
+ var reDirective = /^\s*\w([-:.\w]*\w)?::(\s|$)/;
47
+ var reHyperlink = /^\s*_[\w-]+:(\s|$)/;
48
+ var reFootnote = /^\s*\[(\d+|#)\](\s|$)/;
49
+ var reCitation = /^\s*\[[A-Za-z][\w-]*\](\s|$)/;
50
+ var reFootnoteRef = /^\[(\d+|#)\]_/;
51
+ var reCitationRef = /^\[[A-Za-z][\w-]*\]_/;
52
+ var reDirectiveMarker = /^\.\.(\s|$)/;
53
+ var reVerbatimMarker = /^::\s*$/;
54
+ var rePreInline = /^[-\s"([{</:]/;
55
+ var rePostInline = /^[-\s`'")\]}>/:.,;!?\\_]/;
56
+ var reEnumeratedList = /^\s*((\d+|[A-Za-z#])[.)]|\((\d+|[A-Z-a-z#])\))\s/;
57
+ var reBulletedList = /^\s*[-\+\*]\s/;
58
+ var reExamples = /^\s+(>>>|In \[\d+\]:)\s/;
59
+
60
+ function normal(stream, state) {
61
+ var ch, sol, i;
62
+
63
+ if (stream.eat(/\\/)) {
64
+ ch = stream.next();
65
+ setNormal(state, ch);
66
+ return null;
67
+ }
68
+
69
+ sol = stream.sol();
70
+
71
+ if (sol && (ch = stream.eat(reSection))) {
72
+ for (i = 0; stream.eat(ch); i++);
73
+
74
+ if (i >= 3 && stream.match(/^\s*$/)) {
75
+ setNormal(state, null);
76
+ return 'section';
77
+ } else {
78
+ stream.backUp(i + 1);
79
+ }
80
+ }
81
+
82
+ if (sol && stream.match(reDirectiveMarker)) {
83
+ if (!stream.eol()) {
84
+ setState(state, directive);
85
+ }
86
+
87
+ return 'directive-marker';
88
+ }
89
+
90
+ if (stream.match(reVerbatimMarker)) {
91
+ if (!verbatimMode) {
92
+ setState(state, verbatim);
93
+ } else {
94
+ var mode = verbatimMode;
95
+
96
+ setState(state, verbatim, {
97
+ mode: mode,
98
+ local: mode.startState()
99
+ });
100
+ }
101
+
102
+ return 'verbatim-marker';
103
+ }
104
+
105
+ if (sol && stream.match(reExamples, false)) {
106
+ if (!pythonMode) {
107
+ setState(state, verbatim);
108
+ return 'verbatim-marker';
109
+ } else {
110
+ var mode = pythonMode;
111
+
112
+ setState(state, verbatim, {
113
+ mode: mode,
114
+ local: mode.startState()
115
+ });
116
+
117
+ return null;
118
+ }
119
+ }
120
+
121
+ if (sol && (stream.match(reEnumeratedList) ||
122
+ stream.match(reBulletedList))) {
123
+ setNormal(state, stream);
124
+ return 'list';
125
+ }
126
+
127
+ function testBackward(re) {
128
+ return sol || !state.ctx.back || re.test(state.ctx.back);
129
+ }
130
+
131
+ function testForward(re) {
132
+ return stream.eol() || stream.match(re, false);
133
+ }
134
+
135
+ function testInline(re) {
136
+ return stream.match(re) && testBackward(/\W/) && testForward(/\W/);
137
+ }
138
+
139
+ if (testInline(reFootnoteRef)) {
140
+ setNormal(state, stream);
141
+ return 'footnote';
142
+ }
143
+
144
+ if (testInline(reCitationRef)) {
145
+ setNormal(state, stream);
146
+ return 'citation';
147
+ }
148
+
149
+ ch = stream.next();
150
+
151
+ if (testBackward(rePreInline)) {
152
+ if ((ch === ':' || ch === '|') && stream.eat(/\S/)) {
153
+ var token;
154
+
155
+ if (ch === ':') {
156
+ token = 'role';
157
+ } else {
158
+ token = 'replacement';
159
+ }
160
+
161
+ setState(state, inline, {
162
+ ch: ch,
163
+ wide: false,
164
+ prev: null,
165
+ token: token
166
+ });
167
+
168
+ return token;
169
+ }
170
+
171
+ if (ch === '*' || ch === '`') {
172
+ var orig = ch,
173
+ wide = false;
174
+
175
+ ch = stream.next();
176
+
177
+ if (ch == orig) {
178
+ wide = true;
179
+ ch = stream.next();
180
+ }
181
+
182
+ if (ch && !/\s/.test(ch)) {
183
+ var token;
184
+
185
+ if (orig === '*') {
186
+ token = wide ? 'strong' : 'emphasis';
187
+ } else {
188
+ token = wide ? 'inline' : 'interpreted';
189
+ }
190
+
191
+ setState(state, inline, {
192
+ ch: orig, // inline() has to know what to search for
193
+ wide: wide, // are we looking for `ch` or `chch`
194
+ prev: null, // terminator must not be preceeded with whitespace
195
+ token: token // I don't want to recompute this all the time
196
+ });
197
+
198
+ return token;
199
+ }
200
+ }
201
+ }
202
+
203
+ setNormal(state, ch);
204
+ return null;
205
+ }
206
+
207
+ function inline(stream, state) {
208
+ var ch = stream.next(),
209
+ token = state.ctx.token;
210
+
211
+ function finish(ch) {
212
+ state.ctx.prev = ch;
213
+ return token;
214
+ }
215
+
216
+ if (ch != state.ctx.ch) {
217
+ return finish(ch);
218
+ }
219
+
220
+ if (/\s/.test(state.ctx.prev)) {
221
+ return finish(ch);
222
+ }
223
+
224
+ if (state.ctx.wide) {
225
+ ch = stream.next();
226
+
227
+ if (ch != state.ctx.ch) {
228
+ return finish(ch);
229
+ }
230
+ }
231
+
232
+ if (!stream.eol() && !rePostInline.test(stream.peek())) {
233
+ if (state.ctx.wide) {
234
+ stream.backUp(1);
235
+ }
236
+
237
+ return finish(ch);
238
+ }
239
+
240
+ setState(state, normal);
241
+ setNormal(state, ch);
242
+
243
+ return token;
244
+ }
245
+
246
+ function directive(stream, state) {
247
+ var token = null;
248
+
249
+ if (stream.match(reDirective)) {
250
+ token = 'directive';
251
+ } else if (stream.match(reHyperlink)) {
252
+ token = 'hyperlink';
253
+ } else if (stream.match(reFootnote)) {
254
+ token = 'footnote';
255
+ } else if (stream.match(reCitation)) {
256
+ token = 'citation';
257
+ } else {
258
+ stream.eatSpace();
259
+
260
+ if (stream.eol()) {
261
+ setNormal(state, stream);
262
+ return null;
263
+ } else {
264
+ stream.skipToEnd();
265
+ setState(state, comment);
266
+ return 'comment';
267
+ }
268
+ }
269
+
270
+ setState(state, body, {start: true});
271
+ return token;
272
+ }
273
+
274
+ function body(stream, state) {
275
+ var token = 'body';
276
+
277
+ if (!state.ctx.start || stream.sol()) {
278
+ return block(stream, state, token);
279
+ }
280
+
281
+ stream.skipToEnd();
282
+ setCtx(state);
283
+
284
+ return token;
285
+ }
286
+
287
+ function comment(stream, state) {
288
+ return block(stream, state, 'comment');
289
+ }
290
+
291
+ function verbatim(stream, state) {
292
+ if (!verbatimMode) {
293
+ return block(stream, state, 'verbatim');
294
+ } else {
295
+ if (stream.sol()) {
296
+ if (!stream.eatSpace()) {
297
+ setNormal(state, stream);
298
+ }
299
+
300
+ return null;
301
+ }
302
+
303
+ return verbatimMode.token(stream, state.ctx.local);
304
+ }
305
+ }
306
+
307
+ function block(stream, state, token) {
308
+ if (stream.eol() || stream.eatSpace()) {
309
+ stream.skipToEnd();
310
+ return token;
311
+ } else {
312
+ setNormal(state, stream);
313
+ return null;
314
+ }
315
+ }
316
+
317
+ return {
318
+ startState: function() {
319
+ return {fn: normal, ctx: {}};
320
+ },
321
+
322
+ copyState: function(state) {
323
+ return {fn: state.fn, ctx: state.ctx};
324
+ },
325
+
326
+ token: function(stream, state) {
327
+ var token = state.fn(stream, state);
328
+ return token;
329
+ }
330
+ };
331
+ });
332
+
333
+ CodeMirror.defineMIME("text/x-rst", "rst");
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Author: Koh Zi Han, based on implementation by Koh Zi Chun
3
+ */
4
+ CodeMirror.defineMode("scheme", function (config, mode) {
5
+ var numRegex = /[0-9]/;
6
+ var BUILTIN = "builtin", COMMENT = "comment", STRING = "string",
7
+ ATOM = "atom", NUMBER = "number", BRACKET = "bracket";
8
+ var INDENT_WORD_SKIP = 2, KEYWORDS_SKIP = 1;
9
+
10
+ function makeKeywords(str) {
11
+ var obj = {}, words = str.split(" ");
12
+ for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
13
+ return obj;
14
+ }
15
+
16
+ var keywords = makeKeywords("case-lambda call/cc class define-class exit-handler field import inherit init-field interface let*-values let-values let/ec mixin opt-lambda override protect provide public rename require require-for-syntax syntax syntax-case syntax-error unit/sig unless when with-syntax and begin call-with-current-continuation call-with-input-file call-with-output-file case cond define define-syntax delay do dynamic-wind else for-each if lambda let let* let-syntax letrec letrec-syntax map or syntax-rules abs acos angle append apply asin assoc assq assv atan boolean? caar cadr call-with-input-file call-with-output-file call-with-values car cdddar cddddr cdr ceiling char->integer char-alphabetic? char-ci<=? char-ci<? char-ci=? char-ci>=? char-ci>? char-downcase char-lower-case? char-numeric? char-ready? char-upcase char-upper-case? char-whitespace? char<=? char<? char=? char>=? char>? char? close-input-port close-output-port complex? cons cos current-input-port current-output-port denominator display eof-object? eq? equal? eqv? eval even? exact->inexact exact? exp expt #f floor force gcd imag-part inexact->exact inexact? input-port? integer->char integer? interaction-environment lcm length list list->string list->vector list-ref list-tail list? load log magnitude make-polar make-rectangular make-string make-vector max member memq memv min modulo negative? newline not null-environment null? number->string number? numerator odd? open-input-file open-output-file output-port? pair? peek-char port? positive? procedure? quasiquote quote quotient rational? rationalize read read-char real-part real? remainder reverse round scheme-report-environment set! set-car! set-cdr! sin sqrt string string->list string->number string->symbol string-append string-ci<=? string-ci<? string-ci=? string-ci>=? string-ci>? string-copy string-fill! string-length string-ref string-set! string<=? string<? string=? string>=? string>? string? substring symbol->string symbol? #t tan transcript-off transcript-on truncate values vector vector->list vector-fill! vector-length vector-ref vector-set! with-input-from-file with-output-to-file write write-char zero?");
17
+ var indentKeys = makeKeywords("define let letrec let* lambda begin");
18
+
19
+
20
+ function stateStack(indent, type, prev) { // represents a state stack object
21
+ this.indent = indent;
22
+ this.type = type;
23
+ this.prev = prev;
24
+ }
25
+
26
+ function pushStack(state, indent, type) {
27
+ state.indentStack = new stateStack(indent, type, state.indentStack);
28
+ }
29
+
30
+ function popStack(state) {
31
+ state.indentStack = state.indentStack.prev;
32
+ }
33
+
34
+ return {
35
+ startState: function () {
36
+ return {
37
+ indentStack: null,
38
+ indentation: 0,
39
+ mode: false,
40
+ sExprComment: false
41
+ };
42
+ },
43
+
44
+ token: function (stream, state) {
45
+ if (state.indentStack == null && stream.sol()) {
46
+ // update indentation, but only if indentStack is empty
47
+ state.indentation = stream.indentation();
48
+ }
49
+
50
+ // skip spaces
51
+ if (stream.eatSpace()) {
52
+ return null;
53
+ }
54
+ var returnType = null;
55
+
56
+ switch(state.mode){
57
+ case "string": // multi-line string parsing mode
58
+ var next, escaped = false;
59
+ while ((next = stream.next()) != null) {
60
+ if (next == "\"" && !escaped) {
61
+
62
+ state.mode = false;
63
+ break;
64
+ }
65
+ escaped = !escaped && next == "\\";
66
+ }
67
+ returnType = STRING; // continue on in scheme-string mode
68
+ break;
69
+ case "comment": // comment parsing mode
70
+ var next, maybeEnd = false;
71
+ while ((next = stream.next()) != null) {
72
+ if (next == "#" && maybeEnd) {
73
+
74
+ state.mode = false;
75
+ break;
76
+ }
77
+ maybeEnd = (next == "|");
78
+ }
79
+ returnType = COMMENT;
80
+ break;
81
+ case "s-expr-comment": // s-expr commenting mode
82
+ state.mode = false;
83
+ if(stream.peek() == "(" || stream.peek() == "["){
84
+ // actually start scheme s-expr commenting mode
85
+ state.sExprComment = 0;
86
+ }else{
87
+ // if not we just comment the entire of the next token
88
+ stream.eatWhile(/[^/s]/); // eat non spaces
89
+ returnType = COMMENT;
90
+ break;
91
+ }
92
+ default: // default parsing mode
93
+ var ch = stream.next();
94
+
95
+ if (ch == "\"") {
96
+ state.mode = "string";
97
+ returnType = STRING;
98
+
99
+ } else if (ch == "'") {
100
+ returnType = ATOM;
101
+ } else if (ch == '#') {
102
+ if (stream.eat("|")) { // Multi-line comment
103
+ state.mode = "comment"; // toggle to comment mode
104
+ returnType = COMMENT;
105
+ } else if (stream.eat(/[tf]/)) { // #t/#f (atom)
106
+ returnType = ATOM;
107
+ } else if (stream.eat(';')) { // S-Expr comment
108
+ state.mode = "s-expr-comment";
109
+ returnType = COMMENT;
110
+ }
111
+
112
+ } else if (ch == ";") { // comment
113
+ stream.skipToEnd(); // rest of the line is a comment
114
+ returnType = COMMENT;
115
+
116
+ } else if (numRegex.exec(ch) != null) { // numbers
117
+ returnType = NUMBER;
118
+
119
+ } else if (ch == "(" || ch == "[") {
120
+ var keyWord = ''; var indentTemp = stream.column();
121
+ /**
122
+ Either
123
+ (indent-word ..
124
+ (non-indent-word ..
125
+ (;something else, bracket, etc.
126
+ */
127
+
128
+ while ((letter = stream.eat(/[^\s\(\[\;\)\]]/)) != null) {
129
+ keyWord += letter;
130
+ }
131
+
132
+ if (keyWord.length > 0 && indentKeys.propertyIsEnumerable(keyWord)) { // indent-word
133
+
134
+ pushStack(state, indentTemp + INDENT_WORD_SKIP, ch);
135
+ } else { // non-indent word
136
+ // we continue eating the spaces
137
+ stream.eatSpace();
138
+ if (stream.eol() || stream.peek() == ";") {
139
+ // nothing significant after
140
+ // we restart indentation 1 space after
141
+ pushStack(state, indentTemp + 1, ch);
142
+ } else {
143
+ pushStack(state, indentTemp + stream.current().length, ch); // else we match
144
+ }
145
+ }
146
+ stream.backUp(stream.current().length - 1); // undo all the eating
147
+
148
+ if(typeof state.sExprComment == "number") state.sExprComment++;
149
+
150
+ returnType = BRACKET;
151
+ } else if (ch == ")" || ch == "]") {
152
+ returnType = BRACKET;
153
+ if (state.indentStack != null && state.indentStack.type == (ch == ")" ? "(" : "[")) {
154
+ popStack(state);
155
+
156
+ if(typeof state.sExprComment == "number"){
157
+ if(--state.sExprComment == 0){
158
+ returnType = COMMENT; // final closing bracket
159
+ state.sExprComment = false; // turn off s-expr commenting mode
160
+ }
161
+ }
162
+ }
163
+ } else {
164
+ stream.eatWhile(/[\w\$_]/);
165
+
166
+ if (keywords && keywords.propertyIsEnumerable(stream.current())) {
167
+ returnType = BUILTIN;
168
+ } else returnType = null;
169
+ }
170
+ }
171
+ return (typeof state.sExprComment == "number") ? COMMENT : returnType;
172
+ },
173
+
174
+ indent: function (state, textAfter) {
175
+ if (state.indentStack == null) return state.indentation;
176
+ return state.indentStack.indent;
177
+ }
178
+ };
179
+ });
180
+
181
+ CodeMirror.defineMIME("text/x-scheme", "css");