codemirror-rails 3.00 → 3.02

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. data/README.md +5 -2
  2. data/lib/codemirror/rails/version.rb +2 -2
  3. data/test/dummy/config/database.yml +25 -0
  4. data/test/dummy/db/.gitkeep +0 -0
  5. data/test/integration/codemirror_rails_integration_test.rb +1 -1
  6. data/vendor/assets/javascripts/codemirror.js +385 -152
  7. data/vendor/assets/javascripts/codemirror/keymaps/vim.js +279 -66
  8. data/vendor/assets/javascripts/codemirror/modes/apl.js +160 -0
  9. data/vendor/assets/javascripts/codemirror/modes/asterisk.js +183 -0
  10. data/vendor/assets/javascripts/codemirror/modes/clike.js +2 -0
  11. data/vendor/assets/javascripts/codemirror/modes/clojure.js +3 -3
  12. data/vendor/assets/javascripts/codemirror/modes/css.js +2 -2
  13. data/vendor/assets/javascripts/codemirror/modes/d.js +205 -0
  14. data/vendor/assets/javascripts/codemirror/modes/gfm.js +2 -1
  15. data/vendor/assets/javascripts/codemirror/modes/javascript.js +13 -2
  16. data/vendor/assets/javascripts/codemirror/modes/markdown.js +8 -7
  17. data/vendor/assets/javascripts/codemirror/modes/properties.js +0 -0
  18. data/vendor/assets/javascripts/codemirror/modes/sass.js +349 -0
  19. data/vendor/assets/javascripts/codemirror/modes/sieve.js +37 -10
  20. data/vendor/assets/javascripts/codemirror/modes/sql.js +268 -0
  21. data/vendor/assets/javascripts/codemirror/modes/xquery.js +8 -8
  22. data/vendor/assets/javascripts/codemirror/utils/collapserange.js +68 -0
  23. data/vendor/assets/javascripts/codemirror/utils/dialog.js +1 -0
  24. data/vendor/assets/javascripts/codemirror/utils/foldcode.js +2 -1
  25. data/vendor/assets/javascripts/codemirror/utils/formatting.js +9 -3
  26. data/vendor/assets/javascripts/codemirror/utils/javascript-hint.js +5 -4
  27. data/vendor/assets/javascripts/codemirror/utils/python-hint.js +93 -0
  28. data/vendor/assets/javascripts/codemirror/utils/runmode-standalone.js +51 -10
  29. data/vendor/assets/javascripts/codemirror/utils/search.js +20 -8
  30. data/vendor/assets/javascripts/codemirror/utils/searchcursor.js +17 -10
  31. data/vendor/assets/stylesheets/codemirror.css +10 -9
  32. metadata +47 -15
  33. data/vendor/assets/javascripts/codemirror/modes/xmlpure.js +0 -490
  34. data/vendor/assets/stylesheets/codemirror/modes/diff.css +0 -3
@@ -75,9 +75,10 @@ CodeMirror.defineMode("gfm", function(config) {
75
75
  return "link";
76
76
  }
77
77
  }
78
- if (stream.match(/^((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/i)) {
78
+ if (stream.match(/^((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\([^\s()<>]*\))+(?:\([^\s()<>]*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/i)) {
79
79
  // URLs
80
80
  // Taken from http://daringfireball.net/2010/07/improved_regex_for_matching_urls
81
+ // And then (issue #1160) simplified to make it not crash the Chrome Regexp engine
81
82
  return "link";
82
83
  }
83
84
  stream.next();
@@ -196,12 +196,19 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
196
196
  return true;
197
197
  }
198
198
  function register(varname) {
199
+ function inList(list) {
200
+ for (var v = list; v; v = v.next)
201
+ if (v.name == varname) return true;
202
+ return false;
203
+ }
199
204
  var state = cx.state;
200
205
  if (state.context) {
201
206
  cx.marked = "def";
202
- for (var v = state.localVars; v; v = v.next)
203
- if (v.name == varname) return;
207
+ if (inList(state.localVars)) return;
204
208
  state.localVars = {name: varname, next: state.localVars};
209
+ } else {
210
+ if (inList(state.globalVars)) return;
211
+ state.globalVars = {name: varname, next: state.globalVars};
205
212
  }
206
213
  }
207
214
 
@@ -364,6 +371,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
364
371
  cc: [],
365
372
  lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
366
373
  localVars: parserConfig.localVars,
374
+ globalVars: parserConfig.globalVars,
367
375
  context: parserConfig.localVars && {vars: parserConfig.localVars},
368
376
  indented: 0
369
377
  };
@@ -406,6 +414,9 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
406
414
  });
407
415
 
408
416
  CodeMirror.defineMIME("text/javascript", "javascript");
417
+ CodeMirror.defineMIME("text/ecmascript", "javascript");
418
+ CodeMirror.defineMIME("application/javascript", "javascript");
419
+ CodeMirror.defineMIME("application/ecmascript", "javascript");
409
420
  CodeMirror.defineMIME("application/json", {name: "javascript", json: true});
410
421
  CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true });
411
422
  CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript: true });
@@ -10,7 +10,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
10
10
  "c++": "text/x-c++src",
11
11
  java: "text/x-java",
12
12
  csharp: "text/x-csharp",
13
- "c#": "text/x-csharp"
13
+ "c#": "text/x-csharp",
14
+ scala: "text/x-scala"
14
15
  };
15
16
 
16
17
  var getMode = (function () {
@@ -246,8 +247,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
246
247
  return getType(state);
247
248
  }
248
249
 
249
- if (ch === '!' && stream.match(/\[.*\] ?(?:\(|\[)/, false)) {
250
- stream.match(/\[.*\]/);
250
+ if (ch === '!' && stream.match(/\[[^\]]*\] ?(?:\(|\[)/, false)) {
251
+ stream.match(/\[[^\]]*\]/);
251
252
  state.inline = state.f = linkHref;
252
253
  return image;
253
254
  }
@@ -456,10 +457,10 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
456
457
  var indentation = stream.match(/^\s*/, true)[0].replace(/\t/g, ' ').length;
457
458
  var difference = Math.floor((indentation - state.indentation) / 4) * 4;
458
459
  if (difference > 4) difference = 4;
459
- indentation = state.indentation + difference;
460
- state.indentationDiff = indentation - state.indentation;
461
- state.indentation = indentation;
462
- if (indentation > 0) { return null; }
460
+ var adjustedIndentation = state.indentation + difference;
461
+ state.indentationDiff = adjustedIndentation - state.indentation;
462
+ state.indentation = adjustedIndentation;
463
+ if (indentation > 0) return null;
463
464
  }
464
465
  return state.f(stream, state);
465
466
  },
@@ -0,0 +1,349 @@
1
+ CodeMirror.defineMode("sass", function(config) {
2
+ var tokenRegexp = function(words){
3
+ return new RegExp("^" + words.join("|"));
4
+ };
5
+
6
+ var tags = ["&", "a","abbr","acronym","address","applet","area","article","aside","audio","b","base","basefont","bdi","bdo","big","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","command","datalist","dd","del","details","dfn","dir","div","dl","dt","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","keygen","kbd","label","legend","li","link","map","mark","menu","meta","meter","nav","noframes","noscript","object","ol","optgroup","option","output","p","param","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","span","strike","strong","style","sub","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","title","tr","track","tt","u","ul","var","video","wbr"];
7
+ var keywords = ["true", "false", "null", "auto"];
8
+ var keywordsRegexp = new RegExp("^" + keywords.join("|"));
9
+
10
+ var operators = ["\\(", "\\)", "=", ">", "<", "==", ">=", "<=", "\\+", "-", "\\!=", "/", "\\*", "%", "and", "or", "not"];
11
+ var opRegexp = tokenRegexp(operators);
12
+
13
+ function htmlTag(val){
14
+ for(var i=0; i<tags.length; i++){
15
+ if(val === tags[i]){
16
+ return true;
17
+ }
18
+ }
19
+ }
20
+
21
+
22
+ var pseudoElements = [':first-line', ':hover', ':first-letter', ':active', ':visited', ':before', ':after', ':link', ':focus', ':first-child', ':lang'];
23
+ var pseudoElementsRegexp = new RegExp("^(" + pseudoElements.join("\\b|") + ")");
24
+
25
+ var urlTokens = function(stream, state){
26
+ var ch = stream.peek();
27
+
28
+ if (ch === ")"){
29
+ stream.next();
30
+ state.tokenizer = tokenBase;
31
+ return "operator";
32
+ }else if (ch === "("){
33
+ stream.next();
34
+ stream.eatSpace();
35
+
36
+ return "operator";
37
+ }else if (ch === "'" || ch === '"'){
38
+ state.tokenizer = buildStringTokenizer(stream.next());
39
+ return "string";
40
+ }else{
41
+ state.tokenizer = buildStringTokenizer(")", false);
42
+ return "string";
43
+ }
44
+ };
45
+ var multilineComment = function(stream, state) {
46
+ if (stream.skipTo("*/")){
47
+ stream.next();
48
+ stream.next();
49
+ state.tokenizer = tokenBase;
50
+ }else {
51
+ stream.next();
52
+ }
53
+
54
+ return "comment";
55
+ };
56
+
57
+ var buildStringTokenizer = function(quote, greedy){
58
+ if(greedy == null){ greedy = true; }
59
+
60
+ function stringTokenizer(stream, state){
61
+ var nextChar = stream.next();
62
+ var peekChar = stream.peek();
63
+ var previousChar = stream.string.charAt(stream.pos-2);
64
+
65
+ var endingString = ((nextChar !== "\\" && peekChar === quote) || (nextChar === quote && previousChar !== "\\"));
66
+
67
+ /*
68
+ console.log("previousChar: " + previousChar);
69
+ console.log("nextChar: " + nextChar);
70
+ console.log("peekChar: " + peekChar);
71
+ console.log("ending: " + endingString);
72
+ */
73
+
74
+ if (endingString){
75
+ if (nextChar !== quote && greedy) { stream.next(); }
76
+ state.tokenizer = tokenBase;
77
+ return "string";
78
+ }else if (nextChar === "#" && peekChar === "{"){
79
+ state.tokenizer = buildInterpolationTokenizer(stringTokenizer);
80
+ stream.next();
81
+ return "operator";
82
+ }else {
83
+ return "string";
84
+ }
85
+ }
86
+
87
+ return stringTokenizer;
88
+ };
89
+
90
+ var buildInterpolationTokenizer = function(currentTokenizer){
91
+ return function(stream, state){
92
+ if (stream.peek() === "}"){
93
+ stream.next();
94
+ state.tokenizer = currentTokenizer;
95
+ return "operator";
96
+ }else{
97
+ return tokenBase(stream, state);
98
+ }
99
+ };
100
+ };
101
+
102
+ var indent = function(state){
103
+ if (state.indentCount == 0){
104
+ state.indentCount++;
105
+ var lastScopeOffset = state.scopes[0].offset;
106
+ var currentOffset = lastScopeOffset + config.indentUnit;
107
+ state.scopes.unshift({ offset:currentOffset });
108
+ }
109
+ };
110
+
111
+ var dedent = function(state){
112
+ if (state.scopes.length == 1) { return; }
113
+
114
+ state.scopes.shift();
115
+ };
116
+
117
+ var tokenBase = function(stream, state) {
118
+ var ch = stream.peek();
119
+
120
+ // Single line Comment
121
+ if (stream.match('//')) {
122
+ stream.skipToEnd();
123
+ return "comment";
124
+ }
125
+
126
+ // Multiline Comment
127
+ if (stream.match('/*')){
128
+ state.tokenizer = multilineComment;
129
+ return state.tokenizer(stream, state);
130
+ }
131
+
132
+ // Interpolation
133
+ if (stream.match('#{')){
134
+ state.tokenizer = buildInterpolationTokenizer(tokenBase);
135
+ return "operator";
136
+ }
137
+
138
+ if (ch === "."){
139
+ stream.next();
140
+
141
+ // Match class selectors
142
+ if (stream.match(/^[\w-]+/)){
143
+ indent(state);
144
+ return "atom";
145
+ }else if (stream.peek() === "#"){
146
+ indent(state);
147
+ return "atom";
148
+ }else{
149
+ return "operator";
150
+ }
151
+ }
152
+
153
+ if (ch === "#"){
154
+ stream.next();
155
+
156
+ // Hex numbers
157
+ if (stream.match(/[0-9a-fA-F]{6}|[0-9a-fA-F]{3}/)){
158
+ return "number";
159
+ }
160
+
161
+ // ID selectors
162
+ if (stream.match(/^[\w-]+/)){
163
+ indent(state);
164
+ return "atom";
165
+ }
166
+
167
+ if (stream.peek() === "#"){
168
+ indent(state);
169
+ return "atom";
170
+ }
171
+ }
172
+
173
+ // Numbers
174
+ if (stream.match(/^-?[0-9\.]+/)){
175
+ return "number";
176
+ }
177
+
178
+ // Units
179
+ if (stream.match(/^(px|em|in)\b/)){
180
+ return "unit";
181
+ }
182
+
183
+ if (stream.match(keywordsRegexp)){
184
+ return "keyword";
185
+ }
186
+
187
+ if (stream.match(/^url/) && stream.peek() === "("){
188
+ state.tokenizer = urlTokens;
189
+ return "atom";
190
+ }
191
+
192
+ // Variables
193
+ if (ch === "$"){
194
+ stream.next();
195
+ stream.eatWhile(/[\w-]/);
196
+
197
+ if (stream.peek() === ":"){
198
+ stream.next();
199
+ return "variable-2";
200
+ }else{
201
+ return "variable-3";
202
+ }
203
+ }
204
+
205
+ if (ch === "!"){
206
+ stream.next();
207
+
208
+ if (stream.match(/^[\w]+/)){
209
+ return "keyword";
210
+ }
211
+
212
+ return "operator";
213
+ }
214
+
215
+ if (ch === "="){
216
+ stream.next();
217
+
218
+ // Match shortcut mixin definition
219
+ if (stream.match(/^[\w-]+/)){
220
+ indent(state);
221
+ return "meta";
222
+ }else {
223
+ return "operator";
224
+ }
225
+ }
226
+
227
+ if (ch === "+"){
228
+ stream.next();
229
+
230
+ // Match shortcut mixin definition
231
+ if (stream.match(/^[\w-]+/)){
232
+ return "variable-3";
233
+ }else {
234
+ return "operator";
235
+ }
236
+ }
237
+
238
+ // Indent Directives
239
+ if (stream.match(/^@(else if|if|media|else|for|each|while|mixin|function)/)){
240
+ indent(state);
241
+ return "meta";
242
+ }
243
+
244
+ // Other Directives
245
+ if (ch === "@"){
246
+ stream.next();
247
+ stream.eatWhile(/[\w-]/);
248
+ return "meta";
249
+ }
250
+
251
+ // Strings
252
+ if (ch === '"' || ch === "'"){
253
+ stream.next();
254
+ state.tokenizer = buildStringTokenizer(ch);
255
+ return "string";
256
+ }
257
+
258
+ // Pseudo element selectors
259
+ if (stream.match(pseudoElementsRegexp)){
260
+ return "keyword";
261
+ }
262
+
263
+ // atoms
264
+ if (stream.eatWhile(/[\w-&]/)){
265
+
266
+ var current = stream.current();
267
+ // matches a property definition
268
+ if (stream.peek() === ":"){
269
+ // if this is an html tag and it has a pseudo selector, then it's an atom
270
+ if (htmlTag(current) && stream.match(pseudoElementsRegexp, false)){
271
+ return "atom";
272
+ }else{
273
+ stream.next();
274
+ return "property";
275
+ }
276
+ }
277
+ return "atom";
278
+ }
279
+
280
+ if (stream.match(opRegexp)){
281
+ return "operator";
282
+ }
283
+
284
+ // If we haven't returned by now, we move 1 character
285
+ // and return an error
286
+ stream.next();
287
+ return 'error';
288
+ };
289
+
290
+ var tokenLexer = function(stream, state) {
291
+ if (stream.sol()){
292
+ state.indentCount = 0;
293
+ }
294
+ var style = state.tokenizer(stream, state);
295
+ var current = stream.current();
296
+
297
+ if (current === "@return"){
298
+ dedent(state);
299
+ }
300
+
301
+ if (style === "atom" && htmlTag(current)){
302
+ indent(state);
303
+ }
304
+
305
+ if (style !== "error"){
306
+ var startOfToken = stream.pos - current.length;
307
+ var withCurrentIndent = startOfToken + (config.indentUnit * state.indentCount);
308
+
309
+ var newScopes = [];
310
+
311
+ for (var i = 0; i < state.scopes.length; i++){
312
+ var scope = state.scopes[i];
313
+
314
+ if (scope.offset <= withCurrentIndent){
315
+ newScopes.push(scope);
316
+ }
317
+ }
318
+
319
+ state.scopes = newScopes;
320
+ }
321
+
322
+
323
+ return style;
324
+ };
325
+
326
+ return {
327
+ startState: function() {
328
+ return {
329
+ tokenizer: tokenBase,
330
+ scopes: [{offset: 0, type: 'sass'}],
331
+ definedVars: [],
332
+ definedMixins: [],
333
+ };
334
+ },
335
+ token: function(stream, state) {
336
+ var style = tokenLexer(stream, state);
337
+
338
+ state.lastToken = { style: style, content: stream.current() };
339
+
340
+ return style;
341
+ },
342
+
343
+ indent: function(state) {
344
+ return state.scopes[0].offset;
345
+ }
346
+ };
347
+ });
348
+
349
+ CodeMirror.defineMIME("text/x-sass", "sass");
@@ -31,19 +31,37 @@ CodeMirror.defineMode("sieve", function(config) {
31
31
  state.tokenize = tokenString(ch);
32
32
  return state.tokenize(stream, state);
33
33
  }
34
-
35
- if (ch === "{")
36
- {
37
- state._indent++;
34
+
35
+ if (ch == "(") {
36
+ state._indent.push("(");
37
+ // add virtual angel wings so that editor behaves...
38
+ // ...more sane incase of broken brackets
39
+ state._indent.push("{");
38
40
  return null;
39
41
  }
40
42
 
41
- if (ch === "}")
42
- {
43
- state._indent--;
43
+ if (ch === "{") {
44
+ state._indent.push("{");
44
45
  return null;
45
46
  }
47
+
48
+ if (ch == ")") {
49
+ state._indent.pop();
50
+ state._indent.pop();
51
+ }
46
52
 
53
+ if (ch === "}") {
54
+ state._indent.pop();
55
+ return null;
56
+ }
57
+
58
+ if (ch == ",")
59
+ return null;
60
+
61
+ if (ch == ";")
62
+ return null;
63
+
64
+
47
65
  if (/[{}\(\),;]/.test(ch))
48
66
  return null;
49
67
 
@@ -62,7 +80,7 @@ CodeMirror.defineMode("sieve", function(config) {
62
80
  return "operator";
63
81
  }
64
82
 
65
- stream.eatWhile(/[\w\$_]/);
83
+ stream.eatWhile(/\w/);
66
84
  var cur = stream.current();
67
85
 
68
86
  // "text:" *(SP / HTAB) (hash-comment / CRLF)
@@ -79,6 +97,8 @@ CodeMirror.defineMode("sieve", function(config) {
79
97
 
80
98
  if (atoms.propertyIsEnumerable(cur))
81
99
  return "atom";
100
+
101
+ return null;
82
102
  }
83
103
 
84
104
  function tokenMultiLineString(stream, state)
@@ -135,7 +155,7 @@ CodeMirror.defineMode("sieve", function(config) {
135
155
  startState: function(base) {
136
156
  return {tokenize: tokenBase,
137
157
  baseIndent: base || 0,
138
- _indent: 0};
158
+ _indent: []};
139
159
  },
140
160
 
141
161
  token: function(stream, state) {
@@ -146,7 +166,14 @@ CodeMirror.defineMode("sieve", function(config) {
146
166
  },
147
167
 
148
168
  indent: function(state, _textAfter) {
149
- return state.baseIndent + state._indent * indentUnit;
169
+ var length = state._indent.length;
170
+ if (_textAfter && (_textAfter[0] == "}"))
171
+ length--;
172
+
173
+ if (length <0)
174
+ length = 0;
175
+
176
+ return length * indentUnit;
150
177
  },
151
178
 
152
179
  electricChars: "}"