overpass-doc 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +1 -0
- data/Rakefile +27 -0
- data/bin/overpass-doc +12 -0
- data/lib/overpass-doc.rb +9 -0
- data/lib/overpass-doc/assets/bootstrap.min.css +7 -0
- data/lib/overpass-doc/assets/bootstrap.min.js +7 -0
- data/lib/overpass-doc/assets/codemirror.css +176 -0
- data/lib/overpass-doc/assets/codemirror.js +3190 -0
- data/lib/overpass-doc/assets/jquery.js +2 -0
- data/lib/overpass-doc/assets/mode/clike/clike.js +303 -0
- data/lib/overpass-doc/assets/mode/clike/index.html +102 -0
- data/lib/overpass-doc/assets/mode/clike/scala.html +766 -0
- data/lib/overpass-doc/assets/mode/clike/test.js +165 -0
- data/lib/overpass-doc/assets/util/closetag.js +165 -0
- data/lib/overpass-doc/assets/util/continuecomment.js +36 -0
- data/lib/overpass-doc/assets/util/continuelist.js +29 -0
- data/lib/overpass-doc/assets/util/dialog.css +32 -0
- data/lib/overpass-doc/assets/util/dialog.js +76 -0
- data/lib/overpass-doc/assets/util/foldcode.js +196 -0
- data/lib/overpass-doc/assets/util/formatting.js +108 -0
- data/lib/overpass-doc/assets/util/javascript-hint.js +138 -0
- data/lib/overpass-doc/assets/util/loadmode.js +51 -0
- data/lib/overpass-doc/assets/util/match-highlighter.js +44 -0
- data/lib/overpass-doc/assets/util/multiplex.js +95 -0
- data/lib/overpass-doc/assets/util/overlay.js +59 -0
- data/lib/overpass-doc/assets/util/pig-hint.js +123 -0
- data/lib/overpass-doc/assets/util/runmode-standalone.js +90 -0
- data/lib/overpass-doc/assets/util/runmode.js +53 -0
- data/lib/overpass-doc/assets/util/search.js +118 -0
- data/lib/overpass-doc/assets/util/searchcursor.js +119 -0
- data/lib/overpass-doc/assets/util/simple-hint.css +16 -0
- data/lib/overpass-doc/assets/util/simple-hint.js +102 -0
- data/lib/overpass-doc/assets/util/xml-hint.js +131 -0
- data/lib/overpass-doc/generator.rb +122 -0
- data/lib/overpass-doc/query.rb +119 -0
- data/lib/overpass-doc/views/extra.erb +4 -0
- data/lib/overpass-doc/views/index.erb +37 -0
- data/lib/overpass-doc/views/layout.erb +80 -0
- data/lib/overpass-doc/views/query.erb +115 -0
- metadata +144 -0
@@ -0,0 +1,196 @@
|
|
1
|
+
// the tagRangeFinder function is
|
2
|
+
// Copyright (C) 2011 by Daniel Glazman <daniel@glazman.org>
|
3
|
+
// released under the MIT license (../../LICENSE) like the rest of CodeMirror
|
4
|
+
CodeMirror.tagRangeFinder = function(cm, line, hideEnd) {
|
5
|
+
var nameStartChar = "A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD";
|
6
|
+
var nameChar = nameStartChar + "\-\:\.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
|
7
|
+
var xmlNAMERegExp = new RegExp("^[" + nameStartChar + "][" + nameChar + "]*");
|
8
|
+
|
9
|
+
var lineText = cm.getLine(line);
|
10
|
+
var found = false;
|
11
|
+
var tag = null;
|
12
|
+
var pos = 0;
|
13
|
+
while (!found) {
|
14
|
+
pos = lineText.indexOf("<", pos);
|
15
|
+
if (-1 == pos) // no tag on line
|
16
|
+
return;
|
17
|
+
if (pos + 1 < lineText.length && lineText[pos + 1] == "/") { // closing tag
|
18
|
+
pos++;
|
19
|
+
continue;
|
20
|
+
}
|
21
|
+
// ok we weem to have a start tag
|
22
|
+
if (!lineText.substr(pos + 1).match(xmlNAMERegExp)) { // not a tag name...
|
23
|
+
pos++;
|
24
|
+
continue;
|
25
|
+
}
|
26
|
+
var gtPos = lineText.indexOf(">", pos + 1);
|
27
|
+
if (-1 == gtPos) { // end of start tag not in line
|
28
|
+
var l = line + 1;
|
29
|
+
var foundGt = false;
|
30
|
+
var lastLine = cm.lineCount();
|
31
|
+
while (l < lastLine && !foundGt) {
|
32
|
+
var lt = cm.getLine(l);
|
33
|
+
var gt = lt.indexOf(">");
|
34
|
+
if (-1 != gt) { // found a >
|
35
|
+
foundGt = true;
|
36
|
+
var slash = lt.lastIndexOf("/", gt);
|
37
|
+
if (-1 != slash && slash < gt) {
|
38
|
+
var str = lineText.substr(slash, gt - slash + 1);
|
39
|
+
if (!str.match( /\/\s*\>/ )) { // yep, that's the end of empty tag
|
40
|
+
if (hideEnd === true) l++;
|
41
|
+
return l;
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
l++;
|
46
|
+
}
|
47
|
+
found = true;
|
48
|
+
}
|
49
|
+
else {
|
50
|
+
var slashPos = lineText.lastIndexOf("/", gtPos);
|
51
|
+
if (-1 == slashPos) { // cannot be empty tag
|
52
|
+
found = true;
|
53
|
+
// don't continue
|
54
|
+
}
|
55
|
+
else { // empty tag?
|
56
|
+
// check if really empty tag
|
57
|
+
var str = lineText.substr(slashPos, gtPos - slashPos + 1);
|
58
|
+
if (!str.match( /\/\s*\>/ )) { // finally not empty
|
59
|
+
found = true;
|
60
|
+
// don't continue
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
if (found) {
|
65
|
+
var subLine = lineText.substr(pos + 1);
|
66
|
+
tag = subLine.match(xmlNAMERegExp);
|
67
|
+
if (tag) {
|
68
|
+
// we have an element name, wooohooo !
|
69
|
+
tag = tag[0];
|
70
|
+
// do we have the close tag on same line ???
|
71
|
+
if (-1 != lineText.indexOf("</" + tag + ">", pos)) // yep
|
72
|
+
{
|
73
|
+
found = false;
|
74
|
+
}
|
75
|
+
// we don't, so we have a candidate...
|
76
|
+
}
|
77
|
+
else
|
78
|
+
found = false;
|
79
|
+
}
|
80
|
+
if (!found)
|
81
|
+
pos++;
|
82
|
+
}
|
83
|
+
|
84
|
+
if (found) {
|
85
|
+
var startTag = "(\\<\\/" + tag + "\\>)|(\\<" + tag + "\\>)|(\\<" + tag + "\\s)|(\\<" + tag + "$)";
|
86
|
+
var startTagRegExp = new RegExp(startTag, "g");
|
87
|
+
var endTag = "</" + tag + ">";
|
88
|
+
var depth = 1;
|
89
|
+
var l = line + 1;
|
90
|
+
var lastLine = cm.lineCount();
|
91
|
+
while (l < lastLine) {
|
92
|
+
lineText = cm.getLine(l);
|
93
|
+
var match = lineText.match(startTagRegExp);
|
94
|
+
if (match) {
|
95
|
+
for (var i = 0; i < match.length; i++) {
|
96
|
+
if (match[i] == endTag)
|
97
|
+
depth--;
|
98
|
+
else
|
99
|
+
depth++;
|
100
|
+
if (!depth) {
|
101
|
+
if (hideEnd === true) l++;
|
102
|
+
return l;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
}
|
106
|
+
l++;
|
107
|
+
}
|
108
|
+
return;
|
109
|
+
}
|
110
|
+
};
|
111
|
+
|
112
|
+
CodeMirror.braceRangeFinder = function(cm, line, hideEnd) {
|
113
|
+
var lineText = cm.getLine(line), at = lineText.length, startChar, tokenType;
|
114
|
+
for (;;) {
|
115
|
+
var found = lineText.lastIndexOf("{", at);
|
116
|
+
if (found < 0) break;
|
117
|
+
tokenType = cm.getTokenAt({line: line, ch: found}).className;
|
118
|
+
if (!/^(comment|string)/.test(tokenType)) { startChar = found; break; }
|
119
|
+
at = found - 1;
|
120
|
+
}
|
121
|
+
if (startChar == null || lineText.lastIndexOf("}") > startChar) return;
|
122
|
+
var count = 1, lastLine = cm.lineCount(), end;
|
123
|
+
outer: for (var i = line + 1; i < lastLine; ++i) {
|
124
|
+
var text = cm.getLine(i), pos = 0;
|
125
|
+
for (;;) {
|
126
|
+
var nextOpen = text.indexOf("{", pos), nextClose = text.indexOf("}", pos);
|
127
|
+
if (nextOpen < 0) nextOpen = text.length;
|
128
|
+
if (nextClose < 0) nextClose = text.length;
|
129
|
+
pos = Math.min(nextOpen, nextClose);
|
130
|
+
if (pos == text.length) break;
|
131
|
+
if (cm.getTokenAt({line: i, ch: pos + 1}).className == tokenType) {
|
132
|
+
if (pos == nextOpen) ++count;
|
133
|
+
else if (!--count) { end = i; break outer; }
|
134
|
+
}
|
135
|
+
++pos;
|
136
|
+
}
|
137
|
+
}
|
138
|
+
if (end == null || end == line + 1) return;
|
139
|
+
if (hideEnd === true) end++;
|
140
|
+
return end;
|
141
|
+
};
|
142
|
+
|
143
|
+
CodeMirror.indentRangeFinder = function(cm, line) {
|
144
|
+
var tabSize = cm.getOption("tabSize");
|
145
|
+
var myIndent = cm.getLineHandle(line).indentation(tabSize), last;
|
146
|
+
for (var i = line + 1, end = cm.lineCount(); i < end; ++i) {
|
147
|
+
var handle = cm.getLineHandle(i);
|
148
|
+
if (!/^\s*$/.test(handle.text)) {
|
149
|
+
if (handle.indentation(tabSize) <= myIndent) break;
|
150
|
+
last = i;
|
151
|
+
}
|
152
|
+
}
|
153
|
+
if (!last) return null;
|
154
|
+
return last + 1;
|
155
|
+
};
|
156
|
+
|
157
|
+
CodeMirror.newFoldFunction = function(rangeFinder, markText, hideEnd) {
|
158
|
+
var folded = [];
|
159
|
+
if (markText == null) markText = '<div style="position: absolute; left: 2px; color:#600">▼</div>%N%';
|
160
|
+
|
161
|
+
function isFolded(cm, n) {
|
162
|
+
for (var i = 0; i < folded.length; ++i) {
|
163
|
+
var start = cm.lineInfo(folded[i].start);
|
164
|
+
if (!start) folded.splice(i--, 1);
|
165
|
+
else if (start.line == n) return {pos: i, region: folded[i]};
|
166
|
+
}
|
167
|
+
}
|
168
|
+
|
169
|
+
function expand(cm, region) {
|
170
|
+
cm.clearMarker(region.start);
|
171
|
+
for (var i = 0; i < region.hidden.length; ++i)
|
172
|
+
cm.showLine(region.hidden[i]);
|
173
|
+
}
|
174
|
+
|
175
|
+
return function(cm, line) {
|
176
|
+
cm.operation(function() {
|
177
|
+
var known = isFolded(cm, line);
|
178
|
+
if (known) {
|
179
|
+
folded.splice(known.pos, 1);
|
180
|
+
expand(cm, known.region);
|
181
|
+
} else {
|
182
|
+
var end = rangeFinder(cm, line, hideEnd);
|
183
|
+
if (end == null) return;
|
184
|
+
var hidden = [];
|
185
|
+
for (var i = line + 1; i < end; ++i) {
|
186
|
+
var handle = cm.hideLine(i);
|
187
|
+
if (handle) hidden.push(handle);
|
188
|
+
}
|
189
|
+
var first = cm.setMarker(line, markText);
|
190
|
+
var region = {start: first, hidden: hidden};
|
191
|
+
cm.onDeleteLine(first, function() { expand(cm, region); });
|
192
|
+
folded.push(region);
|
193
|
+
}
|
194
|
+
});
|
195
|
+
};
|
196
|
+
};
|
@@ -0,0 +1,108 @@
|
|
1
|
+
(function() {
|
2
|
+
|
3
|
+
CodeMirror.extendMode("css", {
|
4
|
+
commentStart: "/*",
|
5
|
+
commentEnd: "*/",
|
6
|
+
newlineAfterToken: function(type, content) {
|
7
|
+
return /^[;{}]$/.test(content);
|
8
|
+
}
|
9
|
+
});
|
10
|
+
|
11
|
+
CodeMirror.extendMode("javascript", {
|
12
|
+
commentStart: "/*",
|
13
|
+
commentEnd: "*/",
|
14
|
+
// FIXME semicolons inside of for
|
15
|
+
newlineAfterToken: function(type, content, textAfter, state) {
|
16
|
+
if (this.jsonMode) {
|
17
|
+
return /^[\[,{]$/.test(content) || /^}/.test(textAfter);
|
18
|
+
} else {
|
19
|
+
if (content == ";" && state.lexical && state.lexical.type == ")") return false;
|
20
|
+
return /^[;{}]$/.test(content) && !/^;/.test(textAfter);
|
21
|
+
}
|
22
|
+
}
|
23
|
+
});
|
24
|
+
|
25
|
+
CodeMirror.extendMode("xml", {
|
26
|
+
commentStart: "<!--",
|
27
|
+
commentEnd: "-->",
|
28
|
+
newlineAfterToken: function(type, content, textAfter) {
|
29
|
+
return type == "tag" && />$/.test(content) || /^</.test(textAfter);
|
30
|
+
}
|
31
|
+
});
|
32
|
+
|
33
|
+
// Comment/uncomment the specified range
|
34
|
+
CodeMirror.defineExtension("commentRange", function (isComment, from, to) {
|
35
|
+
var cm = this, curMode = CodeMirror.innerMode(cm.getMode(), cm.getTokenAt(from).state).mode;
|
36
|
+
cm.operation(function() {
|
37
|
+
if (isComment) { // Comment range
|
38
|
+
cm.replaceRange(curMode.commentEnd, to);
|
39
|
+
cm.replaceRange(curMode.commentStart, from);
|
40
|
+
if (from.line == to.line && from.ch == to.ch) // An empty comment inserted - put cursor inside
|
41
|
+
cm.setCursor(from.line, from.ch + curMode.commentStart.length);
|
42
|
+
} else { // Uncomment range
|
43
|
+
var selText = cm.getRange(from, to);
|
44
|
+
var startIndex = selText.indexOf(curMode.commentStart);
|
45
|
+
var endIndex = selText.lastIndexOf(curMode.commentEnd);
|
46
|
+
if (startIndex > -1 && endIndex > -1 && endIndex > startIndex) {
|
47
|
+
// Take string till comment start
|
48
|
+
selText = selText.substr(0, startIndex)
|
49
|
+
// From comment start till comment end
|
50
|
+
+ selText.substring(startIndex + curMode.commentStart.length, endIndex)
|
51
|
+
// From comment end till string end
|
52
|
+
+ selText.substr(endIndex + curMode.commentEnd.length);
|
53
|
+
}
|
54
|
+
cm.replaceRange(selText, from, to);
|
55
|
+
}
|
56
|
+
});
|
57
|
+
});
|
58
|
+
|
59
|
+
// Applies automatic mode-aware indentation to the specified range
|
60
|
+
CodeMirror.defineExtension("autoIndentRange", function (from, to) {
|
61
|
+
var cmInstance = this;
|
62
|
+
this.operation(function () {
|
63
|
+
for (var i = from.line; i <= to.line; i++) {
|
64
|
+
cmInstance.indentLine(i, "smart");
|
65
|
+
}
|
66
|
+
});
|
67
|
+
});
|
68
|
+
|
69
|
+
// Applies automatic formatting to the specified range
|
70
|
+
CodeMirror.defineExtension("autoFormatRange", function (from, to) {
|
71
|
+
var cm = this;
|
72
|
+
var outer = cm.getMode(), text = cm.getRange(from, to).split("\n");
|
73
|
+
var state = CodeMirror.copyState(outer, cm.getTokenAt(from).state);
|
74
|
+
var tabSize = cm.getOption("tabSize");
|
75
|
+
|
76
|
+
var out = "", lines = 0, atSol = from.ch == 0;
|
77
|
+
function newline() {
|
78
|
+
out += "\n";
|
79
|
+
atSol = true;
|
80
|
+
++lines;
|
81
|
+
}
|
82
|
+
|
83
|
+
for (var i = 0; i < text.length; ++i) {
|
84
|
+
var stream = new CodeMirror.StringStream(text[i], tabSize);
|
85
|
+
while (!stream.eol()) {
|
86
|
+
var inner = CodeMirror.innerMode(outer, state);
|
87
|
+
var style = outer.token(stream, state), cur = stream.current();
|
88
|
+
stream.start = stream.pos;
|
89
|
+
if (!atSol || /\S/.test(cur)) {
|
90
|
+
out += cur;
|
91
|
+
atSol = false;
|
92
|
+
}
|
93
|
+
if (!atSol && inner.mode.newlineAfterToken &&
|
94
|
+
inner.mode.newlineAfterToken(style, cur, stream.string.slice(stream.pos) || text[i+1] || "", inner.state))
|
95
|
+
newline();
|
96
|
+
}
|
97
|
+
if (!stream.pos && outer.blankLine) outer.blankLine(state);
|
98
|
+
if (!atSol) newline();
|
99
|
+
}
|
100
|
+
|
101
|
+
cm.operation(function () {
|
102
|
+
cm.replaceRange(out, from, to);
|
103
|
+
for (var cur = from.line + 1, end = from.line + lines; cur <= end; ++cur)
|
104
|
+
cm.indentLine(cur, "smart");
|
105
|
+
cm.setSelection(from, cm.getCursor(false));
|
106
|
+
});
|
107
|
+
});
|
108
|
+
})();
|
@@ -0,0 +1,138 @@
|
|
1
|
+
(function () {
|
2
|
+
function forEach(arr, f) {
|
3
|
+
for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
|
4
|
+
}
|
5
|
+
|
6
|
+
function arrayContains(arr, item) {
|
7
|
+
if (!Array.prototype.indexOf) {
|
8
|
+
var i = arr.length;
|
9
|
+
while (i--) {
|
10
|
+
if (arr[i] === item) {
|
11
|
+
return true;
|
12
|
+
}
|
13
|
+
}
|
14
|
+
return false;
|
15
|
+
}
|
16
|
+
return arr.indexOf(item) != -1;
|
17
|
+
}
|
18
|
+
|
19
|
+
function scriptHint(editor, keywords, getToken, options) {
|
20
|
+
// Find the token at the cursor
|
21
|
+
var cur = editor.getCursor(), token = getToken(editor, cur), tprop = token;
|
22
|
+
// If it's not a 'word-style' token, ignore the token.
|
23
|
+
if (!/^[\w$_]*$/.test(token.string)) {
|
24
|
+
token = tprop = {start: cur.ch, end: cur.ch, string: "", state: token.state,
|
25
|
+
className: token.string == "." ? "property" : null};
|
26
|
+
}
|
27
|
+
// If it is a property, find out what it is a property of.
|
28
|
+
while (tprop.className == "property") {
|
29
|
+
tprop = getToken(editor, {line: cur.line, ch: tprop.start});
|
30
|
+
if (tprop.string != ".") return;
|
31
|
+
tprop = getToken(editor, {line: cur.line, ch: tprop.start});
|
32
|
+
if (tprop.string == ')') {
|
33
|
+
var level = 1;
|
34
|
+
do {
|
35
|
+
tprop = getToken(editor, {line: cur.line, ch: tprop.start});
|
36
|
+
switch (tprop.string) {
|
37
|
+
case ')': level++; break;
|
38
|
+
case '(': level--; break;
|
39
|
+
default: break;
|
40
|
+
}
|
41
|
+
} while (level > 0);
|
42
|
+
tprop = getToken(editor, {line: cur.line, ch: tprop.start});
|
43
|
+
if (tprop.className == 'variable')
|
44
|
+
tprop.className = 'function';
|
45
|
+
else return; // no clue
|
46
|
+
}
|
47
|
+
if (!context) var context = [];
|
48
|
+
context.push(tprop);
|
49
|
+
}
|
50
|
+
return {list: getCompletions(token, context, keywords, options),
|
51
|
+
from: {line: cur.line, ch: token.start},
|
52
|
+
to: {line: cur.line, ch: token.end}};
|
53
|
+
}
|
54
|
+
|
55
|
+
CodeMirror.javascriptHint = function(editor, options) {
|
56
|
+
return scriptHint(editor, javascriptKeywords,
|
57
|
+
function (e, cur) {return e.getTokenAt(cur);},
|
58
|
+
options);
|
59
|
+
};
|
60
|
+
|
61
|
+
function getCoffeeScriptToken(editor, cur) {
|
62
|
+
// This getToken, it is for coffeescript, imitates the behavior of
|
63
|
+
// getTokenAt method in javascript.js, that is, returning "property"
|
64
|
+
// type and treat "." as indepenent token.
|
65
|
+
var token = editor.getTokenAt(cur);
|
66
|
+
if (cur.ch == token.start + 1 && token.string.charAt(0) == '.') {
|
67
|
+
token.end = token.start;
|
68
|
+
token.string = '.';
|
69
|
+
token.className = "property";
|
70
|
+
}
|
71
|
+
else if (/^\.[\w$_]*$/.test(token.string)) {
|
72
|
+
token.className = "property";
|
73
|
+
token.start++;
|
74
|
+
token.string = token.string.replace(/\./, '');
|
75
|
+
}
|
76
|
+
return token;
|
77
|
+
}
|
78
|
+
|
79
|
+
CodeMirror.coffeescriptHint = function(editor, options) {
|
80
|
+
return scriptHint(editor, coffeescriptKeywords, getCoffeeScriptToken, options);
|
81
|
+
};
|
82
|
+
|
83
|
+
var stringProps = ("charAt charCodeAt indexOf lastIndexOf substring substr slice trim trimLeft trimRight " +
|
84
|
+
"toUpperCase toLowerCase split concat match replace search").split(" ");
|
85
|
+
var arrayProps = ("length concat join splice push pop shift unshift slice reverse sort indexOf " +
|
86
|
+
"lastIndexOf every some filter forEach map reduce reduceRight ").split(" ");
|
87
|
+
var funcProps = "prototype apply call bind".split(" ");
|
88
|
+
var javascriptKeywords = ("break case catch continue debugger default delete do else false finally for function " +
|
89
|
+
"if in instanceof new null return switch throw true try typeof var void while with").split(" ");
|
90
|
+
var coffeescriptKeywords = ("and break catch class continue delete do else extends false finally for " +
|
91
|
+
"if in instanceof isnt new no not null of off on or return switch then throw true try typeof until void while with yes").split(" ");
|
92
|
+
|
93
|
+
function getCompletions(token, context, keywords, options) {
|
94
|
+
var found = [], start = token.string;
|
95
|
+
function maybeAdd(str) {
|
96
|
+
if (str.indexOf(start) == 0 && !arrayContains(found, str)) found.push(str);
|
97
|
+
}
|
98
|
+
function gatherCompletions(obj) {
|
99
|
+
if (typeof obj == "string") forEach(stringProps, maybeAdd);
|
100
|
+
else if (obj instanceof Array) forEach(arrayProps, maybeAdd);
|
101
|
+
else if (obj instanceof Function) forEach(funcProps, maybeAdd);
|
102
|
+
for (var name in obj) maybeAdd(name);
|
103
|
+
}
|
104
|
+
|
105
|
+
if (context) {
|
106
|
+
// If this is a property, see if it belongs to some object we can
|
107
|
+
// find in the current environment.
|
108
|
+
var obj = context.pop(), base;
|
109
|
+
if (obj.className == "variable") {
|
110
|
+
if (options && options.additionalContext)
|
111
|
+
base = options.additionalContext[obj.string];
|
112
|
+
base = base || window[obj.string];
|
113
|
+
} else if (obj.className == "string") {
|
114
|
+
base = "";
|
115
|
+
} else if (obj.className == "atom") {
|
116
|
+
base = 1;
|
117
|
+
} else if (obj.className == "function") {
|
118
|
+
if (window.jQuery != null && (obj.string == '$' || obj.string == 'jQuery') &&
|
119
|
+
(typeof window.jQuery == 'function'))
|
120
|
+
base = window.jQuery();
|
121
|
+
else if (window._ != null && (obj.string == '_') && (typeof window._ == 'function'))
|
122
|
+
base = window._();
|
123
|
+
}
|
124
|
+
while (base != null && context.length)
|
125
|
+
base = base[context.pop().string];
|
126
|
+
if (base != null) gatherCompletions(base);
|
127
|
+
}
|
128
|
+
else {
|
129
|
+
// If not, just look in the window object and any local scope
|
130
|
+
// (reading into JS mode internals to get at the local and global variables)
|
131
|
+
for (var v = token.state.localVars; v; v = v.next) maybeAdd(v.name);
|
132
|
+
for (var v = token.state.globalVars; v; v = v.next) maybeAdd(v.name);
|
133
|
+
gatherCompletions(window);
|
134
|
+
forEach(keywords, maybeAdd);
|
135
|
+
}
|
136
|
+
return found;
|
137
|
+
}
|
138
|
+
})();
|
@@ -0,0 +1,51 @@
|
|
1
|
+
(function() {
|
2
|
+
if (!CodeMirror.modeURL) CodeMirror.modeURL = "../mode/%N/%N.js";
|
3
|
+
|
4
|
+
var loading = {};
|
5
|
+
function splitCallback(cont, n) {
|
6
|
+
var countDown = n;
|
7
|
+
return function() { if (--countDown == 0) cont(); };
|
8
|
+
}
|
9
|
+
function ensureDeps(mode, cont) {
|
10
|
+
var deps = CodeMirror.modes[mode].dependencies;
|
11
|
+
if (!deps) return cont();
|
12
|
+
var missing = [];
|
13
|
+
for (var i = 0; i < deps.length; ++i) {
|
14
|
+
if (!CodeMirror.modes.hasOwnProperty(deps[i]))
|
15
|
+
missing.push(deps[i]);
|
16
|
+
}
|
17
|
+
if (!missing.length) return cont();
|
18
|
+
var split = splitCallback(cont, missing.length);
|
19
|
+
for (var i = 0; i < missing.length; ++i)
|
20
|
+
CodeMirror.requireMode(missing[i], split);
|
21
|
+
}
|
22
|
+
|
23
|
+
CodeMirror.requireMode = function(mode, cont) {
|
24
|
+
if (typeof mode != "string") mode = mode.name;
|
25
|
+
if (CodeMirror.modes.hasOwnProperty(mode)) return ensureDeps(mode, cont);
|
26
|
+
if (loading.hasOwnProperty(mode)) return loading[mode].push(cont);
|
27
|
+
|
28
|
+
var script = document.createElement("script");
|
29
|
+
script.src = CodeMirror.modeURL.replace(/%N/g, mode);
|
30
|
+
var others = document.getElementsByTagName("script")[0];
|
31
|
+
others.parentNode.insertBefore(script, others);
|
32
|
+
var list = loading[mode] = [cont];
|
33
|
+
var count = 0, poll = setInterval(function() {
|
34
|
+
if (++count > 100) return clearInterval(poll);
|
35
|
+
if (CodeMirror.modes.hasOwnProperty(mode)) {
|
36
|
+
clearInterval(poll);
|
37
|
+
loading[mode] = null;
|
38
|
+
ensureDeps(mode, function() {
|
39
|
+
for (var i = 0; i < list.length; ++i) list[i]();
|
40
|
+
});
|
41
|
+
}
|
42
|
+
}, 200);
|
43
|
+
};
|
44
|
+
|
45
|
+
CodeMirror.autoLoadMode = function(instance, mode) {
|
46
|
+
if (!CodeMirror.modes.hasOwnProperty(mode))
|
47
|
+
CodeMirror.requireMode(mode, function() {
|
48
|
+
instance.setOption("mode", instance.getOption("mode"));
|
49
|
+
});
|
50
|
+
};
|
51
|
+
}());
|