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,301 @@
1
+ /* ***** BEGIN LICENSE BLOCK *****
2
+ * Distributed under the BSD license:
3
+ *
4
+ * Copyright (c) 2012, Ajax.org B.V.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without
8
+ * modification, are permitted provided that the following conditions are met:
9
+ * * Redistributions of source code must retain the above copyright
10
+ * notice, this list of conditions and the following disclaimer.
11
+ * * Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following disclaimer in the
13
+ * documentation and/or other materials provided with the distribution.
14
+ * * Neither the name of Ajax.org B.V. nor the
15
+ * names of its contributors may be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
22
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ *
29
+ * ***** END LICENSE BLOCK ***** */
30
+
31
+ define('ace/ext/elastic_tabstops_lite', ['require', 'exports', 'module' , 'ace/editor', 'ace/config'], function(require, exports, module) {
32
+
33
+
34
+ var ElasticTabstopsLite = function(editor) {
35
+ this.$editor = editor;
36
+ var self = this;
37
+ var changedRows = [];
38
+ var recordChanges = false;
39
+ this.onAfterExec = function() {
40
+ recordChanges = false;
41
+ self.processRows(changedRows);
42
+ changedRows = [];
43
+ };
44
+ this.onExec = function() {
45
+ recordChanges = true;
46
+ };
47
+ this.onChange = function(e) {
48
+ var range = e.data.range
49
+ if (recordChanges) {
50
+ if (changedRows.indexOf(range.start.row) == -1)
51
+ changedRows.push(range.start.row);
52
+ if (range.end.row != range.start.row)
53
+ changedRows.push(range.end.row);
54
+ }
55
+ };
56
+ };
57
+
58
+ (function() {
59
+ this.processRows = function(rows) {
60
+ this.$inChange = true;
61
+ var checkedRows = [];
62
+
63
+ for (var r = 0, rowCount = rows.length; r < rowCount; r++) {
64
+ var row = rows[r];
65
+
66
+ if (checkedRows.indexOf(row) > -1)
67
+ continue;
68
+
69
+ var cellWidthObj = this.$findCellWidthsForBlock(row);
70
+ var cellWidths = this.$setBlockCellWidthsToMax(cellWidthObj.cellWidths);
71
+ var rowIndex = cellWidthObj.firstRow;
72
+
73
+ for (var w = 0, l = cellWidths.length; w < l; w++) {
74
+ var widths = cellWidths[w];
75
+ checkedRows.push(rowIndex);
76
+ this.$adjustRow(rowIndex, widths);
77
+ rowIndex++;
78
+ }
79
+ }
80
+ this.$inChange = false;
81
+ };
82
+
83
+ this.$findCellWidthsForBlock = function(row) {
84
+ var cellWidths = [], widths;
85
+ var rowIter = row;
86
+ while (rowIter >= 0) {
87
+ widths = this.$cellWidthsForRow(rowIter);
88
+ if (widths.length == 0)
89
+ break;
90
+
91
+ cellWidths.unshift(widths);
92
+ rowIter--;
93
+ }
94
+ var firstRow = rowIter + 1;
95
+ rowIter = row;
96
+ var numRows = this.$editor.session.getLength();
97
+
98
+ while (rowIter < numRows - 1) {
99
+ rowIter++;
100
+
101
+ widths = this.$cellWidthsForRow(rowIter);
102
+ if (widths.length == 0)
103
+ break;
104
+
105
+ cellWidths.push(widths);
106
+ }
107
+
108
+ return { cellWidths: cellWidths, firstRow: firstRow };
109
+ };
110
+
111
+ this.$cellWidthsForRow = function(row) {
112
+ var selectionColumns = this.$selectionColumnsForRow(row);
113
+
114
+ var tabs = [-1].concat(this.$tabsForRow(row));
115
+ var widths = tabs.map(function (el) { return 0; } ).slice(1);
116
+ var line = this.$editor.session.getLine(row);
117
+
118
+ for (var i = 0, len = tabs.length - 1; i < len; i++) {
119
+ var leftEdge = tabs[i]+1;
120
+ var rightEdge = tabs[i+1];
121
+
122
+ var rightmostSelection = this.$rightmostSelectionInCell(selectionColumns, rightEdge);
123
+ var cell = line.substring(leftEdge, rightEdge);
124
+ widths[i] = Math.max(cell.replace(/\s+$/g,'').length, rightmostSelection - leftEdge);
125
+ }
126
+
127
+ return widths;
128
+ };
129
+
130
+ this.$selectionColumnsForRow = function(row) {
131
+ var selections = [], cursor = this.$editor.getCursorPosition();
132
+ if (this.$editor.session.getSelection().isEmpty()) {
133
+ if (row == cursor.row)
134
+ selections.push(cursor.column);
135
+ }
136
+
137
+ return selections;
138
+ };
139
+
140
+ this.$setBlockCellWidthsToMax = function(cellWidths) {
141
+ var startingNewBlock = true, blockStartRow, blockEndRow, maxWidth;
142
+ var columnInfo = this.$izip_longest(cellWidths);
143
+
144
+ for (var c = 0, l = columnInfo.length; c < l; c++) {
145
+ var column = columnInfo[c];
146
+ if (!column.push) {
147
+ console.error(column);
148
+ continue;
149
+ }
150
+ column.push(NaN);
151
+
152
+ for (var r = 0, s = column.length; r < s; r++) {
153
+ var width = column[r];
154
+ if (startingNewBlock) {
155
+ blockStartRow = r;
156
+ maxWidth = 0;
157
+ startingNewBlock = false;
158
+ }
159
+ if (isNaN(width)) {
160
+ blockEndRow = r;
161
+
162
+ for (var j = blockStartRow; j < blockEndRow; j++) {
163
+ cellWidths[j][c] = maxWidth;
164
+ }
165
+ startingNewBlock = true;
166
+ }
167
+
168
+ maxWidth = Math.max(maxWidth, width);
169
+ }
170
+ }
171
+
172
+ return cellWidths;
173
+ };
174
+
175
+ this.$rightmostSelectionInCell = function(selectionColumns, cellRightEdge) {
176
+ var rightmost = 0;
177
+
178
+ if (selectionColumns.length) {
179
+ var lengths = [];
180
+ for (var s = 0, length = selectionColumns.length; s < length; s++) {
181
+ if (selectionColumns[s] <= cellRightEdge)
182
+ lengths.push(s);
183
+ else
184
+ lengths.push(0);
185
+ }
186
+ rightmost = Math.max.apply(Math, lengths);
187
+ }
188
+
189
+ return rightmost;
190
+ };
191
+
192
+ this.$tabsForRow = function(row) {
193
+ var rowTabs = [], line = this.$editor.session.getLine(row),
194
+ re = /\t/g, match;
195
+
196
+ while ((match = re.exec(line)) != null) {
197
+ rowTabs.push(match.index);
198
+ }
199
+
200
+ return rowTabs;
201
+ };
202
+
203
+ this.$adjustRow = function(row, widths) {
204
+ var rowTabs = this.$tabsForRow(row);
205
+
206
+ if (rowTabs.length == 0)
207
+ return;
208
+
209
+ var bias = 0, location = -1;
210
+ var expandedSet = this.$izip(widths, rowTabs);
211
+
212
+ for (var i = 0, l = expandedSet.length; i < l; i++) {
213
+ var w = expandedSet[i][0], it = expandedSet[i][1];
214
+ location += 1 + w;
215
+ it += bias;
216
+ var difference = location - it;
217
+
218
+ if (difference == 0)
219
+ continue;
220
+
221
+ var partialLine = this.$editor.session.getLine(row).substr(0, it );
222
+ var strippedPartialLine = partialLine.replace(/\s*$/g, "");
223
+ var ispaces = partialLine.length - strippedPartialLine.length;
224
+
225
+ if (difference > 0) {
226
+ this.$editor.session.getDocument().insertInLine({row: row, column: it + 1}, Array(difference + 1).join(" ") + "\t");
227
+ this.$editor.session.getDocument().removeInLine(row, it, it + 1);
228
+
229
+ bias += difference;
230
+ }
231
+
232
+ if (difference < 0 && ispaces >= -difference) {
233
+ this.$editor.session.getDocument().removeInLine(row, it + difference, it);
234
+ bias += difference;
235
+ }
236
+ }
237
+ };
238
+ this.$izip_longest = function(iterables) {
239
+ if (!iterables[0])
240
+ return [];
241
+ var longest = iterables[0].length;
242
+ var iterablesLength = iterables.length;
243
+
244
+ for (var i = 1; i < iterablesLength; i++) {
245
+ var iLength = iterables[i].length;
246
+ if (iLength > longest)
247
+ longest = iLength;
248
+ }
249
+
250
+ var expandedSet = [];
251
+
252
+ for (var l = 0; l < longest; l++) {
253
+ var set = [];
254
+ for (var i = 0; i < iterablesLength; i++) {
255
+ if (iterables[i][l] === "")
256
+ set.push(NaN);
257
+ else
258
+ set.push(iterables[i][l]);
259
+ }
260
+
261
+ expandedSet.push(set);
262
+ }
263
+
264
+
265
+ return expandedSet;
266
+ };
267
+ this.$izip = function(widths, tabs) {
268
+ var size = widths.length >= tabs.length ? tabs.length : widths.length;
269
+
270
+ var expandedSet = [];
271
+ for (var i = 0; i < size; i++) {
272
+ var set = [ widths[i], tabs[i] ];
273
+ expandedSet.push(set);
274
+ }
275
+ return expandedSet;
276
+ };
277
+
278
+ }).call(ElasticTabstopsLite.prototype);
279
+
280
+ exports.ElasticTabstopsLite = ElasticTabstopsLite;
281
+
282
+ var Editor = require("../editor").Editor;
283
+ require("../config").defineOptions(Editor.prototype, "editor", {
284
+ useElasticTabstops: {
285
+ set: function(val) {
286
+ if (val) {
287
+ if (!this.elasticTabstops)
288
+ this.elasticTabstops = new ElasticTabstopsLite(this);
289
+ this.commands.on("afterExec", this.elasticTabstops.onAfterExec);
290
+ this.commands.on("exec", this.elasticTabstops.onExec);
291
+ this.on("change", this.elasticTabstops.onChange);
292
+ } else if (this.elasticTabstops) {
293
+ this.commands.removeListener("afterExec", this.elasticTabstops.onAfterExec);
294
+ this.commands.removeListener("exec", this.elasticTabstops.onExec);
295
+ this.removeListener("change", this.elasticTabstops.onChange);
296
+ }
297
+ }
298
+ }
299
+ });
300
+
301
+ });
@@ -0,0 +1,253 @@
1
+ /* ***** BEGIN LICENSE BLOCK *****
2
+ * Distributed under the BSD license:
3
+ *
4
+ * Copyright (c) 2010, Ajax.org B.V.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without
8
+ * modification, are permitted provided that the following conditions are met:
9
+ * * Redistributions of source code must retain the above copyright
10
+ * notice, this list of conditions and the following disclaimer.
11
+ * * Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following disclaimer in the
13
+ * documentation and/or other materials provided with the distribution.
14
+ * * Neither the name of Ajax.org B.V. nor the
15
+ * names of its contributors may be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
22
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ *
29
+ * ***** END LICENSE BLOCK ***** */
30
+
31
+ define('ace/ext/emmet', ['require', 'exports', 'module' , 'ace/keyboard/hash_handler', 'ace/editor', 'ace/config'], function(require, exports, module) {
32
+
33
+ var HashHandler = require("ace/keyboard/hash_handler").HashHandler;
34
+ var Editor = require("ace/editor").Editor;
35
+ var emmet;
36
+
37
+ Editor.prototype.indexToPosition = function(index) {
38
+ return this.session.doc.indexToPosition(index);
39
+ };
40
+
41
+ Editor.prototype.positionToIndex = function(pos) {
42
+ return this.session.doc.positionToIndex(pos);
43
+ };
44
+ function AceEmmetEditor() {}
45
+
46
+ AceEmmetEditor.prototype = {
47
+ setupContext: function(editor) {
48
+ this.ace = editor;
49
+ this.indentation = editor.session.getTabString();
50
+ emmet.require('resources').setVariable('indentation', this.indentation);
51
+ this.$syntax = null;
52
+ this.$syntax = this.getSyntax();
53
+ },
54
+ getSelectionRange: function() {
55
+ var range = this.ace.getSelectionRange();
56
+ return {
57
+ start: this.ace.positionToIndex(range.start),
58
+ end: this.ace.positionToIndex(range.end)
59
+ };
60
+ },
61
+ createSelection: function(start, end) {
62
+ this.ace.selection.setRange({
63
+ start: this.ace.indexToPosition(start),
64
+ end: this.ace.indexToPosition(end)
65
+ });
66
+ },
67
+ getCurrentLineRange: function() {
68
+ var row = this.ace.getCursorPosition().row;
69
+ var lineLength = this.ace.session.getLine(row).length;
70
+ var index = this.ace.positionToIndex({row: row, column: 0});
71
+ return {
72
+ start: index,
73
+ end: index + lineLength
74
+ };
75
+ },
76
+ getCaretPos: function(){
77
+ var pos = this.ace.getCursorPosition();
78
+ return this.ace.positionToIndex(pos);
79
+ },
80
+ setCaretPos: function(index){
81
+ var pos = this.ace.indexToPosition(index);
82
+ this.ace.clearSelection();
83
+ this.ace.selection.moveCursorToPosition(pos);
84
+ },
85
+ getCurrentLine: function() {
86
+ var row = this.ace.getCursorPosition().row;
87
+ return this.ace.session.getLine(row);
88
+ },
89
+ replaceContent: function(value, start, end, noIndent) {
90
+ if (end == null)
91
+ end = start == null ? content.length : start;
92
+ if (start == null)
93
+ start = 0;
94
+ var utils = emmet.require('utils');
95
+ if (!noIndent) {
96
+ value = utils.padString(value, utils.getLinePaddingFromPosition(this.getContent(), start));
97
+ }
98
+ var tabstopData = emmet.require('tabStops').extract(value, {
99
+ escape: function(ch) {
100
+ return ch;
101
+ }
102
+ });
103
+
104
+ value = tabstopData.text;
105
+ var firstTabStop = tabstopData.tabstops[0];
106
+
107
+ if (firstTabStop) {
108
+ firstTabStop.start += start;
109
+ firstTabStop.end += start;
110
+ } else {
111
+ firstTabStop = {
112
+ start: value.length + start,
113
+ end: value.length + start
114
+ };
115
+ }
116
+
117
+ var range = this.ace.getSelectionRange();
118
+ range.start = this.ace.indexToPosition(start);
119
+ range.end = this.ace.indexToPosition(end);
120
+
121
+ this.ace.session.replace(range, value);
122
+
123
+ range.start = this.ace.indexToPosition(firstTabStop.start);
124
+ range.end = this.ace.indexToPosition(firstTabStop.end);
125
+ this.ace.selection.setRange(range);
126
+ },
127
+ getContent: function(){
128
+ return this.ace.getValue();
129
+ },
130
+ getSyntax: function() {
131
+ if (this.$syntax)
132
+ return this.$syntax;
133
+ var syntax = this.ace.session.$modeId.split("/").pop();
134
+ if (syntax == 'html' || syntax == "php") {
135
+ var cursor = this.ace.getCursorPosition();
136
+ var state = this.ace.session.getState(cursor.row);
137
+ if (typeof state != "string")
138
+ state = state[0];
139
+ if (state) {
140
+ state = state.split("-");
141
+ if (state.length > 1)
142
+ syntax = state[0];
143
+ else if (syntax == "php")
144
+ syntax = "html"
145
+ }
146
+ }
147
+ return syntax;
148
+ },
149
+ getProfileName: function() {
150
+ switch(this.getSyntax()) {
151
+ case 'css': return css;
152
+ case 'xml':
153
+ case 'xsl':
154
+ return 'xml';
155
+ case 'html':
156
+ var profile = emmet.require('resources').getVariable('profile');
157
+ if (!profile)
158
+ profile = this.ace.session.getLines(0,2).join("").search(/<!DOCTYPE[^>]+XHTML/i) != -1 ? 'xhtml': 'html';
159
+ return profile;
160
+ }
161
+ return 'xhtml';
162
+ },
163
+ prompt: function(title) {
164
+ return prompt(title);
165
+ },
166
+ getSelection: function() {
167
+ return this.ace.session.getTextRange();
168
+ },
169
+ getFilePath: function() {
170
+ return '';
171
+ }
172
+ };
173
+
174
+
175
+ var keymap = {
176
+ expand_abbreviation: {"mac": "ctrl+alt+e", "win": "alt+e"},
177
+ match_pair_outward: {"mac": "ctrl+d", "win": "ctrl+,"},
178
+ match_pair_inward: {"mac": "ctrl+j", "win": "ctrl+shift+0"},
179
+ matching_pair: {"mac": "ctrl+alt+j", "win": "alt+j"},
180
+ next_edit_point: "alt+right",
181
+ prev_edit_point: "alt+left",
182
+ toggle_comment: {"mac": "command+shift+/", "win": "ctrl+shift+/"},
183
+ split_join_tag: {"mac": "shift+command+'", "win": "shift+ctrl+`"},
184
+ remove_tag: {"mac": "command+'", "win": "shift+ctrl+;"},
185
+ evaluate_math_expression: {"mac": "shift+command+y", "win": "shift+ctrl+y"},
186
+ increment_number_by_1: "ctrl+up",
187
+ decrement_number_by_1: "ctrl+down",
188
+ increment_number_by_01: "alt+up",
189
+ decrement_number_by_01: "alt+down",
190
+ increment_number_by_10: {"mac": "alt+command+up", "win": "shift+alt+up"},
191
+ decrement_number_by_10: {"mac": "alt+command+down", "win": "shift+alt+down"},
192
+ select_next_item: {"mac": "shift+command+.", "win": "shift+ctrl+."},
193
+ select_previous_item: {"mac": "shift+command+,", "win": "shift+ctrl+,"},
194
+ reflect_css_value: {"mac": "shift+command+r", "win": "shift+ctrl+r"},
195
+
196
+ encode_decode_data_url: {"mac": "shift+ctrl+d", "win": "ctrl+'"},
197
+ expand_abbreviation_with_tab: "Tab"
198
+ };
199
+
200
+ var editorProxy = new AceEmmetEditor();
201
+ exports.commands = new HashHandler();
202
+ function runEmmetCommand(editor) {
203
+ editorProxy.setupContext(editor);
204
+ if (editorProxy.getSyntax() == "php")
205
+ return false;
206
+ var actions = emmet.require('actions')
207
+
208
+ try {
209
+ var result = actions.run(this.name, editorProxy);
210
+ } catch(e) {
211
+ editor._signal("changeStatus", typeof e == "string" ? e : e.message);
212
+ }
213
+ return result;
214
+ }
215
+
216
+ for (var command in keymap) {
217
+ exports.commands.addCommand({
218
+ name: command,
219
+ bindKey: keymap[command],
220
+ exec: runEmmetCommand
221
+ });
222
+ }
223
+
224
+ var onChangeMode = function(e, target) {
225
+ var editor = target;
226
+ if (!editor)
227
+ return;
228
+ var modeId = editor.session.$modeId;
229
+ var enabled = modeId && /css|less|sass|html|php/.test(modeId);
230
+ if (e.enableEmmet === false)
231
+ enabled = false;
232
+ if (enabled)
233
+ editor.keyBinding.addKeyboardHandler(exports.commands);
234
+ else
235
+ editor.keyBinding.removeKeyboardHandler(exports.commands);
236
+ };
237
+
238
+
239
+ exports.AceEmmetEditor = AceEmmetEditor
240
+ require("ace/config").defineOptions(Editor.prototype, "editor", {
241
+ enableEmmet: {
242
+ set: function(val) {
243
+ this[val ? "on" : "removeListener"]("changeMode", onChangeMode);
244
+ onChangeMode({enableEmmet: !!val}, this);
245
+ },
246
+ value: true
247
+ }
248
+ });
249
+
250
+
251
+ exports.setCore = function(e) {emmet = e;};
252
+ });
253
+