datagram 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. data/.env.sample +7 -0
  2. data/.gitignore +20 -0
  3. data/.rbenv-version +1 -0
  4. data/Gemfile +12 -0
  5. data/LICENSE.txt +22 -0
  6. data/Procfile +1 -0
  7. data/README.md +29 -0
  8. data/Rakefile +1 -0
  9. data/config.ru +5 -0
  10. data/datagram.gemspec +23 -0
  11. data/db/migrate/1_create_queries.rb +9 -0
  12. data/db/migrate/2_add_name_to_queries.rb +5 -0
  13. data/lib/datagram/version.rb +3 -0
  14. data/lib/datagram.rb +135 -0
  15. data/lib/views/application.coffee +222 -0
  16. data/lib/views/index.haml +47 -0
  17. data/lib/views/layout.haml +17 -0
  18. data/lib/views/style.sass +179 -0
  19. data/public/ace/ace.js +15209 -0
  20. data/public/ace/ext-elastic_tabstops_lite.js +301 -0
  21. data/public/ace/ext-emmet.js +253 -0
  22. data/public/ace/ext-searchbox.js +441 -0
  23. data/public/ace/ext-spellcheck.js +67 -0
  24. data/public/ace/ext-static_highlight.js +96 -0
  25. data/public/ace/ext-textarea.js +492 -0
  26. data/public/ace/ext-whitespace.js +204 -0
  27. data/public/ace/keybinding-emacs.js +962 -0
  28. data/public/ace/keybinding-vim.js +1704 -0
  29. data/public/ace/mode-abap.js +260 -0
  30. data/public/ace/mode-asciidoc.js +372 -0
  31. data/public/ace/mode-c9search.js +182 -0
  32. data/public/ace/mode-c_cpp.js +737 -0
  33. data/public/ace/mode-clojure.js +299 -0
  34. data/public/ace/mode-coffee.js +426 -0
  35. data/public/ace/mode-coldfusion.js +1753 -0
  36. data/public/ace/mode-csharp.js +612 -0
  37. data/public/ace/mode-css.js +773 -0
  38. data/public/ace/mode-curly.js +1950 -0
  39. data/public/ace/mode-dart.js +945 -0
  40. data/public/ace/mode-diff.js +166 -0
  41. data/public/ace/mode-django.js +1969 -0
  42. data/public/ace/mode-dot.js +320 -0
  43. data/public/ace/mode-ftl.js +907 -0
  44. data/public/ace/mode-glsl.js +810 -0
  45. data/public/ace/mode-golang.js +632 -0
  46. data/public/ace/mode-groovy.js +1037 -0
  47. data/public/ace/mode-haml.js +487 -0
  48. data/public/ace/mode-haxe.js +609 -0
  49. data/public/ace/mode-html.js +1881 -0
  50. data/public/ace/mode-jade.js +1951 -0
  51. data/public/ace/mode-java.js +996 -0
  52. data/public/ace/mode-javascript.js +876 -0
  53. data/public/ace/mode-json.js +578 -0
  54. data/public/ace/mode-jsp.js +1351 -0
  55. data/public/ace/mode-jsx.js +635 -0
  56. data/public/ace/mode-latex.js +189 -0
  57. data/public/ace/mode-less.js +807 -0
  58. data/public/ace/mode-liquid.js +862 -0
  59. data/public/ace/mode-lisp.js +138 -0
  60. data/public/ace/mode-livescript.js +288 -0
  61. data/public/ace/mode-logiql.js +664 -0
  62. data/public/ace/mode-lsl.js +828 -0
  63. data/public/ace/mode-lua.js +455 -0
  64. data/public/ace/mode-luapage.js +2340 -0
  65. data/public/ace/mode-lucene.js +64 -0
  66. data/public/ace/mode-makefile.js +313 -0
  67. data/public/ace/mode-markdown.js +2280 -0
  68. data/public/ace/mode-mushcode.js +704 -0
  69. data/public/ace/mode-mushcode_high_rules.js +569 -0
  70. data/public/ace/mode-objectivec.js +659 -0
  71. data/public/ace/mode-ocaml.js +443 -0
  72. data/public/ace/mode-pascal.js +233 -0
  73. data/public/ace/mode-perl.js +316 -0
  74. data/public/ace/mode-pgsql.js +908 -0
  75. data/public/ace/mode-php.js +2291 -0
  76. data/public/ace/mode-powershell.js +618 -0
  77. data/public/ace/mode-python.js +264 -0
  78. data/public/ace/mode-r.js +404 -0
  79. data/public/ace/mode-rdoc.js +184 -0
  80. data/public/ace/mode-rhtml.js +2168 -0
  81. data/public/ace/mode-ruby.js +431 -0
  82. data/public/ace/mode-sass.js +442 -0
  83. data/public/ace/mode-scad.js +670 -0
  84. data/public/ace/mode-scala.js +1025 -0
  85. data/public/ace/mode-scheme.js +144 -0
  86. data/public/ace/mode-scss.js +832 -0
  87. data/public/ace/mode-sh.js +204 -0
  88. data/public/ace/mode-sql.js +118 -0
  89. data/public/ace/mode-stylus.js +483 -0
  90. data/public/ace/mode-svg.js +1442 -0
  91. data/public/ace/mode-tcl.js +319 -0
  92. data/public/ace/mode-tex.js +166 -0
  93. data/public/ace/mode-text.js +0 -0
  94. data/public/ace/mode-textile.js +170 -0
  95. data/public/ace/mode-tmsnippet.js +200 -0
  96. data/public/ace/mode-toml.js +180 -0
  97. data/public/ace/mode-typescript.js +961 -0
  98. data/public/ace/mode-vbscript.js +281 -0
  99. data/public/ace/mode-velocity.js +962 -0
  100. data/public/ace/mode-xml.js +789 -0
  101. data/public/ace/mode-xquery.js +2750 -0
  102. data/public/ace/mode-yaml.js +289 -0
  103. data/public/ace/theme-ambiance.js +202 -0
  104. data/public/ace/theme-chaos.js +182 -0
  105. data/public/ace/theme-chrome.js +161 -0
  106. data/public/ace/theme-clouds.js +135 -0
  107. data/public/ace/theme-clouds_midnight.js +136 -0
  108. data/public/ace/theme-cobalt.js +150 -0
  109. data/public/ace/theme-crimson_editor.js +154 -0
  110. data/public/ace/theme-dawn.js +146 -0
  111. data/public/ace/theme-dreamweaver.js +173 -0
  112. data/public/ace/theme-eclipse.js +122 -0
  113. data/public/ace/theme-github.js +136 -0
  114. data/public/ace/theme-idle_fingers.js +136 -0
  115. data/public/ace/theme-kr.js +143 -0
  116. data/public/ace/theme-merbivore.js +135 -0
  117. data/public/ace/theme-merbivore_soft.js +136 -0
  118. data/public/ace/theme-mono_industrial.js +148 -0
  119. data/public/ace/theme-monokai.js +140 -0
  120. data/public/ace/theme-pastel_on_dark.js +148 -0
  121. data/public/ace/theme-solarized_dark.js +128 -0
  122. data/public/ace/theme-solarized_light.js +131 -0
  123. data/public/ace/theme-terminal.js +154 -0
  124. data/public/ace/theme-textmate.js +0 -0
  125. data/public/ace/theme-tomorrow.js +147 -0
  126. data/public/ace/theme-tomorrow_night.js +147 -0
  127. data/public/ace/theme-tomorrow_night_blue.js +145 -0
  128. data/public/ace/theme-tomorrow_night_bright.js +147 -0
  129. data/public/ace/theme-tomorrow_night_eighties.js +144 -0
  130. data/public/ace/theme-twilight.js +147 -0
  131. data/public/ace/theme-vibrant_ink.js +131 -0
  132. data/public/ace/theme-xcode.js +125 -0
  133. data/public/ace/worker-coffee.js +7091 -0
  134. data/public/ace/worker-css.js +8289 -0
  135. data/public/ace/worker-javascript.js +6496 -0
  136. data/public/ace/worker-json.js +2305 -0
  137. data/public/ace/worker-lua.js +3313 -0
  138. data/public/ace/worker-php.js +6743 -0
  139. data/public/ace/worker-xquery.js +21897 -0
  140. data/public/font/FontAwesome.otf +0 -0
  141. data/public/font/fontawesome-webfont.eot +0 -0
  142. data/public/font/fontawesome-webfont.svg +284 -0
  143. data/public/font/fontawesome-webfont.ttf +0 -0
  144. data/public/font/fontawesome-webfont.woff +0 -0
  145. data/public/font-awesome.css +540 -0
  146. data/public/jquery.js +9597 -0
  147. data/script/migrate.sh +2 -0
  148. metadata +242 -0
@@ -0,0 +1,635 @@
1
+ define('ace/mode/jsx', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/jsx_highlight_rules', 'ace/mode/matching_brace_outdent', 'ace/mode/behaviour/cstyle', 'ace/mode/folding/cstyle'], function(require, exports, module) {
2
+
3
+
4
+ var oop = require("../lib/oop");
5
+ var TextMode = require("./text").Mode;
6
+ var Tokenizer = require("../tokenizer").Tokenizer;
7
+ var JsxHighlightRules = require("./jsx_highlight_rules").JsxHighlightRules;
8
+ var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
9
+ var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
10
+ var CStyleFoldMode = require("./folding/cstyle").FoldMode;
11
+
12
+ function Mode() {
13
+ this.$tokenizer = new Tokenizer(new JsxHighlightRules().getRules());
14
+ this.$outdent = new MatchingBraceOutdent();
15
+ this.$behaviour = new CstyleBehaviour();
16
+ this.foldingRules = new CStyleFoldMode();
17
+ }
18
+ oop.inherits(Mode, TextMode);
19
+
20
+ (function() {
21
+
22
+ this.lineCommentStart = "//";
23
+ this.blockComment = {start: "/*", end: "*/"};
24
+
25
+ this.getNextLineIndent = function(state, line, tab) {
26
+ var indent = this.$getIndent(line);
27
+
28
+ var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
29
+ var tokens = tokenizedLine.tokens;
30
+
31
+ if (tokens.length && tokens[tokens.length-1].type == "comment") {
32
+ return indent;
33
+ }
34
+
35
+ if (state == "start") {
36
+ var match = line.match(/^.*[\{\(\[]\s*$/);
37
+ if (match) {
38
+ indent += tab;
39
+ }
40
+ }
41
+
42
+ return indent;
43
+ };
44
+
45
+ this.checkOutdent = function(state, line, input) {
46
+ return this.$outdent.checkOutdent(line, input);
47
+ };
48
+
49
+ this.autoOutdent = function(state, doc, row) {
50
+ this.$outdent.autoOutdent(doc, row);
51
+ };
52
+
53
+ }).call(Mode.prototype);
54
+
55
+ exports.Mode = Mode;
56
+ });
57
+ define('ace/mode/jsx_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/lang', 'ace/mode/doc_comment_highlight_rules', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
58
+ var oop = require("../lib/oop");
59
+ var lang = require("../lib/lang");
60
+ var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
61
+ var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
62
+
63
+ var JsxHighlightRules = function() {
64
+ var keywords = lang.arrayToMap(
65
+ ("break|do|instanceof|typeof|case|else|new|var|catch|finally|return|void|continue|for|switch|default|while|function|this|" +
66
+ "if|throw|" +
67
+ "delete|in|try|" +
68
+ "class|extends|super|import|from|into|implements|interface|static|mixin|override|abstract|final|" +
69
+ "number|int|string|boolean|variant|" +
70
+ "log|assert").split("|")
71
+ );
72
+
73
+ var buildinConstants = lang.arrayToMap(
74
+ ("null|true|false|NaN|Infinity|__FILE__|__LINE__|undefined").split("|")
75
+ );
76
+
77
+ var reserved = lang.arrayToMap(
78
+ ("debugger|with|" +
79
+ "const|export|" +
80
+ "let|private|public|yield|protected|" +
81
+ "extern|native|as|operator|__fake__|__readonly__").split("|")
82
+ );
83
+
84
+ var identifierRe = "[a-zA-Z_][a-zA-Z0-9_]*\\b";
85
+
86
+ this.$rules = {
87
+ "start" : [
88
+ {
89
+ token : "comment",
90
+ regex : "\\/\\/.*$"
91
+ },
92
+ DocCommentHighlightRules.getStartRule("doc-start"),
93
+ {
94
+ token : "comment", // multi line comment
95
+ regex : "\\/\\*",
96
+ next : "comment"
97
+ }, {
98
+ token : "string.regexp",
99
+ regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
100
+ }, {
101
+ token : "string", // single line
102
+ regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
103
+ }, {
104
+ token : "string", // single line
105
+ regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
106
+ }, {
107
+ token : "constant.numeric", // hex
108
+ regex : "0[xX][0-9a-fA-F]+\\b"
109
+ }, {
110
+ token : "constant.numeric", // float
111
+ regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
112
+ }, {
113
+ token : "constant.language.boolean",
114
+ regex : "(?:true|false)\\b"
115
+ }, {
116
+ token : [
117
+ "storage.type",
118
+ "text",
119
+ "entity.name.function"
120
+ ],
121
+ regex : "(function)(\\s+)(" + identifierRe + ")"
122
+ }, {
123
+ token : function(value) {
124
+ if (value == "this")
125
+ return "variable.language";
126
+ else if (value == "function")
127
+ return "storage.type";
128
+ else if (keywords.hasOwnProperty(value) || reserved.hasOwnProperty(value))
129
+ return "keyword";
130
+ else if (buildinConstants.hasOwnProperty(value))
131
+ return "constant.language";
132
+ else if (/^_?[A-Z][a-zA-Z0-9_]*$/.test(value))
133
+ return "language.support.class";
134
+ else
135
+ return "identifier";
136
+ },
137
+ regex : identifierRe
138
+ }, {
139
+ token : "keyword.operator",
140
+ regex : "!|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|==|=|!=|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
141
+ }, {
142
+ token : "punctuation.operator",
143
+ regex : "\\?|\\:|\\,|\\;|\\."
144
+ }, {
145
+ token : "paren.lparen",
146
+ regex : "[[({<]"
147
+ }, {
148
+ token : "paren.rparen",
149
+ regex : "[\\])}>]"
150
+ }, {
151
+ token : "text",
152
+ regex : "\\s+"
153
+ }
154
+ ],
155
+ "comment" : [
156
+ {
157
+ token : "comment", // closing comment
158
+ regex : ".*?\\*\\/",
159
+ next : "start"
160
+ }, {
161
+ token : "comment", // comment spanning whole line
162
+ regex : ".+"
163
+ }
164
+ ]
165
+ };
166
+
167
+ this.embedRules(DocCommentHighlightRules, "doc-",
168
+ [ DocCommentHighlightRules.getEndRule("start") ]);
169
+ };
170
+
171
+ oop.inherits(JsxHighlightRules, TextHighlightRules);
172
+
173
+ exports.JsxHighlightRules = JsxHighlightRules;
174
+ });
175
+
176
+ define('ace/mode/doc_comment_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
177
+
178
+
179
+ var oop = require("../lib/oop");
180
+ var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
181
+
182
+ var DocCommentHighlightRules = function() {
183
+
184
+ this.$rules = {
185
+ "start" : [ {
186
+ token : "comment.doc.tag",
187
+ regex : "@[\\w\\d_]+" // TODO: fix email addresses
188
+ }, {
189
+ token : "comment.doc.tag",
190
+ regex : "\\bTODO\\b"
191
+ }, {
192
+ defaultToken : "comment.doc"
193
+ }]
194
+ };
195
+ };
196
+
197
+ oop.inherits(DocCommentHighlightRules, TextHighlightRules);
198
+
199
+ DocCommentHighlightRules.getStartRule = function(start) {
200
+ return {
201
+ token : "comment.doc", // doc comment
202
+ regex : "\\/\\*(?=\\*)",
203
+ next : start
204
+ };
205
+ };
206
+
207
+ DocCommentHighlightRules.getEndRule = function (start) {
208
+ return {
209
+ token : "comment.doc", // closing comment
210
+ regex : "\\*\\/",
211
+ next : start
212
+ };
213
+ };
214
+
215
+
216
+ exports.DocCommentHighlightRules = DocCommentHighlightRules;
217
+
218
+ });
219
+
220
+ define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
221
+
222
+
223
+ var Range = require("../range").Range;
224
+
225
+ var MatchingBraceOutdent = function() {};
226
+
227
+ (function() {
228
+
229
+ this.checkOutdent = function(line, input) {
230
+ if (! /^\s+$/.test(line))
231
+ return false;
232
+
233
+ return /^\s*\}/.test(input);
234
+ };
235
+
236
+ this.autoOutdent = function(doc, row) {
237
+ var line = doc.getLine(row);
238
+ var match = line.match(/^(\s*\})/);
239
+
240
+ if (!match) return 0;
241
+
242
+ var column = match[1].length;
243
+ var openBracePos = doc.findMatchingBracket({row: row, column: column});
244
+
245
+ if (!openBracePos || openBracePos.row == row) return 0;
246
+
247
+ var indent = this.$getIndent(doc.getLine(openBracePos.row));
248
+ doc.replace(new Range(row, 0, row, column-1), indent);
249
+ };
250
+
251
+ this.$getIndent = function(line) {
252
+ return line.match(/^\s*/)[0];
253
+ };
254
+
255
+ }).call(MatchingBraceOutdent.prototype);
256
+
257
+ exports.MatchingBraceOutdent = MatchingBraceOutdent;
258
+ });
259
+
260
+ define('ace/mode/behaviour/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour', 'ace/token_iterator', 'ace/lib/lang'], function(require, exports, module) {
261
+
262
+
263
+ var oop = require("../../lib/oop");
264
+ var Behaviour = require("../behaviour").Behaviour;
265
+ var TokenIterator = require("../../token_iterator").TokenIterator;
266
+ var lang = require("../../lib/lang");
267
+
268
+ var SAFE_INSERT_IN_TOKENS =
269
+ ["text", "paren.rparen", "punctuation.operator"];
270
+ var SAFE_INSERT_BEFORE_TOKENS =
271
+ ["text", "paren.rparen", "punctuation.operator", "comment"];
272
+
273
+
274
+ var autoInsertedBrackets = 0;
275
+ var autoInsertedRow = -1;
276
+ var autoInsertedLineEnd = "";
277
+ var maybeInsertedBrackets = 0;
278
+ var maybeInsertedRow = -1;
279
+ var maybeInsertedLineStart = "";
280
+ var maybeInsertedLineEnd = "";
281
+
282
+ var CstyleBehaviour = function () {
283
+
284
+ CstyleBehaviour.isSaneInsertion = function(editor, session) {
285
+ var cursor = editor.getCursorPosition();
286
+ var iterator = new TokenIterator(session, cursor.row, cursor.column);
287
+ if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
288
+ var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
289
+ if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
290
+ return false;
291
+ }
292
+ iterator.stepForward();
293
+ return iterator.getCurrentTokenRow() !== cursor.row ||
294
+ this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
295
+ };
296
+
297
+ CstyleBehaviour.$matchTokenType = function(token, types) {
298
+ return types.indexOf(token.type || token) > -1;
299
+ };
300
+
301
+ CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
302
+ var cursor = editor.getCursorPosition();
303
+ var line = session.doc.getLine(cursor.row);
304
+ if (!this.isAutoInsertedClosing(cursor, line, autoInsertedLineEnd[0]))
305
+ autoInsertedBrackets = 0;
306
+ autoInsertedRow = cursor.row;
307
+ autoInsertedLineEnd = bracket + line.substr(cursor.column);
308
+ autoInsertedBrackets++;
309
+ };
310
+
311
+ CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
312
+ var cursor = editor.getCursorPosition();
313
+ var line = session.doc.getLine(cursor.row);
314
+ if (!this.isMaybeInsertedClosing(cursor, line))
315
+ maybeInsertedBrackets = 0;
316
+ maybeInsertedRow = cursor.row;
317
+ maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
318
+ maybeInsertedLineEnd = line.substr(cursor.column);
319
+ maybeInsertedBrackets++;
320
+ };
321
+
322
+ CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
323
+ return autoInsertedBrackets > 0 &&
324
+ cursor.row === autoInsertedRow &&
325
+ bracket === autoInsertedLineEnd[0] &&
326
+ line.substr(cursor.column) === autoInsertedLineEnd;
327
+ };
328
+
329
+ CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
330
+ return maybeInsertedBrackets > 0 &&
331
+ cursor.row === maybeInsertedRow &&
332
+ line.substr(cursor.column) === maybeInsertedLineEnd &&
333
+ line.substr(0, cursor.column) == maybeInsertedLineStart;
334
+ };
335
+
336
+ CstyleBehaviour.popAutoInsertedClosing = function() {
337
+ autoInsertedLineEnd = autoInsertedLineEnd.substr(1);
338
+ autoInsertedBrackets--;
339
+ };
340
+
341
+ CstyleBehaviour.clearMaybeInsertedClosing = function() {
342
+ maybeInsertedBrackets = 0;
343
+ maybeInsertedRow = -1;
344
+ };
345
+
346
+ this.add("braces", "insertion", function (state, action, editor, session, text) {
347
+ var cursor = editor.getCursorPosition();
348
+ var line = session.doc.getLine(cursor.row);
349
+ if (text == '{') {
350
+ var selection = editor.getSelectionRange();
351
+ var selected = session.doc.getTextRange(selection);
352
+ if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
353
+ return {
354
+ text: '{' + selected + '}',
355
+ selection: false
356
+ };
357
+ } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
358
+ if (/[\]\}\)]/.test(line[cursor.column])) {
359
+ CstyleBehaviour.recordAutoInsert(editor, session, "}");
360
+ return {
361
+ text: '{}',
362
+ selection: [1, 1]
363
+ };
364
+ } else {
365
+ CstyleBehaviour.recordMaybeInsert(editor, session, "{");
366
+ return {
367
+ text: '{',
368
+ selection: [1, 1]
369
+ };
370
+ }
371
+ }
372
+ } else if (text == '}') {
373
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
374
+ if (rightChar == '}') {
375
+ var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
376
+ if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
377
+ CstyleBehaviour.popAutoInsertedClosing();
378
+ return {
379
+ text: '',
380
+ selection: [1, 1]
381
+ };
382
+ }
383
+ }
384
+ } else if (text == "\n" || text == "\r\n") {
385
+ var closing = "";
386
+ if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
387
+ closing = lang.stringRepeat("}", maybeInsertedBrackets);
388
+ CstyleBehaviour.clearMaybeInsertedClosing();
389
+ }
390
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
391
+ if (rightChar == '}' || closing !== "") {
392
+ var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column}, '}');
393
+ if (!openBracePos)
394
+ return null;
395
+
396
+ var indent = this.getNextLineIndent(state, line.substring(0, cursor.column), session.getTabString());
397
+ var next_indent = this.$getIndent(line);
398
+
399
+ return {
400
+ text: '\n' + indent + '\n' + next_indent + closing,
401
+ selection: [1, indent.length, 1, indent.length]
402
+ };
403
+ }
404
+ }
405
+ });
406
+
407
+ this.add("braces", "deletion", function (state, action, editor, session, range) {
408
+ var selected = session.doc.getTextRange(range);
409
+ if (!range.isMultiLine() && selected == '{') {
410
+ var line = session.doc.getLine(range.start.row);
411
+ var rightChar = line.substring(range.end.column, range.end.column + 1);
412
+ if (rightChar == '}') {
413
+ range.end.column++;
414
+ return range;
415
+ } else {
416
+ maybeInsertedBrackets--;
417
+ }
418
+ }
419
+ });
420
+
421
+ this.add("parens", "insertion", function (state, action, editor, session, text) {
422
+ if (text == '(') {
423
+ var selection = editor.getSelectionRange();
424
+ var selected = session.doc.getTextRange(selection);
425
+ if (selected !== "" && editor.getWrapBehavioursEnabled()) {
426
+ return {
427
+ text: '(' + selected + ')',
428
+ selection: false
429
+ };
430
+ } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
431
+ CstyleBehaviour.recordAutoInsert(editor, session, ")");
432
+ return {
433
+ text: '()',
434
+ selection: [1, 1]
435
+ };
436
+ }
437
+ } else if (text == ')') {
438
+ var cursor = editor.getCursorPosition();
439
+ var line = session.doc.getLine(cursor.row);
440
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
441
+ if (rightChar == ')') {
442
+ var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
443
+ if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
444
+ CstyleBehaviour.popAutoInsertedClosing();
445
+ return {
446
+ text: '',
447
+ selection: [1, 1]
448
+ };
449
+ }
450
+ }
451
+ }
452
+ });
453
+
454
+ this.add("parens", "deletion", function (state, action, editor, session, range) {
455
+ var selected = session.doc.getTextRange(range);
456
+ if (!range.isMultiLine() && selected == '(') {
457
+ var line = session.doc.getLine(range.start.row);
458
+ var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
459
+ if (rightChar == ')') {
460
+ range.end.column++;
461
+ return range;
462
+ }
463
+ }
464
+ });
465
+
466
+ this.add("brackets", "insertion", function (state, action, editor, session, text) {
467
+ if (text == '[') {
468
+ var selection = editor.getSelectionRange();
469
+ var selected = session.doc.getTextRange(selection);
470
+ if (selected !== "" && editor.getWrapBehavioursEnabled()) {
471
+ return {
472
+ text: '[' + selected + ']',
473
+ selection: false
474
+ };
475
+ } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
476
+ CstyleBehaviour.recordAutoInsert(editor, session, "]");
477
+ return {
478
+ text: '[]',
479
+ selection: [1, 1]
480
+ };
481
+ }
482
+ } else if (text == ']') {
483
+ var cursor = editor.getCursorPosition();
484
+ var line = session.doc.getLine(cursor.row);
485
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
486
+ if (rightChar == ']') {
487
+ var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
488
+ if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
489
+ CstyleBehaviour.popAutoInsertedClosing();
490
+ return {
491
+ text: '',
492
+ selection: [1, 1]
493
+ };
494
+ }
495
+ }
496
+ }
497
+ });
498
+
499
+ this.add("brackets", "deletion", function (state, action, editor, session, range) {
500
+ var selected = session.doc.getTextRange(range);
501
+ if (!range.isMultiLine() && selected == '[') {
502
+ var line = session.doc.getLine(range.start.row);
503
+ var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
504
+ if (rightChar == ']') {
505
+ range.end.column++;
506
+ return range;
507
+ }
508
+ }
509
+ });
510
+
511
+ this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
512
+ if (text == '"' || text == "'") {
513
+ var quote = text;
514
+ var selection = editor.getSelectionRange();
515
+ var selected = session.doc.getTextRange(selection);
516
+ if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
517
+ return {
518
+ text: quote + selected + quote,
519
+ selection: false
520
+ };
521
+ } else {
522
+ var cursor = editor.getCursorPosition();
523
+ var line = session.doc.getLine(cursor.row);
524
+ var leftChar = line.substring(cursor.column-1, cursor.column);
525
+ if (leftChar == '\\') {
526
+ return null;
527
+ }
528
+ var tokens = session.getTokens(selection.start.row);
529
+ var col = 0, token;
530
+ var quotepos = -1; // Track whether we're inside an open quote.
531
+
532
+ for (var x = 0; x < tokens.length; x++) {
533
+ token = tokens[x];
534
+ if (token.type == "string") {
535
+ quotepos = -1;
536
+ } else if (quotepos < 0) {
537
+ quotepos = token.value.indexOf(quote);
538
+ }
539
+ if ((token.value.length + col) > selection.start.column) {
540
+ break;
541
+ }
542
+ col += tokens[x].value.length;
543
+ }
544
+ if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) {
545
+ if (!CstyleBehaviour.isSaneInsertion(editor, session))
546
+ return;
547
+ return {
548
+ text: quote + quote,
549
+ selection: [1,1]
550
+ };
551
+ } else if (token && token.type === "string") {
552
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
553
+ if (rightChar == quote) {
554
+ return {
555
+ text: '',
556
+ selection: [1, 1]
557
+ };
558
+ }
559
+ }
560
+ }
561
+ }
562
+ });
563
+
564
+ this.add("string_dquotes", "deletion", function (state, action, editor, session, range) {
565
+ var selected = session.doc.getTextRange(range);
566
+ if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
567
+ var line = session.doc.getLine(range.start.row);
568
+ var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
569
+ if (rightChar == selected) {
570
+ range.end.column++;
571
+ return range;
572
+ }
573
+ }
574
+ });
575
+
576
+ };
577
+
578
+ oop.inherits(CstyleBehaviour, Behaviour);
579
+
580
+ exports.CstyleBehaviour = CstyleBehaviour;
581
+ });
582
+
583
+ define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
584
+
585
+
586
+ var oop = require("../../lib/oop");
587
+ var Range = require("../../range").Range;
588
+ var BaseFoldMode = require("./fold_mode").FoldMode;
589
+
590
+ var FoldMode = exports.FoldMode = function(commentRegex) {
591
+ if (commentRegex) {
592
+ this.foldingStartMarker = new RegExp(
593
+ this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
594
+ );
595
+ this.foldingStopMarker = new RegExp(
596
+ this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
597
+ );
598
+ }
599
+ };
600
+ oop.inherits(FoldMode, BaseFoldMode);
601
+
602
+ (function() {
603
+
604
+ this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
605
+ this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
606
+
607
+ this.getFoldWidgetRange = function(session, foldStyle, row) {
608
+ var line = session.getLine(row);
609
+ var match = line.match(this.foldingStartMarker);
610
+ if (match) {
611
+ var i = match.index;
612
+
613
+ if (match[1])
614
+ return this.openingBracketBlock(session, match[1], row, i);
615
+
616
+ return session.getCommentFoldRange(row, i + match[0].length, 1);
617
+ }
618
+
619
+ if (foldStyle !== "markbeginend")
620
+ return;
621
+
622
+ var match = line.match(this.foldingStopMarker);
623
+ if (match) {
624
+ var i = match.index + match[0].length;
625
+
626
+ if (match[1])
627
+ return this.closingBracketBlock(session, match[1], row, i);
628
+
629
+ return session.getCommentFoldRange(row, i, -1);
630
+ }
631
+ };
632
+
633
+ }).call(FoldMode.prototype);
634
+
635
+ });