overpass-doc 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 (41) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +1 -0
  3. data/Rakefile +27 -0
  4. data/bin/overpass-doc +12 -0
  5. data/lib/overpass-doc.rb +9 -0
  6. data/lib/overpass-doc/assets/bootstrap.min.css +7 -0
  7. data/lib/overpass-doc/assets/bootstrap.min.js +7 -0
  8. data/lib/overpass-doc/assets/codemirror.css +176 -0
  9. data/lib/overpass-doc/assets/codemirror.js +3190 -0
  10. data/lib/overpass-doc/assets/jquery.js +2 -0
  11. data/lib/overpass-doc/assets/mode/clike/clike.js +303 -0
  12. data/lib/overpass-doc/assets/mode/clike/index.html +102 -0
  13. data/lib/overpass-doc/assets/mode/clike/scala.html +766 -0
  14. data/lib/overpass-doc/assets/mode/clike/test.js +165 -0
  15. data/lib/overpass-doc/assets/util/closetag.js +165 -0
  16. data/lib/overpass-doc/assets/util/continuecomment.js +36 -0
  17. data/lib/overpass-doc/assets/util/continuelist.js +29 -0
  18. data/lib/overpass-doc/assets/util/dialog.css +32 -0
  19. data/lib/overpass-doc/assets/util/dialog.js +76 -0
  20. data/lib/overpass-doc/assets/util/foldcode.js +196 -0
  21. data/lib/overpass-doc/assets/util/formatting.js +108 -0
  22. data/lib/overpass-doc/assets/util/javascript-hint.js +138 -0
  23. data/lib/overpass-doc/assets/util/loadmode.js +51 -0
  24. data/lib/overpass-doc/assets/util/match-highlighter.js +44 -0
  25. data/lib/overpass-doc/assets/util/multiplex.js +95 -0
  26. data/lib/overpass-doc/assets/util/overlay.js +59 -0
  27. data/lib/overpass-doc/assets/util/pig-hint.js +123 -0
  28. data/lib/overpass-doc/assets/util/runmode-standalone.js +90 -0
  29. data/lib/overpass-doc/assets/util/runmode.js +53 -0
  30. data/lib/overpass-doc/assets/util/search.js +118 -0
  31. data/lib/overpass-doc/assets/util/searchcursor.js +119 -0
  32. data/lib/overpass-doc/assets/util/simple-hint.css +16 -0
  33. data/lib/overpass-doc/assets/util/simple-hint.js +102 -0
  34. data/lib/overpass-doc/assets/util/xml-hint.js +131 -0
  35. data/lib/overpass-doc/generator.rb +122 -0
  36. data/lib/overpass-doc/query.rb +119 -0
  37. data/lib/overpass-doc/views/extra.erb +4 -0
  38. data/lib/overpass-doc/views/index.erb +37 -0
  39. data/lib/overpass-doc/views/layout.erb +80 -0
  40. data/lib/overpass-doc/views/query.erb +115 -0
  41. metadata +144 -0
@@ -0,0 +1,118 @@
1
+ // Define search commands. Depends on dialog.js or another
2
+ // implementation of the openDialog method.
3
+
4
+ // Replace works a little oddly -- it will do the replace on the next
5
+ // Ctrl-G (or whatever is bound to findNext) press. You prevent a
6
+ // replace by making sure the match is no longer selected when hitting
7
+ // Ctrl-G.
8
+
9
+ (function() {
10
+ function SearchState() {
11
+ this.posFrom = this.posTo = this.query = null;
12
+ this.marked = [];
13
+ }
14
+ function getSearchState(cm) {
15
+ return cm._searchState || (cm._searchState = new SearchState());
16
+ }
17
+ function getSearchCursor(cm, query, pos) {
18
+ // Heuristic: if the query string is all lowercase, do a case insensitive search.
19
+ return cm.getSearchCursor(query, pos, typeof query == "string" && query == query.toLowerCase());
20
+ }
21
+ function dialog(cm, text, shortText, f) {
22
+ if (cm.openDialog) cm.openDialog(text, f);
23
+ else f(prompt(shortText, ""));
24
+ }
25
+ function confirmDialog(cm, text, shortText, fs) {
26
+ if (cm.openConfirm) cm.openConfirm(text, fs);
27
+ else if (confirm(shortText)) fs[0]();
28
+ }
29
+ function parseQuery(query) {
30
+ var isRE = query.match(/^\/(.*)\/([a-z]*)$/);
31
+ return isRE ? new RegExp(isRE[1], isRE[2].indexOf("i") == -1 ? "" : "i") : query;
32
+ }
33
+ var queryDialog =
34
+ 'Search: <input type="text" style="width: 10em"/> <span style="color: #888">(Use /re/ syntax for regexp search)</span>';
35
+ function doSearch(cm, rev) {
36
+ var state = getSearchState(cm);
37
+ if (state.query) return findNext(cm, rev);
38
+ dialog(cm, queryDialog, "Search for:", function(query) {
39
+ cm.operation(function() {
40
+ if (!query || state.query) return;
41
+ state.query = parseQuery(query);
42
+ if (cm.lineCount() < 2000) { // This is too expensive on big documents.
43
+ for (var cursor = getSearchCursor(cm, state.query); cursor.findNext();)
44
+ state.marked.push(cm.markText(cursor.from(), cursor.to(), "CodeMirror-searching"));
45
+ }
46
+ state.posFrom = state.posTo = cm.getCursor();
47
+ findNext(cm, rev);
48
+ });
49
+ });
50
+ }
51
+ function findNext(cm, rev) {cm.operation(function() {
52
+ var state = getSearchState(cm);
53
+ var cursor = getSearchCursor(cm, state.query, rev ? state.posFrom : state.posTo);
54
+ if (!cursor.find(rev)) {
55
+ cursor = getSearchCursor(cm, state.query, rev ? {line: cm.lineCount() - 1} : {line: 0, ch: 0});
56
+ if (!cursor.find(rev)) return;
57
+ }
58
+ cm.setSelection(cursor.from(), cursor.to());
59
+ state.posFrom = cursor.from(); state.posTo = cursor.to();
60
+ });}
61
+ function clearSearch(cm) {cm.operation(function() {
62
+ var state = getSearchState(cm);
63
+ if (!state.query) return;
64
+ state.query = null;
65
+ for (var i = 0; i < state.marked.length; ++i) state.marked[i].clear();
66
+ state.marked.length = 0;
67
+ });}
68
+
69
+ var replaceQueryDialog =
70
+ 'Replace: <input type="text" style="width: 10em"/> <span style="color: #888">(Use /re/ syntax for regexp search)</span>';
71
+ var replacementQueryDialog = 'With: <input type="text" style="width: 10em"/>';
72
+ var doReplaceConfirm = "Replace? <button>Yes</button> <button>No</button> <button>Stop</button>";
73
+ function replace(cm, all) {
74
+ dialog(cm, replaceQueryDialog, "Replace:", function(query) {
75
+ if (!query) return;
76
+ query = parseQuery(query);
77
+ dialog(cm, replacementQueryDialog, "Replace with:", function(text) {
78
+ if (all) {
79
+ cm.compoundChange(function() { cm.operation(function() {
80
+ for (var cursor = getSearchCursor(cm, query); cursor.findNext();) {
81
+ if (typeof query != "string") {
82
+ var match = cm.getRange(cursor.from(), cursor.to()).match(query);
83
+ cursor.replace(text.replace(/\$(\d)/, function(w, i) {return match[i];}));
84
+ } else cursor.replace(text);
85
+ }
86
+ });});
87
+ } else {
88
+ clearSearch(cm);
89
+ var cursor = getSearchCursor(cm, query, cm.getCursor());
90
+ function advance() {
91
+ var start = cursor.from(), match;
92
+ if (!(match = cursor.findNext())) {
93
+ cursor = getSearchCursor(cm, query);
94
+ if (!(match = cursor.findNext()) ||
95
+ (start && cursor.from().line == start.line && cursor.from().ch == start.ch)) return;
96
+ }
97
+ cm.setSelection(cursor.from(), cursor.to());
98
+ confirmDialog(cm, doReplaceConfirm, "Replace?",
99
+ [function() {doReplace(match);}, advance]);
100
+ }
101
+ function doReplace(match) {
102
+ cursor.replace(typeof query == "string" ? text :
103
+ text.replace(/\$(\d)/, function(w, i) {return match[i];}));
104
+ advance();
105
+ }
106
+ advance();
107
+ }
108
+ });
109
+ });
110
+ }
111
+
112
+ CodeMirror.commands.find = function(cm) {clearSearch(cm); doSearch(cm);};
113
+ CodeMirror.commands.findNext = doSearch;
114
+ CodeMirror.commands.findPrev = function(cm) {doSearch(cm, true);};
115
+ CodeMirror.commands.clearSearch = clearSearch;
116
+ CodeMirror.commands.replace = replace;
117
+ CodeMirror.commands.replaceAll = function(cm) {replace(cm, true);};
118
+ })();
@@ -0,0 +1,119 @@
1
+ (function(){
2
+ function SearchCursor(cm, query, pos, caseFold) {
3
+ this.atOccurrence = false; this.cm = cm;
4
+ if (caseFold == null && typeof query == "string") caseFold = false;
5
+
6
+ pos = pos ? cm.clipPos(pos) : {line: 0, ch: 0};
7
+ this.pos = {from: pos, to: pos};
8
+
9
+ // The matches method is filled in based on the type of query.
10
+ // It takes a position and a direction, and returns an object
11
+ // describing the next occurrence of the query, or null if no
12
+ // more matches were found.
13
+ if (typeof query != "string") { // Regexp match
14
+ if (!query.global) query = new RegExp(query.source, query.ignoreCase ? "ig" : "g");
15
+ this.matches = function(reverse, pos) {
16
+ if (reverse) {
17
+ query.lastIndex = 0;
18
+ var line = cm.getLine(pos.line).slice(0, pos.ch), match = query.exec(line), start = 0;
19
+ while (match) {
20
+ start += match.index + 1;
21
+ line = line.slice(start);
22
+ query.lastIndex = 0;
23
+ var newmatch = query.exec(line);
24
+ if (newmatch) match = newmatch;
25
+ else break;
26
+ }
27
+ start--;
28
+ } else {
29
+ query.lastIndex = pos.ch;
30
+ var line = cm.getLine(pos.line), match = query.exec(line),
31
+ start = match && match.index;
32
+ }
33
+ if (match)
34
+ return {from: {line: pos.line, ch: start},
35
+ to: {line: pos.line, ch: start + match[0].length},
36
+ match: match};
37
+ };
38
+ } else { // String query
39
+ if (caseFold) query = query.toLowerCase();
40
+ var fold = caseFold ? function(str){return str.toLowerCase();} : function(str){return str;};
41
+ var target = query.split("\n");
42
+ // Different methods for single-line and multi-line queries
43
+ if (target.length == 1)
44
+ this.matches = function(reverse, pos) {
45
+ var line = fold(cm.getLine(pos.line)), len = query.length, match;
46
+ if (reverse ? (pos.ch >= len && (match = line.lastIndexOf(query, pos.ch - len)) != -1)
47
+ : (match = line.indexOf(query, pos.ch)) != -1)
48
+ return {from: {line: pos.line, ch: match},
49
+ to: {line: pos.line, ch: match + len}};
50
+ };
51
+ else
52
+ this.matches = function(reverse, pos) {
53
+ var ln = pos.line, idx = (reverse ? target.length - 1 : 0), match = target[idx], line = fold(cm.getLine(ln));
54
+ var offsetA = (reverse ? line.indexOf(match) + match.length : line.lastIndexOf(match));
55
+ if (reverse ? offsetA >= pos.ch || offsetA != match.length
56
+ : offsetA <= pos.ch || offsetA != line.length - match.length)
57
+ return;
58
+ for (;;) {
59
+ if (reverse ? !ln : ln == cm.lineCount() - 1) return;
60
+ line = fold(cm.getLine(ln += reverse ? -1 : 1));
61
+ match = target[reverse ? --idx : ++idx];
62
+ if (idx > 0 && idx < target.length - 1) {
63
+ if (line != match) return;
64
+ else continue;
65
+ }
66
+ var offsetB = (reverse ? line.lastIndexOf(match) : line.indexOf(match) + match.length);
67
+ if (reverse ? offsetB != line.length - match.length : offsetB != match.length)
68
+ return;
69
+ var start = {line: pos.line, ch: offsetA}, end = {line: ln, ch: offsetB};
70
+ return {from: reverse ? end : start, to: reverse ? start : end};
71
+ }
72
+ };
73
+ }
74
+ }
75
+
76
+ SearchCursor.prototype = {
77
+ findNext: function() {return this.find(false);},
78
+ findPrevious: function() {return this.find(true);},
79
+
80
+ find: function(reverse) {
81
+ var self = this, pos = this.cm.clipPos(reverse ? this.pos.from : this.pos.to);
82
+ function savePosAndFail(line) {
83
+ var pos = {line: line, ch: 0};
84
+ self.pos = {from: pos, to: pos};
85
+ self.atOccurrence = false;
86
+ return false;
87
+ }
88
+
89
+ for (;;) {
90
+ if (this.pos = this.matches(reverse, pos)) {
91
+ this.atOccurrence = true;
92
+ return this.pos.match || true;
93
+ }
94
+ if (reverse) {
95
+ if (!pos.line) return savePosAndFail(0);
96
+ pos = {line: pos.line-1, ch: this.cm.getLine(pos.line-1).length};
97
+ }
98
+ else {
99
+ var maxLine = this.cm.lineCount();
100
+ if (pos.line == maxLine - 1) return savePosAndFail(maxLine);
101
+ pos = {line: pos.line+1, ch: 0};
102
+ }
103
+ }
104
+ },
105
+
106
+ from: function() {if (this.atOccurrence) return this.pos.from;},
107
+ to: function() {if (this.atOccurrence) return this.pos.to;},
108
+
109
+ replace: function(newText) {
110
+ var self = this;
111
+ if (this.atOccurrence)
112
+ self.pos.to = this.cm.replaceRange(newText, self.pos.from, self.pos.to);
113
+ }
114
+ };
115
+
116
+ CodeMirror.defineExtension("getSearchCursor", function(query, pos, caseFold) {
117
+ return new SearchCursor(this, query, pos, caseFold);
118
+ });
119
+ })();
@@ -0,0 +1,16 @@
1
+ .CodeMirror-completions {
2
+ position: absolute;
3
+ z-index: 10;
4
+ overflow: hidden;
5
+ -webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
6
+ -moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
7
+ box-shadow: 2px 3px 5px rgba(0,0,0,.2);
8
+ }
9
+ .CodeMirror-completions select {
10
+ background: #fafafa;
11
+ outline: none;
12
+ border: none;
13
+ padding: 0;
14
+ margin: 0;
15
+ font-family: monospace;
16
+ }
@@ -0,0 +1,102 @@
1
+ (function() {
2
+ CodeMirror.simpleHint = function(editor, getHints, givenOptions) {
3
+ // Determine effective options based on given values and defaults.
4
+ var options = {}, defaults = CodeMirror.simpleHint.defaults;
5
+ for (var opt in defaults)
6
+ if (defaults.hasOwnProperty(opt))
7
+ options[opt] = (givenOptions && givenOptions.hasOwnProperty(opt) ? givenOptions : defaults)[opt];
8
+
9
+ function collectHints(previousToken) {
10
+ // We want a single cursor position.
11
+ if (editor.somethingSelected()) return;
12
+
13
+ var tempToken = editor.getTokenAt(editor.getCursor());
14
+
15
+ // Don't show completions if token has changed and the option is set.
16
+ if (options.closeOnTokenChange && previousToken != null &&
17
+ (tempToken.start != previousToken.start || tempToken.className != previousToken.className)) {
18
+ return;
19
+ }
20
+
21
+ var result = getHints(editor, givenOptions);
22
+ if (!result || !result.list.length) return;
23
+ var completions = result.list;
24
+ function insert(str) {
25
+ editor.replaceRange(str, result.from, result.to);
26
+ }
27
+ // When there is only one completion, use it directly.
28
+ if (options.completeSingle && completions.length == 1) {
29
+ insert(completions[0]);
30
+ return true;
31
+ }
32
+
33
+ // Build the select widget
34
+ var complete = document.createElement("div");
35
+ complete.className = "CodeMirror-completions";
36
+ var sel = complete.appendChild(document.createElement("select"));
37
+ // Opera doesn't move the selection when pressing up/down in a
38
+ // multi-select, but it does properly support the size property on
39
+ // single-selects, so no multi-select is necessary.
40
+ if (!window.opera) sel.multiple = true;
41
+ for (var i = 0; i < completions.length; ++i) {
42
+ var opt = sel.appendChild(document.createElement("option"));
43
+ opt.appendChild(document.createTextNode(completions[i]));
44
+ }
45
+ sel.firstChild.selected = true;
46
+ sel.size = Math.min(10, completions.length);
47
+ var pos = options.alignWithWord ? editor.charCoords(result.from) : editor.cursorCoords();
48
+ complete.style.left = pos.x + "px";
49
+ complete.style.top = pos.yBot + "px";
50
+ document.body.appendChild(complete);
51
+ // If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
52
+ var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth);
53
+ if(winW - pos.x < sel.clientWidth)
54
+ complete.style.left = (pos.x - sel.clientWidth) + "px";
55
+ // Hack to hide the scrollbar.
56
+ if (completions.length <= 10)
57
+ complete.style.width = (sel.clientWidth - 1) + "px";
58
+
59
+ var done = false;
60
+ function close() {
61
+ if (done) return;
62
+ done = true;
63
+ complete.parentNode.removeChild(complete);
64
+ }
65
+ function pick() {
66
+ insert(completions[sel.selectedIndex]);
67
+ close();
68
+ setTimeout(function(){editor.focus();}, 50);
69
+ }
70
+ CodeMirror.connect(sel, "blur", close);
71
+ CodeMirror.connect(sel, "keydown", function(event) {
72
+ var code = event.keyCode;
73
+ // Enter
74
+ if (code == 13) {CodeMirror.e_stop(event); pick();}
75
+ // Escape
76
+ else if (code == 27) {CodeMirror.e_stop(event); close(); editor.focus();}
77
+ else if (code != 38 && code != 40 && code != 33 && code != 34 && !CodeMirror.isModifierKey(event)) {
78
+ close(); editor.focus();
79
+ // Pass the event to the CodeMirror instance so that it can handle things like backspace properly.
80
+ editor.triggerOnKeyDown(event);
81
+ // Don't show completions if the code is backspace and the option is set.
82
+ if (!options.closeOnBackspace || code != 8) {
83
+ setTimeout(function(){collectHints(tempToken);}, 50);
84
+ }
85
+ }
86
+ });
87
+ CodeMirror.connect(sel, "dblclick", pick);
88
+
89
+ sel.focus();
90
+ // Opera sometimes ignores focusing a freshly created node
91
+ if (window.opera) setTimeout(function(){if (!done) sel.focus();}, 100);
92
+ return true;
93
+ }
94
+ return collectHints();
95
+ };
96
+ CodeMirror.simpleHint.defaults = {
97
+ closeOnBackspace: true,
98
+ closeOnTokenChange: false,
99
+ completeSingle: true,
100
+ alignWithWord: true
101
+ };
102
+ })();
@@ -0,0 +1,131 @@
1
+
2
+ (function() {
3
+
4
+ CodeMirror.xmlHints = [];
5
+
6
+ CodeMirror.xmlHint = function(cm, simbol) {
7
+
8
+ if(simbol.length > 0) {
9
+ var cursor = cm.getCursor();
10
+ cm.replaceSelection(simbol);
11
+ cursor = {line: cursor.line, ch: cursor.ch + 1};
12
+ cm.setCursor(cursor);
13
+ }
14
+
15
+ CodeMirror.simpleHint(cm, getHint);
16
+ };
17
+
18
+ var getHint = function(cm) {
19
+
20
+ var cursor = cm.getCursor();
21
+
22
+ if (cursor.ch > 0) {
23
+
24
+ var text = cm.getRange({line: 0, ch: 0}, cursor);
25
+ var typed = '';
26
+ var simbol = '';
27
+ for(var i = text.length - 1; i >= 0; i--) {
28
+ if(text[i] == ' ' || text[i] == '<') {
29
+ simbol = text[i];
30
+ break;
31
+ }
32
+ else {
33
+ typed = text[i] + typed;
34
+ }
35
+ }
36
+
37
+ text = text.slice(0, text.length - typed.length);
38
+
39
+ var path = getActiveElement(cm, text) + simbol;
40
+ var hints = CodeMirror.xmlHints[path];
41
+
42
+ if(typeof hints === 'undefined')
43
+ hints = [''];
44
+ else {
45
+ hints = hints.slice(0);
46
+ for (var i = hints.length - 1; i >= 0; i--) {
47
+ if(hints[i].indexOf(typed) != 0)
48
+ hints.splice(i, 1);
49
+ }
50
+ }
51
+
52
+ return {
53
+ list: hints,
54
+ from: { line: cursor.line, ch: cursor.ch - typed.length },
55
+ to: cursor
56
+ };
57
+ };
58
+ };
59
+
60
+ var getActiveElement = function(codeMirror, text) {
61
+
62
+ var element = '';
63
+
64
+ if(text.length >= 0) {
65
+
66
+ var regex = new RegExp('<([^!?][^\\s/>]*).*?>', 'g');
67
+
68
+ var matches = [];
69
+ var match;
70
+ while ((match = regex.exec(text)) != null) {
71
+ matches.push({
72
+ tag: match[1],
73
+ selfclose: (match[0].slice(match[0].length - 2) === '/>')
74
+ });
75
+ }
76
+
77
+ for (var i = matches.length - 1, skip = 0; i >= 0; i--) {
78
+
79
+ var item = matches[i];
80
+
81
+ if (item.tag[0] == '/')
82
+ {
83
+ skip++;
84
+ }
85
+ else if (item.selfclose == false)
86
+ {
87
+ if (skip > 0)
88
+ {
89
+ skip--;
90
+ }
91
+ else
92
+ {
93
+ element = '<' + item.tag + '>' + element;
94
+ }
95
+ }
96
+ }
97
+
98
+ element += getOpenTag(text);
99
+ }
100
+
101
+ return element;
102
+ };
103
+
104
+ var getOpenTag = function(text) {
105
+
106
+ var open = text.lastIndexOf('<');
107
+ var close = text.lastIndexOf('>');
108
+
109
+ if (close < open)
110
+ {
111
+ text = text.slice(open);
112
+
113
+ if(text != '<') {
114
+
115
+ var space = text.indexOf(' ');
116
+ if(space < 0)
117
+ space = text.indexOf('\t');
118
+ if(space < 0)
119
+ space = text.indexOf('\n');
120
+
121
+ if (space < 0)
122
+ space = text.length;
123
+
124
+ return text.slice(0, space);
125
+ }
126
+ }
127
+
128
+ return '';
129
+ };
130
+
131
+ })();