datagram 0.0.1

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 (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,609 @@
1
+ define('ace/mode/haxe', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/haxe_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 HaxeHighlightRules = require("./haxe_highlight_rules").HaxeHighlightRules;
8
+ var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
9
+ var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
10
+ var CStyleFoldMode = require("./folding/cstyle").FoldMode;
11
+
12
+ var Mode = function() {
13
+ this.$tokenizer = new Tokenizer(new HaxeHighlightRules().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
+ this.lineCommentStart = "//";
22
+ this.blockComment = {start: "/*", end: "*/"};
23
+
24
+ this.getNextLineIndent = function(state, line, tab) {
25
+ var indent = this.$getIndent(line);
26
+
27
+ var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
28
+ var tokens = tokenizedLine.tokens;
29
+
30
+ if (tokens.length && tokens[tokens.length-1].type == "comment") {
31
+ return indent;
32
+ }
33
+
34
+ if (state == "start") {
35
+ var match = line.match(/^.*[\{\(\[]\s*$/);
36
+ if (match) {
37
+ indent += tab;
38
+ }
39
+ }
40
+
41
+ return indent;
42
+ };
43
+
44
+ this.checkOutdent = function(state, line, input) {
45
+ return this.$outdent.checkOutdent(line, input);
46
+ };
47
+
48
+ this.autoOutdent = function(state, doc, row) {
49
+ this.$outdent.autoOutdent(doc, row);
50
+ };
51
+
52
+ }).call(Mode.prototype);
53
+
54
+ exports.Mode = Mode;
55
+ });
56
+ define('ace/mode/haxe_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/doc_comment_highlight_rules', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
57
+
58
+
59
+ var oop = require("../lib/oop");
60
+
61
+ var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
62
+ var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
63
+
64
+ var HaxeHighlightRules = function() {
65
+
66
+ var keywords = (
67
+ "break|case|cast|catch|class|continue|default|else|enum|extends|for|function|if|implements|import|in|inline|interface|new|override|package|private|public|return|static|super|switch|this|throw|trace|try|typedef|untyped|var|while|Array|Void|Bool|Int|UInt|Float|Dynamic|String|List|Hash|IntHash|Error|Unknown|Type|Std"
68
+ );
69
+
70
+ var buildinConstants = (
71
+ "null|true|false"
72
+ );
73
+
74
+ var keywordMapper = this.createKeywordMapper({
75
+ "variable.language": "this",
76
+ "keyword": keywords,
77
+ "constant.language": buildinConstants
78
+ }, "identifier");
79
+
80
+ this.$rules = {
81
+ "start" : [
82
+ {
83
+ token : "comment",
84
+ regex : "\\/\\/.*$"
85
+ },
86
+ DocCommentHighlightRules.getStartRule("doc-start"),
87
+ {
88
+ token : "comment", // multi line comment
89
+ regex : "\\/\\*",
90
+ next : "comment"
91
+ }, {
92
+ token : "string.regexp",
93
+ regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
94
+ }, {
95
+ token : "string", // single line
96
+ regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
97
+ }, {
98
+ token : "string", // single line
99
+ regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
100
+ }, {
101
+ token : "constant.numeric", // hex
102
+ regex : "0[xX][0-9a-fA-F]+\\b"
103
+ }, {
104
+ token : "constant.numeric", // float
105
+ regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
106
+ }, {
107
+ token : "constant.language.boolean",
108
+ regex : "(?:true|false)\\b"
109
+ }, {
110
+ token : keywordMapper,
111
+ regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
112
+ }, {
113
+ token : "keyword.operator",
114
+ regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
115
+ }, {
116
+ token : "punctuation.operator",
117
+ regex : "\\?|\\:|\\,|\\;|\\."
118
+ }, {
119
+ token : "paren.lparen",
120
+ regex : "[[({<]"
121
+ }, {
122
+ token : "paren.rparen",
123
+ regex : "[\\])}>]"
124
+ }, {
125
+ token : "text",
126
+ regex : "\\s+"
127
+ }
128
+ ],
129
+ "comment" : [
130
+ {
131
+ token : "comment", // closing comment
132
+ regex : ".*?\\*\\/",
133
+ next : "start"
134
+ }, {
135
+ token : "comment", // comment spanning whole line
136
+ regex : ".+"
137
+ }
138
+ ]
139
+ };
140
+
141
+ this.embedRules(DocCommentHighlightRules, "doc-",
142
+ [ DocCommentHighlightRules.getEndRule("start") ]);
143
+ };
144
+
145
+ oop.inherits(HaxeHighlightRules, TextHighlightRules);
146
+
147
+ exports.HaxeHighlightRules = HaxeHighlightRules;
148
+ });
149
+
150
+ define('ace/mode/doc_comment_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
151
+
152
+
153
+ var oop = require("../lib/oop");
154
+ var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
155
+
156
+ var DocCommentHighlightRules = function() {
157
+
158
+ this.$rules = {
159
+ "start" : [ {
160
+ token : "comment.doc.tag",
161
+ regex : "@[\\w\\d_]+" // TODO: fix email addresses
162
+ }, {
163
+ token : "comment.doc.tag",
164
+ regex : "\\bTODO\\b"
165
+ }, {
166
+ defaultToken : "comment.doc"
167
+ }]
168
+ };
169
+ };
170
+
171
+ oop.inherits(DocCommentHighlightRules, TextHighlightRules);
172
+
173
+ DocCommentHighlightRules.getStartRule = function(start) {
174
+ return {
175
+ token : "comment.doc", // doc comment
176
+ regex : "\\/\\*(?=\\*)",
177
+ next : start
178
+ };
179
+ };
180
+
181
+ DocCommentHighlightRules.getEndRule = function (start) {
182
+ return {
183
+ token : "comment.doc", // closing comment
184
+ regex : "\\*\\/",
185
+ next : start
186
+ };
187
+ };
188
+
189
+
190
+ exports.DocCommentHighlightRules = DocCommentHighlightRules;
191
+
192
+ });
193
+
194
+ define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
195
+
196
+
197
+ var Range = require("../range").Range;
198
+
199
+ var MatchingBraceOutdent = function() {};
200
+
201
+ (function() {
202
+
203
+ this.checkOutdent = function(line, input) {
204
+ if (! /^\s+$/.test(line))
205
+ return false;
206
+
207
+ return /^\s*\}/.test(input);
208
+ };
209
+
210
+ this.autoOutdent = function(doc, row) {
211
+ var line = doc.getLine(row);
212
+ var match = line.match(/^(\s*\})/);
213
+
214
+ if (!match) return 0;
215
+
216
+ var column = match[1].length;
217
+ var openBracePos = doc.findMatchingBracket({row: row, column: column});
218
+
219
+ if (!openBracePos || openBracePos.row == row) return 0;
220
+
221
+ var indent = this.$getIndent(doc.getLine(openBracePos.row));
222
+ doc.replace(new Range(row, 0, row, column-1), indent);
223
+ };
224
+
225
+ this.$getIndent = function(line) {
226
+ return line.match(/^\s*/)[0];
227
+ };
228
+
229
+ }).call(MatchingBraceOutdent.prototype);
230
+
231
+ exports.MatchingBraceOutdent = MatchingBraceOutdent;
232
+ });
233
+
234
+ define('ace/mode/behaviour/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour', 'ace/token_iterator', 'ace/lib/lang'], function(require, exports, module) {
235
+
236
+
237
+ var oop = require("../../lib/oop");
238
+ var Behaviour = require("../behaviour").Behaviour;
239
+ var TokenIterator = require("../../token_iterator").TokenIterator;
240
+ var lang = require("../../lib/lang");
241
+
242
+ var SAFE_INSERT_IN_TOKENS =
243
+ ["text", "paren.rparen", "punctuation.operator"];
244
+ var SAFE_INSERT_BEFORE_TOKENS =
245
+ ["text", "paren.rparen", "punctuation.operator", "comment"];
246
+
247
+
248
+ var autoInsertedBrackets = 0;
249
+ var autoInsertedRow = -1;
250
+ var autoInsertedLineEnd = "";
251
+ var maybeInsertedBrackets = 0;
252
+ var maybeInsertedRow = -1;
253
+ var maybeInsertedLineStart = "";
254
+ var maybeInsertedLineEnd = "";
255
+
256
+ var CstyleBehaviour = function () {
257
+
258
+ CstyleBehaviour.isSaneInsertion = function(editor, session) {
259
+ var cursor = editor.getCursorPosition();
260
+ var iterator = new TokenIterator(session, cursor.row, cursor.column);
261
+ if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
262
+ var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
263
+ if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
264
+ return false;
265
+ }
266
+ iterator.stepForward();
267
+ return iterator.getCurrentTokenRow() !== cursor.row ||
268
+ this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
269
+ };
270
+
271
+ CstyleBehaviour.$matchTokenType = function(token, types) {
272
+ return types.indexOf(token.type || token) > -1;
273
+ };
274
+
275
+ CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
276
+ var cursor = editor.getCursorPosition();
277
+ var line = session.doc.getLine(cursor.row);
278
+ if (!this.isAutoInsertedClosing(cursor, line, autoInsertedLineEnd[0]))
279
+ autoInsertedBrackets = 0;
280
+ autoInsertedRow = cursor.row;
281
+ autoInsertedLineEnd = bracket + line.substr(cursor.column);
282
+ autoInsertedBrackets++;
283
+ };
284
+
285
+ CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
286
+ var cursor = editor.getCursorPosition();
287
+ var line = session.doc.getLine(cursor.row);
288
+ if (!this.isMaybeInsertedClosing(cursor, line))
289
+ maybeInsertedBrackets = 0;
290
+ maybeInsertedRow = cursor.row;
291
+ maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
292
+ maybeInsertedLineEnd = line.substr(cursor.column);
293
+ maybeInsertedBrackets++;
294
+ };
295
+
296
+ CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
297
+ return autoInsertedBrackets > 0 &&
298
+ cursor.row === autoInsertedRow &&
299
+ bracket === autoInsertedLineEnd[0] &&
300
+ line.substr(cursor.column) === autoInsertedLineEnd;
301
+ };
302
+
303
+ CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
304
+ return maybeInsertedBrackets > 0 &&
305
+ cursor.row === maybeInsertedRow &&
306
+ line.substr(cursor.column) === maybeInsertedLineEnd &&
307
+ line.substr(0, cursor.column) == maybeInsertedLineStart;
308
+ };
309
+
310
+ CstyleBehaviour.popAutoInsertedClosing = function() {
311
+ autoInsertedLineEnd = autoInsertedLineEnd.substr(1);
312
+ autoInsertedBrackets--;
313
+ };
314
+
315
+ CstyleBehaviour.clearMaybeInsertedClosing = function() {
316
+ maybeInsertedBrackets = 0;
317
+ maybeInsertedRow = -1;
318
+ };
319
+
320
+ this.add("braces", "insertion", function (state, action, editor, session, text) {
321
+ var cursor = editor.getCursorPosition();
322
+ var line = session.doc.getLine(cursor.row);
323
+ if (text == '{') {
324
+ var selection = editor.getSelectionRange();
325
+ var selected = session.doc.getTextRange(selection);
326
+ if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
327
+ return {
328
+ text: '{' + selected + '}',
329
+ selection: false
330
+ };
331
+ } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
332
+ if (/[\]\}\)]/.test(line[cursor.column])) {
333
+ CstyleBehaviour.recordAutoInsert(editor, session, "}");
334
+ return {
335
+ text: '{}',
336
+ selection: [1, 1]
337
+ };
338
+ } else {
339
+ CstyleBehaviour.recordMaybeInsert(editor, session, "{");
340
+ return {
341
+ text: '{',
342
+ selection: [1, 1]
343
+ };
344
+ }
345
+ }
346
+ } else if (text == '}') {
347
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
348
+ if (rightChar == '}') {
349
+ var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
350
+ if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
351
+ CstyleBehaviour.popAutoInsertedClosing();
352
+ return {
353
+ text: '',
354
+ selection: [1, 1]
355
+ };
356
+ }
357
+ }
358
+ } else if (text == "\n" || text == "\r\n") {
359
+ var closing = "";
360
+ if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
361
+ closing = lang.stringRepeat("}", maybeInsertedBrackets);
362
+ CstyleBehaviour.clearMaybeInsertedClosing();
363
+ }
364
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
365
+ if (rightChar == '}' || closing !== "") {
366
+ var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column}, '}');
367
+ if (!openBracePos)
368
+ return null;
369
+
370
+ var indent = this.getNextLineIndent(state, line.substring(0, cursor.column), session.getTabString());
371
+ var next_indent = this.$getIndent(line);
372
+
373
+ return {
374
+ text: '\n' + indent + '\n' + next_indent + closing,
375
+ selection: [1, indent.length, 1, indent.length]
376
+ };
377
+ }
378
+ }
379
+ });
380
+
381
+ this.add("braces", "deletion", function (state, action, editor, session, range) {
382
+ var selected = session.doc.getTextRange(range);
383
+ if (!range.isMultiLine() && selected == '{') {
384
+ var line = session.doc.getLine(range.start.row);
385
+ var rightChar = line.substring(range.end.column, range.end.column + 1);
386
+ if (rightChar == '}') {
387
+ range.end.column++;
388
+ return range;
389
+ } else {
390
+ maybeInsertedBrackets--;
391
+ }
392
+ }
393
+ });
394
+
395
+ this.add("parens", "insertion", function (state, action, editor, session, text) {
396
+ if (text == '(') {
397
+ var selection = editor.getSelectionRange();
398
+ var selected = session.doc.getTextRange(selection);
399
+ if (selected !== "" && editor.getWrapBehavioursEnabled()) {
400
+ return {
401
+ text: '(' + selected + ')',
402
+ selection: false
403
+ };
404
+ } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
405
+ CstyleBehaviour.recordAutoInsert(editor, session, ")");
406
+ return {
407
+ text: '()',
408
+ selection: [1, 1]
409
+ };
410
+ }
411
+ } else if (text == ')') {
412
+ var cursor = editor.getCursorPosition();
413
+ var line = session.doc.getLine(cursor.row);
414
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
415
+ if (rightChar == ')') {
416
+ var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
417
+ if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
418
+ CstyleBehaviour.popAutoInsertedClosing();
419
+ return {
420
+ text: '',
421
+ selection: [1, 1]
422
+ };
423
+ }
424
+ }
425
+ }
426
+ });
427
+
428
+ this.add("parens", "deletion", function (state, action, editor, session, range) {
429
+ var selected = session.doc.getTextRange(range);
430
+ if (!range.isMultiLine() && selected == '(') {
431
+ var line = session.doc.getLine(range.start.row);
432
+ var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
433
+ if (rightChar == ')') {
434
+ range.end.column++;
435
+ return range;
436
+ }
437
+ }
438
+ });
439
+
440
+ this.add("brackets", "insertion", function (state, action, editor, session, text) {
441
+ if (text == '[') {
442
+ var selection = editor.getSelectionRange();
443
+ var selected = session.doc.getTextRange(selection);
444
+ if (selected !== "" && editor.getWrapBehavioursEnabled()) {
445
+ return {
446
+ text: '[' + selected + ']',
447
+ selection: false
448
+ };
449
+ } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
450
+ CstyleBehaviour.recordAutoInsert(editor, session, "]");
451
+ return {
452
+ text: '[]',
453
+ selection: [1, 1]
454
+ };
455
+ }
456
+ } else if (text == ']') {
457
+ var cursor = editor.getCursorPosition();
458
+ var line = session.doc.getLine(cursor.row);
459
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
460
+ if (rightChar == ']') {
461
+ var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
462
+ if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
463
+ CstyleBehaviour.popAutoInsertedClosing();
464
+ return {
465
+ text: '',
466
+ selection: [1, 1]
467
+ };
468
+ }
469
+ }
470
+ }
471
+ });
472
+
473
+ this.add("brackets", "deletion", function (state, action, editor, session, range) {
474
+ var selected = session.doc.getTextRange(range);
475
+ if (!range.isMultiLine() && selected == '[') {
476
+ var line = session.doc.getLine(range.start.row);
477
+ var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
478
+ if (rightChar == ']') {
479
+ range.end.column++;
480
+ return range;
481
+ }
482
+ }
483
+ });
484
+
485
+ this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
486
+ if (text == '"' || text == "'") {
487
+ var quote = text;
488
+ var selection = editor.getSelectionRange();
489
+ var selected = session.doc.getTextRange(selection);
490
+ if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
491
+ return {
492
+ text: quote + selected + quote,
493
+ selection: false
494
+ };
495
+ } else {
496
+ var cursor = editor.getCursorPosition();
497
+ var line = session.doc.getLine(cursor.row);
498
+ var leftChar = line.substring(cursor.column-1, cursor.column);
499
+ if (leftChar == '\\') {
500
+ return null;
501
+ }
502
+ var tokens = session.getTokens(selection.start.row);
503
+ var col = 0, token;
504
+ var quotepos = -1; // Track whether we're inside an open quote.
505
+
506
+ for (var x = 0; x < tokens.length; x++) {
507
+ token = tokens[x];
508
+ if (token.type == "string") {
509
+ quotepos = -1;
510
+ } else if (quotepos < 0) {
511
+ quotepos = token.value.indexOf(quote);
512
+ }
513
+ if ((token.value.length + col) > selection.start.column) {
514
+ break;
515
+ }
516
+ col += tokens[x].value.length;
517
+ }
518
+ 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)))) {
519
+ if (!CstyleBehaviour.isSaneInsertion(editor, session))
520
+ return;
521
+ return {
522
+ text: quote + quote,
523
+ selection: [1,1]
524
+ };
525
+ } else if (token && token.type === "string") {
526
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
527
+ if (rightChar == quote) {
528
+ return {
529
+ text: '',
530
+ selection: [1, 1]
531
+ };
532
+ }
533
+ }
534
+ }
535
+ }
536
+ });
537
+
538
+ this.add("string_dquotes", "deletion", function (state, action, editor, session, range) {
539
+ var selected = session.doc.getTextRange(range);
540
+ if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
541
+ var line = session.doc.getLine(range.start.row);
542
+ var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
543
+ if (rightChar == selected) {
544
+ range.end.column++;
545
+ return range;
546
+ }
547
+ }
548
+ });
549
+
550
+ };
551
+
552
+ oop.inherits(CstyleBehaviour, Behaviour);
553
+
554
+ exports.CstyleBehaviour = CstyleBehaviour;
555
+ });
556
+
557
+ define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
558
+
559
+
560
+ var oop = require("../../lib/oop");
561
+ var Range = require("../../range").Range;
562
+ var BaseFoldMode = require("./fold_mode").FoldMode;
563
+
564
+ var FoldMode = exports.FoldMode = function(commentRegex) {
565
+ if (commentRegex) {
566
+ this.foldingStartMarker = new RegExp(
567
+ this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
568
+ );
569
+ this.foldingStopMarker = new RegExp(
570
+ this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
571
+ );
572
+ }
573
+ };
574
+ oop.inherits(FoldMode, BaseFoldMode);
575
+
576
+ (function() {
577
+
578
+ this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
579
+ this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
580
+
581
+ this.getFoldWidgetRange = function(session, foldStyle, row) {
582
+ var line = session.getLine(row);
583
+ var match = line.match(this.foldingStartMarker);
584
+ if (match) {
585
+ var i = match.index;
586
+
587
+ if (match[1])
588
+ return this.openingBracketBlock(session, match[1], row, i);
589
+
590
+ return session.getCommentFoldRange(row, i + match[0].length, 1);
591
+ }
592
+
593
+ if (foldStyle !== "markbeginend")
594
+ return;
595
+
596
+ var match = line.match(this.foldingStopMarker);
597
+ if (match) {
598
+ var i = match.index + match[0].length;
599
+
600
+ if (match[1])
601
+ return this.closingBracketBlock(session, match[1], row, i);
602
+
603
+ return session.getCommentFoldRange(row, i, -1);
604
+ }
605
+ };
606
+
607
+ }).call(FoldMode.prototype);
608
+
609
+ });