sdoc_local_editor 0.3.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/.gitignore +3 -0
  2. data/.rake_tasks~ +20 -0
  3. data/LICENSE +110 -0
  4. data/README.rdoc +37 -0
  5. data/Rakefile +12 -0
  6. data/bin/sdoc_local_editor +27 -0
  7. data/bin/sdoc_local_editor_merge +24 -0
  8. data/lib/rdoc/discover.rb +5 -0
  9. data/lib/rdoc/generator/template/merge/index.rhtml +14 -0
  10. data/lib/rdoc/generator/template/rails/_context.rhtml +210 -0
  11. data/lib/rdoc/generator/template/rails/_head.rhtml +7 -0
  12. data/lib/rdoc/generator/template/rails/class.rhtml +39 -0
  13. data/lib/rdoc/generator/template/rails/file.rhtml +37 -0
  14. data/lib/rdoc/generator/template/rails/index.rhtml +13 -0
  15. data/lib/rdoc/generator/template/rails/resources/apple-touch-icon.png +0 -0
  16. data/lib/rdoc/generator/template/rails/resources/css/github.css +129 -0
  17. data/lib/rdoc/generator/template/rails/resources/css/main.css +346 -0
  18. data/lib/rdoc/generator/template/rails/resources/css/panel.css +389 -0
  19. data/lib/rdoc/generator/template/rails/resources/css/reset.css +48 -0
  20. data/lib/rdoc/generator/template/rails/resources/favicon.ico +0 -0
  21. data/lib/rdoc/generator/template/rails/resources/i/arrows.png +0 -0
  22. data/lib/rdoc/generator/template/rails/resources/i/results_bg.png +0 -0
  23. data/lib/rdoc/generator/template/rails/resources/i/tree_bg.png +0 -0
  24. data/lib/rdoc/generator/template/rails/resources/js/highlight.pack.js +1 -0
  25. data/lib/rdoc/generator/template/rails/resources/js/jquery-1.3.2.min.js +19 -0
  26. data/lib/rdoc/generator/template/rails/resources/js/jquery-effect.js +593 -0
  27. data/lib/rdoc/generator/template/rails/resources/js/main.js +20 -0
  28. data/lib/rdoc/generator/template/rails/resources/js/searchdoc.js +441 -0
  29. data/lib/rdoc/generator/template/rails/resources/panel/index.html +73 -0
  30. data/lib/rdoc/generator/template/rails/se_index.rhtml +8 -0
  31. data/lib/rdoc/generator/template/sdoc/_context.rhtml +221 -0
  32. data/lib/rdoc/generator/template/sdoc/_head.rhtml +7 -0
  33. data/lib/rdoc/generator/template/sdoc/class.rhtml +39 -0
  34. data/lib/rdoc/generator/template/sdoc/file.rhtml +29 -0
  35. data/lib/rdoc/generator/template/sdoc/index.rhtml +13 -0
  36. data/lib/rdoc/generator/template/sdoc/resources/apple-touch-icon.png +0 -0
  37. data/lib/rdoc/generator/template/sdoc/resources/css/github.css +129 -0
  38. data/lib/rdoc/generator/template/sdoc/resources/css/main.css +333 -0
  39. data/lib/rdoc/generator/template/sdoc/resources/css/panel.css +384 -0
  40. data/lib/rdoc/generator/template/sdoc/resources/css/reset.css +48 -0
  41. data/lib/rdoc/generator/template/sdoc/resources/favicon.ico +0 -0
  42. data/lib/rdoc/generator/template/sdoc/resources/i/arrows.png +0 -0
  43. data/lib/rdoc/generator/template/sdoc/resources/i/results_bg.png +0 -0
  44. data/lib/rdoc/generator/template/sdoc/resources/i/tree_bg.png +0 -0
  45. data/lib/rdoc/generator/template/sdoc/resources/js/highlight.pack.js +1 -0
  46. data/lib/rdoc/generator/template/sdoc/resources/js/jquery-1.3.2.min.js +19 -0
  47. data/lib/rdoc/generator/template/sdoc/resources/js/jquery-effect.js +593 -0
  48. data/lib/rdoc/generator/template/sdoc/resources/js/main.js +24 -0
  49. data/lib/rdoc/generator/template/sdoc/resources/js/searchdoc.js +442 -0
  50. data/lib/rdoc/generator/template/sdoc/resources/panel/index.html +73 -0
  51. data/lib/rdoc/generator/template/sdoc/se_index.rhtml +8 -0
  52. data/lib/sdoc_local_editor.rb +9 -0
  53. data/lib/sdoc_local_editor/generator.rb +418 -0
  54. data/lib/sdoc_local_editor/github.rb +61 -0
  55. data/lib/sdoc_local_editor/helpers.rb +26 -0
  56. data/lib/sdoc_local_editor/merge.rb +223 -0
  57. data/lib/sdoc_local_editor/templatable.rb +60 -0
  58. data/sdoc_local_editor.gemspec +31 -0
  59. metadata +139 -0
@@ -0,0 +1,20 @@
1
+ function toggleSource(id)
2
+ {
3
+ var src = $('#' + id).toggle();
4
+ var isVisible = src.is(':visible');
5
+ $('#l_' + id).html(isVisible ? 'hide' : 'show');
6
+ }
7
+
8
+ window.highlight = function(url) {
9
+ var hash = url.match(/#([^#]+)$/)
10
+ if(hash) {
11
+ $('a[name=' + hash[1] + ']').parent().effect('highlight', {}, 'slow')
12
+ }
13
+ }
14
+
15
+ $(function() {
16
+ highlight('#' + location.hash);
17
+ $('.description pre').each(function() {
18
+ hljs.highlightBlock(this);
19
+ });
20
+ });
@@ -0,0 +1,441 @@
1
+ Searchdoc = {};
2
+
3
+ // navigation.js ------------------------------------------
4
+
5
+ Searchdoc.Navigation = new function() {
6
+ this.initNavigation = function() {
7
+ var _this = this;
8
+
9
+ $(document).keydown(function(e) {
10
+ _this.onkeydown(e);
11
+ }).keyup(function(e) {
12
+ _this.onkeyup(e);
13
+ });
14
+
15
+ this.navigationActive = true;
16
+ }
17
+
18
+ this.setNavigationActive = function(state) {
19
+ this.navigationActive = state;
20
+ this.clearMoveTimeout();
21
+ }
22
+
23
+
24
+ this.onkeyup = function(e) {
25
+ if (!this.navigationActive) return;
26
+ switch(e.keyCode) {
27
+ case 37: //Event.KEY_LEFT:
28
+ case 38: //Event.KEY_UP:
29
+ case 39: //Event.KEY_RIGHT:
30
+ case 40: //Event.KEY_DOWN:
31
+ case 73: // i - qwerty
32
+ case 74: // j
33
+ case 75: // k
34
+ case 76: // l
35
+ case 67: // c - dvorak
36
+ case 72: // h
37
+ case 84: // t
38
+ case 78: // n
39
+ this.clearMoveTimeout();
40
+ break;
41
+ }
42
+ }
43
+
44
+ this.onkeydown = function(e) {
45
+ if (!this.navigationActive) return;
46
+ switch(e.keyCode) {
47
+ case 37: //Event.KEY_LEFT:
48
+ case 74: // j (qwerty)
49
+ case 72: // h (dvorak)
50
+ if (this.moveLeft()) e.preventDefault();
51
+ break;
52
+ case 38: //Event.KEY_UP:
53
+ case 73: // i (qwerty)
54
+ case 67: // c (dvorak)
55
+ if (e.keyCode == 38 || e.ctrlKey) {
56
+ if (this.moveUp()) e.preventDefault();
57
+ this.startMoveTimeout(false);
58
+ }
59
+ break;
60
+ case 39: //Event.KEY_RIGHT:
61
+ case 76: // l (qwerty)
62
+ case 78: // n (dvorak)
63
+ if (this.moveRight()) e.preventDefault();
64
+ break;
65
+ case 40: //Event.KEY_DOWN:
66
+ case 75: // k (qwerty)
67
+ case 84: // t (dvorak)
68
+ if (e.keyCode == 40 || e.ctrlKey) {
69
+ if (this.moveDown()) e.preventDefault();
70
+ this.startMoveTimeout(true);
71
+ }
72
+ break;
73
+ case 9: //Event.KEY_TAB:
74
+ case 13: //Event.KEY_RETURN:
75
+ if (this.$current) this.select(this.$current);
76
+ break;
77
+ }
78
+ if (e.ctrlKey && e.shiftKey) this.select(this.$current);
79
+ }
80
+
81
+ this.clearMoveTimeout = function() {
82
+ clearTimeout(this.moveTimeout);
83
+ this.moveTimeout = null;
84
+ }
85
+
86
+ this.startMoveTimeout = function(isDown) {
87
+ if (!$.browser.mozilla && !$.browser.opera) return;
88
+ if (this.moveTimeout) this.clearMoveTimeout();
89
+ var _this = this;
90
+
91
+ var go = function() {
92
+ if (!_this.moveTimeout) return;
93
+ _this[isDown ? 'moveDown' : 'moveUp']();
94
+ _this.moveTimout = setTimeout(go, 100);
95
+ }
96
+ this.moveTimeout = setTimeout(go, 200);
97
+ }
98
+
99
+ this.moveRight = function() {
100
+ }
101
+
102
+ this.moveLeft = function() {
103
+ }
104
+
105
+ this.move = function(isDown) {
106
+ }
107
+
108
+ this.moveUp = function() {
109
+ return this.move(false);
110
+ }
111
+
112
+ this.moveDown = function() {
113
+ return this.move(true);
114
+ }
115
+ }
116
+
117
+
118
+ // scrollIntoView.js --------------------------------------
119
+
120
+ function scrollIntoView(element, view) {
121
+ var offset, viewHeight, viewScroll, height;
122
+ offset = element.offsetTop;
123
+ height = element.offsetHeight;
124
+ viewHeight = view.offsetHeight;
125
+ viewScroll = view.scrollTop;
126
+ if (offset - viewScroll + height > viewHeight) {
127
+ view.scrollTop = offset - viewHeight + height;
128
+ }
129
+ if (offset < viewScroll) {
130
+ view.scrollTop = offset;
131
+ }
132
+ }
133
+
134
+ // panel.js -----------------------------------------------
135
+
136
+ Searchdoc.Panel = function(element, data, tree, frame) {
137
+ this.$element = $(element);
138
+ this.$input = $('input', element).eq(0);
139
+ this.$result = $('.result ul', element).eq(0);
140
+ this.frame = frame;
141
+ this.$current = null;
142
+ this.$view = this.$result.parent();
143
+ this.data = data;
144
+ this.searcher = new Searcher(data.index);
145
+ this.tree = new Searchdoc.Tree($('.tree', element), tree, this);
146
+ this.init();
147
+ }
148
+
149
+ Searchdoc.Panel.prototype = $.extend({}, Searchdoc.Navigation, new function() {
150
+ var suid = 1;
151
+
152
+ this.init = function() {
153
+ var _this = this;
154
+ var observer = function() {
155
+ _this.search(_this.$input[0].value);
156
+ };
157
+ this.$input.keyup(observer);
158
+ this.$input.click(observer); // mac's clear field
159
+
160
+ this.searcher.ready(function(results, isLast) {
161
+ _this.addResults(results, isLast);
162
+ })
163
+
164
+ this.$result.click(function(e) {
165
+ _this.$current.removeClass('current');
166
+ _this.$current = $(e.target).closest('li').addClass('current');
167
+ _this.select();
168
+ _this.$input.focus();
169
+ });
170
+
171
+ this.initNavigation();
172
+ this.setNavigationActive(false);
173
+ }
174
+
175
+ this.search = function(value, selectFirstMatch) {
176
+ value = jQuery.trim(value).toLowerCase();
177
+ this.selectFirstMatch = selectFirstMatch;
178
+ if (value) {
179
+ this.$element.removeClass('panel_tree').addClass('panel_results');
180
+ this.tree.setNavigationActive(false);
181
+ this.setNavigationActive(true);
182
+ } else {
183
+ this.$element.addClass('panel_tree').removeClass('panel_results');
184
+ this.tree.setNavigationActive(true);
185
+ this.setNavigationActive(false);
186
+ }
187
+ if (value != this.lastQuery) {
188
+ this.lastQuery = value;
189
+ this.firstRun = true;
190
+ this.searcher.find(value);
191
+ }
192
+ }
193
+
194
+ this.addResults = function(results, isLast) {
195
+ var target = this.$result.get(0);
196
+ if (this.firstRun && (results.length > 0 || isLast)) {
197
+ this.$current = null;
198
+ this.$result.empty();
199
+ }
200
+ for (var i=0, l = results.length; i < l; i++) {
201
+ target.appendChild(renderItem.call(this, results[i]));
202
+ };
203
+ if (this.firstRun && results.length > 0) {
204
+ this.firstRun = false;
205
+ this.$current = $(target.firstChild);
206
+ this.$current.addClass('current');
207
+ if (this.selectFirstMatch) this.select();
208
+ scrollIntoView(this.$current[0], this.$view[0])
209
+ }
210
+ if (jQuery.browser.msie) this.$element[0].className += '';
211
+ }
212
+
213
+ this.open = function(src) {
214
+ this.frame.location.href = '../' + src;
215
+ if (this.frame.highlight) this.frame.highlight(src);
216
+ }
217
+
218
+ this.select = function() {
219
+ this.open(this.$current.data('path'));
220
+ }
221
+
222
+ this.move = function(isDown) {
223
+ if (!this.$current) return;
224
+ var $next = this.$current[isDown ? 'next' : 'prev']();
225
+ if ($next.length) {
226
+ this.$current.removeClass('current');
227
+ $next.addClass('current');
228
+ scrollIntoView($next[0], this.$view[0]);
229
+ this.$current = $next;
230
+ }
231
+ return true;
232
+ }
233
+
234
+ function renderItem(result) {
235
+ var li = document.createElement('li'),
236
+ html = '', badge = result.badge;
237
+ html += '<h1>' + hlt(result.title);
238
+ if (result.params) html += '<i>' + result.params + '</i>';
239
+ html += '</h1>';
240
+ html += '<p>';
241
+ if (typeof badge != 'undefined') {
242
+ html += '<span class="badge badge_' + (badge % 6 + 1) + '">' + escapeHTML(this.data.badges[badge] || 'unknown') + '</span>';
243
+ }
244
+ html += hlt(result.namespace) + '</p>';
245
+ if (result.snippet) html += '<p class="snippet">' + escapeHTML(result.snippet) + '</p>';
246
+ li.innerHTML = html;
247
+ jQuery.data(li, 'path', result.path);
248
+ return li;
249
+ }
250
+
251
+ function hlt(html) {
252
+ return escapeHTML(html).replace(/\u0001/g, '<b>').replace(/\u0002/g, '</b>')
253
+ }
254
+
255
+ function escapeHTML(html) {
256
+ return html.replace(/[&<>]/g, function(c) {
257
+ return '&#' + c.charCodeAt(0) + ';';
258
+ });
259
+ }
260
+
261
+ });
262
+
263
+ // tree.js ------------------------------------------------
264
+
265
+ Searchdoc.Tree = function(element, tree, panel) {
266
+ this.$element = $(element);
267
+ this.$list = $('ul', element);
268
+ this.tree = tree;
269
+ this.panel = panel;
270
+ this.init();
271
+ }
272
+
273
+ Searchdoc.Tree.prototype = $.extend({}, Searchdoc.Navigation, new function() {
274
+ this.init = function() {
275
+ var stopper = document.createElement('li');
276
+ stopper.className = 'stopper';
277
+ this.$list[0].appendChild(stopper);
278
+ for (var i=0, l = this.tree.length; i < l; i++) {
279
+ buildAndAppendItem.call(this, this.tree[i], 0, stopper);
280
+ };
281
+ var _this = this;
282
+ this.$list.click(function(e) {
283
+ var $target = $(e.target),
284
+ $li = $target.closest('li');
285
+ if ($target.hasClass('icon')) {
286
+ _this.toggle($li);
287
+ } else {
288
+ _this.select($li);
289
+ }
290
+ })
291
+
292
+ this.initNavigation();
293
+ if (jQuery.browser.msie) document.body.className += '';
294
+ }
295
+
296
+ this.select = function($li) {
297
+ this.highlight($li);
298
+ var path = $li[0].searchdoc_tree_data.path;
299
+ if (path) this.panel.open(path);
300
+ }
301
+
302
+ this.highlight = function($li) {
303
+ if (this.$current) this.$current.removeClass('current');
304
+ this.$current = $li.addClass('current');
305
+ }
306
+
307
+ this.toggle = function($li) {
308
+ var closed = !$li.hasClass('closed'),
309
+ children = $li[0].searchdoc_tree_data.children;
310
+ $li.toggleClass('closed');
311
+ for (var i=0, l = children.length; i < l; i++) {
312
+ toggleVis.call(this, $(children[i].li), !closed);
313
+ };
314
+ }
315
+
316
+ this.moveRight = function() {
317
+ if (!this.$current) {
318
+ this.highlight(this.$list.find('li:first'));
319
+ return;
320
+ }
321
+ if (this.$current.hasClass('closed')) {
322
+ this.toggle(this.$current);
323
+ }
324
+ }
325
+
326
+ this.moveLeft = function() {
327
+ if (!this.$current) {
328
+ this.highlight(this.$list.find('li:first'));
329
+ return;
330
+ }
331
+ if (!this.$current.hasClass('closed')) {
332
+ this.toggle(this.$current);
333
+ } else {
334
+ var level = this.$current[0].searchdoc_tree_data.level;
335
+ if (level == 0) return;
336
+ var $next = this.$current.prevAll('li.level_' + (level - 1) + ':visible:first');
337
+ this.$current.removeClass('current');
338
+ $next.addClass('current');
339
+ scrollIntoView($next[0], this.$element[0]);
340
+ this.$current = $next;
341
+ }
342
+ }
343
+
344
+ this.move = function(isDown) {
345
+ if (!this.$current) {
346
+ this.highlight(this.$list.find('li:first'));
347
+ return true;
348
+ }
349
+ var next = this.$current[0];
350
+ if (isDown) {
351
+ do {
352
+ next = next.nextSibling;
353
+ if (next && next.style && next.style.display != 'none') break;
354
+ } while(next);
355
+ } else {
356
+ do {
357
+ next = next.previousSibling;
358
+ if (next && next.style && next.style.display != 'none') break;
359
+ } while(next);
360
+ }
361
+ if (next && next.className.indexOf('stopper') == -1) {
362
+ this.$current.removeClass('current');
363
+ $(next).addClass('current');
364
+ scrollIntoView(next, this.$element[0]);
365
+ this.$current = $(next);
366
+ }
367
+ return true;
368
+ }
369
+
370
+ function toggleVis($li, show) {
371
+ var closed = $li.hasClass('closed'),
372
+ children = $li[0].searchdoc_tree_data.children;
373
+ $li.css('display', show ? '' : 'none')
374
+ if (!show && this.$current && $li[0] == this.$current[0]) {
375
+ this.$current.removeClass('current');
376
+ this.$current = null;
377
+ }
378
+ for (var i=0, l = children.length; i < l; i++) {
379
+ toggleVis.call(this, $(children[i].li), show && !closed);
380
+ };
381
+ }
382
+
383
+ function buildAndAppendItem(item, level, before) {
384
+ var li = renderItem(item, level),
385
+ list = this.$list[0];
386
+ item.li = li;
387
+ list.insertBefore(li, before);
388
+ for (var i=0, l = item[3].length; i < l; i++) {
389
+ buildAndAppendItem.call(this, item[3][i], level + 1, before);
390
+ };
391
+ return li;
392
+ }
393
+
394
+ function renderItem(item, level) {
395
+ var li = document.createElement('li'),
396
+ cnt = document.createElement('div'),
397
+ h1 = document.createElement('h1'),
398
+ p = document.createElement('p'),
399
+ icon, i;
400
+
401
+ li.appendChild(cnt);
402
+ li.style.paddingLeft = getOffset(level);
403
+ cnt.className = 'content';
404
+ if (!item[1]) li.className = 'empty ';
405
+ cnt.appendChild(h1);
406
+ // cnt.appendChild(p);
407
+ h1.appendChild(document.createTextNode(item[0]));
408
+ // p.appendChild(document.createTextNode(item[4]));
409
+ if (item[2]) {
410
+ i = document.createElement('i');
411
+ i.appendChild(document.createTextNode(item[2]));
412
+ h1.appendChild(i);
413
+ }
414
+ if (item[3].length > 0) {
415
+ icon = document.createElement('div');
416
+ icon.className = 'icon';
417
+ cnt.appendChild(icon);
418
+ }
419
+
420
+ // user direct assignement instead of $()
421
+ // it's 8x faster
422
+ // $(li).data('path', item[1])
423
+ // .data('children', item[3])
424
+ // .data('level', level)
425
+ // .css('display', level == 0 ? '' : 'none')
426
+ // .addClass('level_' + level)
427
+ // .addClass('closed');
428
+ li.searchdoc_tree_data = {
429
+ path: item[1],
430
+ children: item[3],
431
+ level: level
432
+ }
433
+ li.style.display = level == 0 ? '' : 'none';
434
+ li.className += 'level_' + level + ' closed';
435
+ return li;
436
+ }
437
+
438
+ function getOffset(level) {
439
+ return 5 + 18*level + 'px';
440
+ }
441
+ });