sdoc-templates-42floors 0.2

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