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,24 @@
1
+ function toggleSource(id)
2
+ {
3
+ var src = $('#' + id).toggle();
4
+ var isVisible = src.is(':visible');
5
+ $('#l_' + id).html(isVisible ? 'hide' : 'show');
6
+ if (!src.data('syntax-higlighted')) {
7
+ src.data('syntax-higlighted', 1);
8
+ hljs.highlightBlock(src[0]);
9
+ }
10
+ }
11
+
12
+ window.highlight = function(url) {
13
+ var hash = url.match(/#([^#]+)$/)
14
+ if(hash) {
15
+ $('a[name=' + hash[1] + ']').parent().effect('highlight', {}, 'slow')
16
+ }
17
+ }
18
+
19
+ $(function() {
20
+ highlight('#' + location.hash);
21
+ $('.description pre').each(function() {
22
+ hljs.highlightBlock(this);
23
+ });
24
+ });
@@ -0,0 +1,442 @@
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
+
146
+ this.tree = new Searchdoc.Tree($('.tree', element), tree, this);
147
+ this.init();
148
+ }
149
+
150
+ Searchdoc.Panel.prototype = $.extend({}, Searchdoc.Navigation, new function() {
151
+ var suid = 1;
152
+
153
+ this.init = function() {
154
+ var _this = this;
155
+ var observer = function() {
156
+ _this.search(_this.$input[0].value);
157
+ };
158
+ this.$input.keyup(observer);
159
+ this.$input.click(observer); // mac's clear field
160
+
161
+ this.searcher.ready(function(results, isLast) {
162
+ _this.addResults(results, isLast);
163
+ })
164
+
165
+ this.$result.click(function(e) {
166
+ _this.$current.removeClass('current');
167
+ _this.$current = $(e.target).closest('li').addClass('current');
168
+ _this.select();
169
+ _this.$input.focus();
170
+ });
171
+
172
+ this.initNavigation();
173
+ this.setNavigationActive(false);
174
+ }
175
+
176
+ this.search = function(value, selectFirstMatch) {
177
+ value = jQuery.trim(value).toLowerCase();
178
+ this.selectFirstMatch = selectFirstMatch;
179
+ if (value) {
180
+ this.$element.removeClass('panel_tree').addClass('panel_results');
181
+ this.tree.setNavigationActive(false);
182
+ this.setNavigationActive(true);
183
+ } else {
184
+ this.$element.addClass('panel_tree').removeClass('panel_results');
185
+ this.tree.setNavigationActive(true);
186
+ this.setNavigationActive(false);
187
+ }
188
+ if (value != this.lastQuery) {
189
+ this.lastQuery = value;
190
+ this.firstRun = true;
191
+ this.searcher.find(value);
192
+ }
193
+ }
194
+
195
+ this.addResults = function(results, isLast) {
196
+ var target = this.$result.get(0);
197
+ if (this.firstRun && (results.length > 0 || isLast)) {
198
+ this.$current = null;
199
+ this.$result.empty();
200
+ }
201
+ for (var i=0, l = results.length; i < l; i++) {
202
+ target.appendChild(renderItem.call(this, results[i]));
203
+ };
204
+ if (this.firstRun && results.length > 0) {
205
+ this.firstRun = false;
206
+ this.$current = $(target.firstChild);
207
+ this.$current.addClass('current');
208
+ if (this.selectFirstMatch) this.select();
209
+ scrollIntoView(this.$current[0], this.$view[0])
210
+ }
211
+ if (jQuery.browser.msie) this.$element[0].className += '';
212
+ }
213
+
214
+ this.open = function(src) {
215
+ this.frame.location.href = '../' + src;
216
+ if (this.frame.highlight) this.frame.highlight(src);
217
+ }
218
+
219
+ this.select = function() {
220
+ this.open(this.$current.data('path'));
221
+ }
222
+
223
+ this.move = function(isDown) {
224
+ if (!this.$current) return;
225
+ var $next = this.$current[isDown ? 'next' : 'prev']();
226
+ if ($next.length) {
227
+ this.$current.removeClass('current');
228
+ $next.addClass('current');
229
+ scrollIntoView($next[0], this.$view[0]);
230
+ this.$current = $next;
231
+ }
232
+ return true;
233
+ }
234
+
235
+ function renderItem(result) {
236
+ var li = document.createElement('li'),
237
+ html = '', badge = result.badge;
238
+ html += '<h1>' + hlt(result.title);
239
+ if (result.params) html += '<i>' + result.params + '</i>';
240
+ html += '</h1>';
241
+ html += '<p>';
242
+ if (typeof badge != 'undefined') {
243
+ html += '<span class="badge badge_' + (badge % 6 + 1) + '">' + escapeHTML(this.data.badges[badge] || 'unknown') + '</span>';
244
+ }
245
+ html += hlt(result.namespace) + '</p>';
246
+ if (result.snippet) html += '<p class="snippet">' + escapeHTML(result.snippet) + '</p>';
247
+ li.innerHTML = html;
248
+ jQuery.data(li, 'path', result.path);
249
+ return li;
250
+ }
251
+
252
+ function hlt(html) {
253
+ return escapeHTML(html).replace(/\u0001/g, '<b>').replace(/\u0002/g, '</b>')
254
+ }
255
+
256
+ function escapeHTML(html) {
257
+ return html.replace(/[&<>]/g, function(c) {
258
+ return '&#' + c.charCodeAt(0) + ';';
259
+ });
260
+ }
261
+
262
+ });
263
+
264
+ // tree.js ------------------------------------------------
265
+
266
+ Searchdoc.Tree = function(element, tree, panel) {
267
+ this.$element = $(element);
268
+ this.$list = $('ul', element);
269
+ this.tree = tree;
270
+ this.panel = panel;
271
+ this.init();
272
+ }
273
+
274
+ Searchdoc.Tree.prototype = $.extend({}, Searchdoc.Navigation, new function() {
275
+ this.init = function() {
276
+ var stopper = document.createElement('li');
277
+ stopper.className = 'stopper';
278
+ this.$list[0].appendChild(stopper);
279
+ for (var i=0, l = this.tree.length; i < l; i++) {
280
+ buildAndAppendItem.call(this, this.tree[i], 0, stopper);
281
+ };
282
+ var _this = this;
283
+ this.$list.click(function(e) {
284
+ var $target = $(e.target),
285
+ $li = $target.closest('li');
286
+ if ($target.hasClass('icon')) {
287
+ _this.toggle($li);
288
+ } else {
289
+ _this.select($li);
290
+ }
291
+ })
292
+
293
+ this.initNavigation();
294
+ if (jQuery.browser.msie) document.body.className += '';
295
+ }
296
+
297
+ this.select = function($li) {
298
+ this.highlight($li);
299
+ var path = $li[0].searchdoc_tree_data.path;
300
+ if (path) this.panel.open(path);
301
+ }
302
+
303
+ this.highlight = function($li) {
304
+ if (this.$current) this.$current.removeClass('current');
305
+ this.$current = $li.addClass('current');
306
+ }
307
+
308
+ this.toggle = function($li) {
309
+ var closed = !$li.hasClass('closed'),
310
+ children = $li[0].searchdoc_tree_data.children;
311
+ $li.toggleClass('closed');
312
+ for (var i=0, l = children.length; i < l; i++) {
313
+ toggleVis.call(this, $(children[i].li), !closed);
314
+ };
315
+ }
316
+
317
+ this.moveRight = function() {
318
+ if (!this.$current) {
319
+ this.highlight(this.$list.find('li:first'));
320
+ return;
321
+ }
322
+ if (this.$current.hasClass('closed')) {
323
+ this.toggle(this.$current);
324
+ }
325
+ }
326
+
327
+ this.moveLeft = function() {
328
+ if (!this.$current) {
329
+ this.highlight(this.$list.find('li:first'));
330
+ return;
331
+ }
332
+ if (!this.$current.hasClass('closed')) {
333
+ this.toggle(this.$current);
334
+ } else {
335
+ var level = this.$current[0].searchdoc_tree_data.level;
336
+ if (level == 0) return;
337
+ var $next = this.$current.prevAll('li.level_' + (level - 1) + ':visible:first');
338
+ this.$current.removeClass('current');
339
+ $next.addClass('current');
340
+ scrollIntoView($next[0], this.$element[0]);
341
+ this.$current = $next;
342
+ }
343
+ }
344
+
345
+ this.move = function(isDown) {
346
+ if (!this.$current) {
347
+ this.highlight(this.$list.find('li:first'));
348
+ return true;
349
+ }
350
+ var next = this.$current[0];
351
+ if (isDown) {
352
+ do {
353
+ next = next.nextSibling;
354
+ if (next && next.style && next.style.display != 'none') break;
355
+ } while(next);
356
+ } else {
357
+ do {
358
+ next = next.previousSibling;
359
+ if (next && next.style && next.style.display != 'none') break;
360
+ } while(next);
361
+ }
362
+ if (next && next.className.indexOf('stopper') == -1) {
363
+ this.$current.removeClass('current');
364
+ $(next).addClass('current');
365
+ scrollIntoView(next, this.$element[0]);
366
+ this.$current = $(next);
367
+ }
368
+ return true;
369
+ }
370
+
371
+ function toggleVis($li, show) {
372
+ var closed = $li.hasClass('closed'),
373
+ children = $li[0].searchdoc_tree_data.children;
374
+ $li.css('display', show ? '' : 'none')
375
+ if (!show && this.$current && $li[0] == this.$current[0]) {
376
+ this.$current.removeClass('current');
377
+ this.$current = null;
378
+ }
379
+ for (var i=0, l = children.length; i < l; i++) {
380
+ toggleVis.call(this, $(children[i].li), show && !closed);
381
+ };
382
+ }
383
+
384
+ function buildAndAppendItem(item, level, before) {
385
+ var li = renderItem(item, level),
386
+ list = this.$list[0];
387
+ item.li = li;
388
+ list.insertBefore(li, before);
389
+ for (var i=0, l = item[3].length; i < l; i++) {
390
+ buildAndAppendItem.call(this, item[3][i], level + 1, before);
391
+ };
392
+ return li;
393
+ }
394
+
395
+ function renderItem(item, level) {
396
+ var li = document.createElement('li'),
397
+ cnt = document.createElement('div'),
398
+ h1 = document.createElement('h1'),
399
+ p = document.createElement('p'),
400
+ icon, i;
401
+
402
+ li.appendChild(cnt);
403
+ li.style.paddingLeft = getOffset(level);
404
+ cnt.className = 'content';
405
+ if (!item[1]) li.className = 'empty ';
406
+ cnt.appendChild(h1);
407
+ // cnt.appendChild(p);
408
+ h1.appendChild(document.createTextNode(item[0]));
409
+ // p.appendChild(document.createTextNode(item[4]));
410
+ if (item[2]) {
411
+ i = document.createElement('i');
412
+ i.appendChild(document.createTextNode(item[2]));
413
+ h1.appendChild(i);
414
+ }
415
+ if (item[3].length > 0) {
416
+ icon = document.createElement('div');
417
+ icon.className = 'icon';
418
+ cnt.appendChild(icon);
419
+ }
420
+
421
+ // user direct assignement instead of $()
422
+ // it's 8x faster
423
+ // $(li).data('path', item[1])
424
+ // .data('children', item[3])
425
+ // .data('level', level)
426
+ // .css('display', level == 0 ? '' : 'none')
427
+ // .addClass('level_' + level)
428
+ // .addClass('closed');
429
+ li.searchdoc_tree_data = {
430
+ path: item[1],
431
+ children: item[3],
432
+ level: level
433
+ }
434
+ li.style.display = level == 0 ? '' : 'none';
435
+ li.className += 'level_' + level + ' closed';
436
+ return li;
437
+ }
438
+
439
+ function getOffset(level) {
440
+ return 5 + 18*level + 'px';
441
+ }
442
+ });