yard 0.9.36 → 0.9.40

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 (81) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +59 -1
  3. data/README.md +29 -25
  4. data/docs/GettingStarted.md +41 -15
  5. data/docs/Tags.md +5 -5
  6. data/docs/Templates.md +5 -4
  7. data/docs/WhatsNew.md +59 -7
  8. data/docs/templates/default/yard_tags/html/setup.rb +1 -1
  9. data/lib/yard/autoload.rb +18 -0
  10. data/lib/yard/cli/diff.rb +7 -2
  11. data/lib/yard/code_objects/base.rb +1 -1
  12. data/lib/yard/code_objects/extra_file_object.rb +1 -0
  13. data/lib/yard/code_objects/macro_object.rb +0 -1
  14. data/lib/yard/code_objects/proxy.rb +1 -1
  15. data/lib/yard/docstring_parser.rb +0 -1
  16. data/lib/yard/handlers/base.rb +23 -1
  17. data/lib/yard/handlers/processor.rb +1 -1
  18. data/lib/yard/handlers/rbs/attribute_handler.rb +43 -0
  19. data/lib/yard/handlers/rbs/base.rb +38 -0
  20. data/lib/yard/handlers/rbs/constant_handler.rb +18 -0
  21. data/lib/yard/handlers/rbs/method_handler.rb +327 -0
  22. data/lib/yard/handlers/rbs/mixin_handler.rb +20 -0
  23. data/lib/yard/handlers/rbs/namespace_handler.rb +26 -0
  24. data/lib/yard/handlers/ruby/attribute_handler.rb +7 -4
  25. data/lib/yard/handlers/ruby/constant_handler.rb +24 -6
  26. data/lib/yard/handlers/ruby/legacy/visibility_handler.rb +2 -1
  27. data/lib/yard/handlers/ruby/visibility_handler.rb +14 -1
  28. data/lib/yard/i18n/locale.rb +1 -1
  29. data/lib/yard/i18n/pot_generator.rb +1 -1
  30. data/lib/yard/logging.rb +116 -61
  31. data/lib/yard/open_struct.rb +67 -0
  32. data/lib/yard/parser/rbs/rbs_parser.rb +325 -0
  33. data/lib/yard/parser/rbs/statement.rb +75 -0
  34. data/lib/yard/parser/ruby/ast_node.rb +5 -4
  35. data/lib/yard/parser/ruby/legacy/irb/slex.rb +19 -1
  36. data/lib/yard/parser/ruby/legacy/ruby_lex.rb +20 -5
  37. data/lib/yard/parser/ruby/ruby_parser.rb +109 -24
  38. data/lib/yard/parser/source_parser.rb +5 -4
  39. data/lib/yard/registry_resolver.rb +7 -0
  40. data/lib/yard/rubygems/specification.rb +1 -1
  41. data/lib/yard/server/library_version.rb +1 -1
  42. data/lib/yard/server/templates/default/fulldoc/html/js/autocomplete.js +208 -12
  43. data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +1 -17
  44. data/lib/yard/server/templates/default/method_details/html/permalink.erb +4 -2
  45. data/lib/yard/server/templates/doc_server/library_list/html/headers.erb +3 -3
  46. data/lib/yard/server/templates/doc_server/library_list/html/library_list.erb +2 -3
  47. data/lib/yard/server/templates/doc_server/processing/html/processing.erb +22 -16
  48. data/lib/yard/tags/default_factory.rb +1 -0
  49. data/lib/yard/tags/directives.rb +7 -1
  50. data/lib/yard/tags/library.rb +3 -3
  51. data/lib/yard/tags/overload_tag.rb +2 -1
  52. data/lib/yard/tags/tag.rb +2 -1
  53. data/lib/yard/tags/types_explainer.rb +5 -4
  54. data/lib/yard/templates/engine.rb +0 -1
  55. data/lib/yard/templates/helpers/base_helper.rb +1 -1
  56. data/lib/yard/templates/helpers/html_helper.rb +21 -6
  57. data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +6 -1
  58. data/lib/yard/templates/helpers/markup/hybrid_markdown.rb +2125 -0
  59. data/lib/yard/templates/helpers/markup/rdoc_markup.rb +2 -0
  60. data/lib/yard/templates/helpers/markup_helper.rb +4 -2
  61. data/lib/yard/templates/template_options.rb +0 -1
  62. data/lib/yard/version.rb +1 -1
  63. data/po/ja.po +82 -82
  64. data/templates/default/fulldoc/html/css/full_list.css +3 -3
  65. data/templates/default/fulldoc/html/css/style.css +8 -15
  66. data/templates/default/fulldoc/html/full_list.erb +8 -5
  67. data/templates/default/fulldoc/html/js/app.js +546 -281
  68. data/templates/default/fulldoc/html/js/full_list.js +315 -189
  69. data/templates/default/fulldoc/html/setup.rb +10 -2
  70. data/templates/default/layout/html/headers.erb +1 -1
  71. data/templates/default/method/html/header.erb +3 -3
  72. data/templates/default/module/html/defines.erb +3 -3
  73. data/templates/default/module/html/inherited_methods.erb +1 -0
  74. data/templates/default/module/html/method_summary.erb +8 -0
  75. data/templates/default/module/setup.rb +20 -0
  76. data/templates/default/onefile/html/headers.erb +2 -0
  77. data/templates/default/onefile/html/layout.erb +3 -4
  78. data/templates/default/tags/html/example.erb +2 -2
  79. data/templates/guide/fulldoc/html/js/app.js +57 -26
  80. data/templates/guide/layout/html/layout.erb +9 -11
  81. metadata +19 -8
@@ -1,314 +1,579 @@
1
1
  (function() {
2
+ var appState = window.__yardAppState || (window.__yardAppState = {
3
+ navigationListenerBound: false,
4
+ navigationChangeBound: false,
5
+ navResizerBound: false,
6
+ searchFrameGlobalsBound: false
7
+ });
8
+ var safeLocalStorage = {};
9
+ var safeSessionStorage = {};
10
+
11
+ try {
12
+ safeLocalStorage = window.localStorage;
13
+ } catch (error) {}
14
+
15
+ try {
16
+ safeSessionStorage = window.sessionStorage;
17
+ } catch (error) {}
18
+
19
+ function query(selector, root) {
20
+ return (root || document).querySelector(selector);
21
+ }
22
+
23
+ function queryAll(selector, root) {
24
+ return Array.prototype.slice.call(
25
+ (root || document).querySelectorAll(selector)
26
+ );
27
+ }
28
+
29
+ function isVisible(element) {
30
+ if (!element) return false;
31
+ return window.getComputedStyle(element).display !== "none";
32
+ }
33
+
34
+ function toggleDisplay(element, visible, displayValue) {
35
+ if (!element) return;
36
+ element.style.display = visible ? (displayValue || "") : "none";
37
+ }
38
+
39
+ function firstNextMatchingSibling(element, selector) {
40
+ var current = element;
41
+ while (current) {
42
+ current = current.nextElementSibling;
43
+ if (current && current.matches(selector)) return current;
44
+ }
45
+ return null;
46
+ }
47
+
48
+ function ready(callback) {
49
+ if (document.readyState === "loading") {
50
+ document.addEventListener("DOMContentLoaded", callback, { once: true });
51
+ } else {
52
+ callback();
53
+ }
54
+ }
55
+
56
+ function createSourceLinks() {
57
+ queryAll(".method_details_list .source_code").forEach(function(sourceCode) {
58
+ var toggleWrapper = document.createElement("span");
59
+ var link = document.createElement("a");
60
+
61
+ toggleWrapper.className = "showSource";
62
+ toggleWrapper.appendChild(document.createTextNode("["));
63
+ toggleWrapper.appendChild(link);
64
+ toggleWrapper.appendChild(document.createTextNode("]"));
65
+
66
+ link.href = "#";
67
+ link.className = "toggleSource";
68
+ link.textContent = "View source";
2
69
 
3
- var localStorage = {}, sessionStorage = {};
4
- try { localStorage = window.localStorage; } catch (e) { }
5
- try { sessionStorage = window.sessionStorage; } catch (e) { }
6
-
7
- function createSourceLinks() {
8
- $('.method_details_list .source_code').
9
- before("<span class='showSource'>[<a href='#' class='toggleSource'>View source</a>]</span>");
10
- $('.toggleSource').toggle(function() {
11
- $(this).parent().nextAll('.source_code').slideDown(100);
12
- $(this).text("Hide source");
13
- },
14
- function() {
15
- $(this).parent().nextAll('.source_code').slideUp(100);
16
- $(this).text("View source");
70
+ link.addEventListener("click", function(event) {
71
+ event.preventDefault();
72
+ var expanded = isVisible(sourceCode);
73
+ toggleDisplay(sourceCode, !expanded, "table");
74
+ link.textContent = expanded ? "View source" : "Hide source";
75
+ });
76
+
77
+ sourceCode.parentNode.insertBefore(toggleWrapper, sourceCode);
17
78
  });
18
- }
19
-
20
- function createDefineLinks() {
21
- var tHeight = 0;
22
- $('.defines').after(" <a href='#' class='toggleDefines'>more...</a>");
23
- $('.toggleDefines').toggle(function() {
24
- tHeight = $(this).parent().prev().height();
25
- $(this).prev().css('display', 'inline');
26
- $(this).parent().prev().height($(this).parent().height());
27
- $(this).text("(less)");
28
- },
29
- function() {
30
- $(this).prev().hide();
31
- $(this).parent().prev().height(tHeight);
32
- $(this).text("more...");
79
+ }
80
+
81
+ function createDefineLinks() {
82
+ queryAll(".defines").forEach(function(defines) {
83
+ var toggleLink = document.createElement("a");
84
+ var summary = defines.parentElement.previousElementSibling;
85
+
86
+ toggleLink.href = "#";
87
+ toggleLink.className = "toggleDefines";
88
+ toggleLink.textContent = "more...";
89
+ defines.insertAdjacentText("afterend", " ");
90
+ defines.insertAdjacentElement("afterend", toggleLink);
91
+
92
+ toggleLink.addEventListener("click", function(event) {
93
+ event.preventDefault();
94
+ var expanded = toggleLink.dataset.expanded === "true";
95
+
96
+ if (!expanded) {
97
+ toggleLink.dataset.height = String(summary.offsetHeight);
98
+ defines.style.display = "inline";
99
+ summary.style.height = toggleLink.parentElement.offsetHeight + "px";
100
+ toggleLink.textContent = "(less)";
101
+ toggleLink.dataset.expanded = "true";
102
+ } else {
103
+ defines.style.display = "none";
104
+ if (toggleLink.dataset.height) {
105
+ summary.style.height = toggleLink.dataset.height + "px";
106
+ }
107
+ toggleLink.textContent = "more...";
108
+ toggleLink.dataset.expanded = "false";
109
+ }
110
+ });
33
111
  });
34
- }
35
-
36
- function createFullTreeLinks() {
37
- var tHeight = 0;
38
- $('.inheritanceTree').toggle(function() {
39
- tHeight = $(this).parent().prev().height();
40
- $(this).parent().toggleClass('showAll');
41
- $(this).text("(hide)");
42
- $(this).parent().prev().height($(this).parent().height());
43
- },
44
- function() {
45
- $(this).parent().toggleClass('showAll');
46
- $(this).parent().prev().height(tHeight);
47
- $(this).text("show all");
112
+ }
113
+
114
+ function createFullTreeLinks() {
115
+ queryAll(".inheritanceTree").forEach(function(toggleLink) {
116
+ var container = toggleLink.parentElement;
117
+ var tree = container.previousElementSibling;
118
+
119
+ toggleLink.addEventListener("click", function(event) {
120
+ event.preventDefault();
121
+ var expanded = toggleLink.dataset.expanded === "true";
122
+
123
+ if (!expanded) {
124
+ toggleLink.dataset.height = String(tree.offsetHeight);
125
+ container.classList.add("showAll");
126
+ toggleLink.textContent = "(hide)";
127
+ tree.style.height = container.offsetHeight + "px";
128
+ toggleLink.dataset.expanded = "true";
129
+ } else {
130
+ container.classList.remove("showAll");
131
+ if (toggleLink.dataset.height) {
132
+ tree.style.height = toggleLink.dataset.height + "px";
133
+ }
134
+ toggleLink.textContent = "show all";
135
+ toggleLink.dataset.expanded = "false";
136
+ }
137
+ });
48
138
  });
49
- }
139
+ }
50
140
 
51
- function searchFrameButtons() {
52
- $('.full_list_link').click(function() {
53
- toggleSearchFrame(this, $(this).attr('href'));
54
- return false;
55
- });
56
- window.addEventListener('message', function(e) {
57
- if (e.data === 'navEscape') {
58
- $('#nav').slideUp(100);
59
- $('#search a').removeClass('active inactive');
60
- $(window).focus();
61
- }
62
- });
141
+ function resetSearchFrame() {
142
+ var frame = query("#nav");
143
+
144
+ if (frame) frame.removeAttribute("style");
145
+ queryAll("#search a").forEach(function(link) {
146
+ link.classList.remove("active");
147
+ link.classList.remove("inactive");
148
+ });
149
+ window.focus();
150
+ }
63
151
 
64
- $(window).resize(function() {
65
- if ($('#search:visible').length === 0) {
66
- $('#nav').removeAttr('style');
67
- $('#search a').removeClass('active inactive');
68
- $(window).focus();
152
+ function toggleSearchFrame(linkElement, link) {
153
+ var frame = query("#nav");
154
+
155
+ if (!frame) return;
156
+
157
+ queryAll("#search a").forEach(function(searchLink) {
158
+ searchLink.classList.remove("active");
159
+ searchLink.classList.add("inactive");
160
+ });
161
+
162
+ if (frame.getAttribute("src") === link && isVisible(frame)) {
163
+ frame.style.display = "none";
164
+ queryAll("#search a").forEach(function(searchLink) {
165
+ searchLink.classList.remove("active");
166
+ searchLink.classList.remove("inactive");
167
+ });
168
+ } else {
169
+ linkElement.classList.add("active");
170
+ linkElement.classList.remove("inactive");
171
+ if (frame.getAttribute("src") !== link) frame.setAttribute("src", link);
172
+ frame.style.display = "block";
69
173
  }
70
- });
71
- }
72
-
73
- function toggleSearchFrame(id, link) {
74
- var frame = $('#nav');
75
- $('#search a').removeClass('active').addClass('inactive');
76
- if (frame.attr('src') === link && frame.css('display') !== "none") {
77
- frame.slideUp(100);
78
- $('#search a').removeClass('active inactive');
79
174
  }
80
- else {
81
- $(id).addClass('active').removeClass('inactive');
82
- if (frame.attr('src') !== link) frame.attr('src', link);
83
- frame.slideDown(100);
175
+
176
+ function searchFrameButtons() {
177
+ queryAll(".full_list_link").forEach(function(link) {
178
+ if (link.dataset.yardSearchFrameBound === "true") return;
179
+
180
+ link.addEventListener("click", function(event) {
181
+ event.preventDefault();
182
+ toggleSearchFrame(link, link.getAttribute("href"));
183
+ });
184
+
185
+ link.dataset.yardSearchFrameBound = "true";
186
+ });
187
+
188
+ if (appState.searchFrameGlobalsBound) return;
189
+
190
+ window.addEventListener("message", function(event) {
191
+ if (event.data === "navEscape") resetSearchFrame();
192
+ });
193
+
194
+ window.addEventListener("resize", function() {
195
+ if (!isVisible(query("#search"))) resetSearchFrame();
196
+ });
197
+
198
+ appState.searchFrameGlobalsBound = true;
84
199
  }
85
- }
86
200
 
87
- function linkSummaries() {
88
- $('.summary_signature').click(function() {
89
- document.location = $(this).find('a').attr('href');
90
- });
91
- }
92
-
93
- function summaryToggle() {
94
- $('.summary_toggle').click(function(e) {
95
- e.preventDefault();
96
- localStorage.summaryCollapsed = $(this).text();
97
- $('.summary_toggle').each(function() {
98
- $(this).text($(this).text() == "collapse" ? "expand" : "collapse");
99
- var next = $(this).parent().parent().nextAll('ul.summary').first();
100
- if (next.hasClass('compact')) {
101
- next.toggle();
102
- next.nextAll('ul.summary').first().toggle();
103
- }
104
- else if (next.hasClass('summary')) {
105
- var list = $('<ul class="summary compact" />');
106
- list.html(next.html());
107
- list.find('.summary_desc, .note').remove();
108
- list.find('a').each(function() {
109
- $(this).html($(this).find('strong').html());
110
- $(this).parent().html($(this)[0].outerHTML);
111
- });
112
- next.before(list);
113
- next.toggle();
114
- }
201
+ function linkSummaries() {
202
+ queryAll(".summary_signature").forEach(function(signature) {
203
+ signature.addEventListener("click", function(event) {
204
+ if (event.target.closest("a")) return;
205
+ var link = signature.querySelector("a");
206
+ if (link) document.location = link.getAttribute("href");
207
+ });
115
208
  });
116
- return false;
117
- });
118
- if (localStorage.summaryCollapsed == "collapse") {
119
- $('.summary_toggle').first().click();
120
- } else { localStorage.summaryCollapsed = "expand"; }
121
- }
122
-
123
- function constantSummaryToggle() {
124
- $('.constants_summary_toggle').click(function(e) {
125
- e.preventDefault();
126
- localStorage.summaryCollapsed = $(this).text();
127
- $('.constants_summary_toggle').each(function() {
128
- $(this).text($(this).text() == "collapse" ? "expand" : "collapse");
129
- var next = $(this).parent().parent().nextAll('dl.constants').first();
130
- if (next.hasClass('compact')) {
131
- next.toggle();
132
- next.nextAll('dl.constants').first().toggle();
133
- }
134
- else if (next.hasClass('constants')) {
135
- var list = $('<dl class="constants compact" />');
136
- list.html(next.html());
137
- list.find('dt').each(function() {
138
- $(this).addClass('summary_signature');
139
- $(this).text( $(this).text().split('=')[0]);
140
- if ($(this).has(".deprecated").length) {
141
- $(this).addClass('deprecated');
142
- };
143
- });
144
- // Add the value of the constant as "Tooltip" to the summary object
145
- list.find('pre.code').each(function() {
146
- console.log($(this).parent());
147
- var dt_element = $(this).parent().prev();
148
- var tooltip = $(this).text();
149
- if (dt_element.hasClass("deprecated")) {
150
- tooltip = 'Deprecated. ' + tooltip;
151
- };
152
- dt_element.attr('title', tooltip);
209
+ }
210
+
211
+ function toggleSummaryCollection(toggleSelector, listSelector, cloneBuilder) {
212
+ queryAll(toggleSelector).forEach(function(toggleLink) {
213
+ toggleLink.addEventListener("click", function(event) {
214
+ event.preventDefault();
215
+ safeLocalStorage.summaryCollapsed = toggleLink.textContent;
216
+
217
+ queryAll(toggleSelector).forEach(function(link) {
218
+ link.textContent =
219
+ link.textContent === "collapse" ? "expand" : "collapse";
220
+
221
+ var container = link.parentElement.parentElement;
222
+ var next = firstNextMatchingSibling(container, listSelector);
223
+
224
+ if (!next) return;
225
+
226
+ if (next.classList.contains("compact")) {
227
+ var fullList = firstNextMatchingSibling(next, listSelector);
228
+ toggleDisplay(next, !isVisible(next));
229
+ toggleDisplay(fullList, !isVisible(fullList));
230
+ } else {
231
+ var compactList = cloneBuilder(next.cloneNode(true));
232
+ next.parentNode.insertBefore(compactList, next);
233
+ toggleDisplay(next, false);
234
+ }
153
235
  });
154
- list.find('.docstring, .tags, dd').remove();
155
- next.before(list);
156
- next.toggle();
157
- }
236
+ });
158
237
  });
159
- return false;
160
- });
161
- if (localStorage.summaryCollapsed == "collapse") {
162
- $('.constants_summary_toggle').first().click();
163
- } else { localStorage.summaryCollapsed = "expand"; }
164
- }
165
-
166
- function generateTOC() {
167
- if ($('#filecontents').length === 0) return;
168
- var _toc = $('<ol class="top"></ol>');
169
- var show = false;
170
- var toc = _toc;
171
- var counter = 0;
172
- var tags = ['h2', 'h3', 'h4', 'h5', 'h6'];
173
- var i;
174
- var curli;
175
- if ($('#filecontents h1').length > 1) tags.unshift('h1');
176
- for (i = 0; i < tags.length; i++) { tags[i] = '#filecontents ' + tags[i]; }
177
- var lastTag = parseInt(tags[0][1], 10);
178
- $(tags.join(', ')).each(function() {
179
- if ($(this).parents('.method_details .docstring').length != 0) return;
180
- if (this.id == "filecontents") return;
181
- show = true;
182
- var thisTag = parseInt(this.tagName[1], 10);
183
- if (this.id.length === 0) {
184
- var proposedId = $(this).attr('toc-id');
185
- if (typeof(proposedId) != "undefined") this.id = proposedId;
186
- else {
187
- var proposedId = $(this).text().replace(/[^a-z0-9-]/ig, '_');
188
- if ($('#' + proposedId).length > 0) { proposedId += counter; counter++; }
189
- this.id = proposedId;
238
+ }
239
+
240
+ function buildCompactSummary(list) {
241
+ list.className = "summary compact";
242
+
243
+ queryAll(".summary_desc, .note", list).forEach(function(node) {
244
+ node.remove();
245
+ });
246
+
247
+ queryAll("a", list).forEach(function(link) {
248
+ var strong = link.querySelector("strong");
249
+ if (strong) link.innerHTML = strong.innerHTML;
250
+ if (link.parentElement) link.parentElement.outerHTML = link.outerHTML;
251
+ });
252
+
253
+ return list;
254
+ }
255
+
256
+ function buildCompactConstants(list) {
257
+ list.className = "constants compact";
258
+
259
+ queryAll("dt", list).forEach(function(node) {
260
+ var deprecated = !!node.querySelector(".deprecated");
261
+ node.classList.add("summary_signature");
262
+ node.textContent = node.textContent.split("=")[0];
263
+ if (deprecated) node.classList.add("deprecated");
264
+ });
265
+
266
+ queryAll("pre.code", list).forEach(function(pre) {
267
+ var dtElement = pre.parentElement.previousElementSibling;
268
+ var tooltip = pre.textContent;
269
+ if (dtElement.classList.contains("deprecated")) {
270
+ tooltip = "Deprecated. " + tooltip;
190
271
  }
272
+ dtElement.setAttribute("title", tooltip);
273
+ });
274
+
275
+ queryAll(".docstring, .tags, dd", list).forEach(function(node) {
276
+ node.remove();
277
+ });
278
+
279
+ return list;
280
+ }
281
+
282
+ function summaryToggle() {
283
+ toggleSummaryCollection(".summary_toggle", "ul.summary", buildCompactSummary);
284
+
285
+ if (safeLocalStorage.summaryCollapsed === "collapse") {
286
+ var toggle = query(".summary_toggle");
287
+ if (toggle) toggle.click();
288
+ } else {
289
+ safeLocalStorage.summaryCollapsed = "expand";
290
+ }
291
+ }
292
+
293
+ function constantSummaryToggle() {
294
+ toggleSummaryCollection(
295
+ ".constants_summary_toggle",
296
+ "dl.constants",
297
+ buildCompactConstants
298
+ );
299
+
300
+ if (safeLocalStorage.summaryCollapsed === "collapse") {
301
+ var toggle = query(".constants_summary_toggle");
302
+ if (toggle) toggle.click();
303
+ } else {
304
+ safeLocalStorage.summaryCollapsed = "expand";
191
305
  }
192
- if (thisTag > lastTag) {
193
- for (i = 0; i < thisTag - lastTag; i++) {
194
- if ( typeof(curli) == "undefined" ) {
195
- curli = $('<li/>');
196
- toc.append(curli);
306
+ }
307
+
308
+ function generateTOC() {
309
+ var fileContents = query("#filecontents");
310
+ var content = query("#content");
311
+
312
+ if (!fileContents || !content) return;
313
+
314
+ var topLevel = document.createElement("ol");
315
+ var currentList = topLevel;
316
+ var currentItem;
317
+ var counter = 0;
318
+ var headings = ["h2", "h3", "h4", "h5", "h6"];
319
+ var hasEntries = false;
320
+
321
+ topLevel.className = "top";
322
+
323
+ if (queryAll("#filecontents h1").length > 1) headings.unshift("h1");
324
+
325
+ var selectors = headings.map(function(tagName) {
326
+ return "#filecontents " + tagName;
327
+ });
328
+
329
+ var lastLevel = parseInt(headings[0].substring(1), 10);
330
+
331
+ queryAll(selectors.join(", ")).forEach(function(heading) {
332
+ var level;
333
+ var title;
334
+ var item;
335
+
336
+ if (heading.closest(".method_details .docstring")) return;
337
+ if (heading.id === "filecontents") return;
338
+
339
+ hasEntries = true;
340
+ level = parseInt(heading.tagName.substring(1), 10);
341
+
342
+ if (!heading.id) {
343
+ var proposedId = heading.getAttribute("toc-id");
344
+ if (!proposedId) {
345
+ proposedId = heading.textContent.replace(/[^a-z0-9-]/gi, "_");
346
+ if (query("#" + proposedId)) {
347
+ proposedId += counter;
348
+ counter += 1;
349
+ }
197
350
  }
198
- toc = $('<ol/>');
199
- curli.append(toc);
200
- curli = undefined;
351
+ heading.id = proposedId;
201
352
  }
202
- }
203
- if (thisTag < lastTag) {
204
- for (i = 0; i < lastTag - thisTag; i++) {
205
- toc = toc.parent();
206
- toc = toc.parent();
353
+
354
+ if (level > lastLevel) {
355
+ while (level > lastLevel) {
356
+ if (!currentItem) {
357
+ currentItem = document.createElement("li");
358
+ currentList.appendChild(currentItem);
359
+ }
360
+ var nestedList = document.createElement("ol");
361
+ currentItem.appendChild(nestedList);
362
+ currentList = nestedList;
363
+ currentItem = null;
364
+ lastLevel += 1;
365
+ }
366
+ } else if (level < lastLevel) {
367
+ while (level < lastLevel && currentList.parentElement) {
368
+ currentList = currentList.parentElement.parentElement;
369
+ lastLevel -= 1;
370
+ }
207
371
  }
208
- }
209
- var title = $(this).attr('toc-title');
210
- if (typeof(title) == "undefined") title = $(this).text();
211
- curli =$('<li><a href="#' + this.id + '">' + title + '</a></li>');
212
- toc.append(curli);
213
- lastTag = thisTag;
214
- });
215
- if (!show) return;
216
- html = '<div id="toc"><p class="title hide_toc"><a href="#"><strong>Table of Contents</strong></a></p></div>';
217
- $('#content').prepend(html);
218
- $('#toc').append(_toc);
219
- $('#toc .hide_toc').toggle(function() {
220
- $('#toc .top').slideUp('fast');
221
- $('#toc').toggleClass('hidden');
222
- $('#toc .title small').toggle();
223
- }, function() {
224
- $('#toc .top').slideDown('fast');
225
- $('#toc').toggleClass('hidden');
226
- $('#toc .title small').toggle();
227
- });
228
- }
229
372
 
230
- function navResizeFn(e) {
231
- if (e.which !== 1) {
232
- navResizeFnStop();
233
- return;
373
+ title = heading.getAttribute("toc-title") || heading.textContent;
374
+ item = document.createElement("li");
375
+ item.innerHTML = '<a href="#' + heading.id + '">' + title + "</a>";
376
+ currentList.appendChild(item);
377
+ currentItem = item;
378
+ });
379
+
380
+ if (!hasEntries) return;
381
+
382
+ var toc = document.createElement("div");
383
+ toc.id = "toc";
384
+ toc.innerHTML =
385
+ '<p class="title hide_toc"><a href="#"><strong>Table of Contents</strong></a></p>';
386
+ content.insertBefore(toc, content.firstChild);
387
+ toc.appendChild(topLevel);
388
+
389
+ var hideLink = query("#toc .hide_toc");
390
+ if (hideLink) {
391
+ hideLink.addEventListener("click", function(event) {
392
+ event.preventDefault();
393
+ var list = query("#toc .top");
394
+ var hidden = query("#toc").classList.toggle("hidden");
395
+ toggleDisplay(list, !hidden);
396
+ queryAll("#toc .title small").forEach(function(node) {
397
+ toggleDisplay(node, hidden);
398
+ });
399
+ });
400
+ }
234
401
  }
235
402
 
236
- sessionStorage.navWidth = e.pageX.toString();
237
- $('.nav_wrap').css('width', e.pageX);
238
- $('.nav_wrap').css('-ms-flex', 'inherit');
239
- }
240
-
241
- function navResizeFnStop() {
242
- $(window).unbind('mousemove', navResizeFn);
243
- window.removeEventListener('message', navMessageFn, false);
244
- }
245
-
246
- function navMessageFn(e) {
247
- if (e.data.action === 'mousemove') navResizeFn(e.data.event);
248
- if (e.data.action === 'mouseup') navResizeFnStop();
249
- }
250
-
251
- function navResizer() {
252
- $('#resizer').mousedown(function(e) {
253
- e.preventDefault();
254
- $(window).mousemove(navResizeFn);
255
- window.addEventListener('message', navMessageFn, false);
256
- });
257
- $(window).mouseup(navResizeFnStop);
403
+ function navResizer() {
404
+ var resizer = document.getElementById("resizer");
405
+
406
+ if (!resizer) return;
407
+
408
+ if (!appState.navResizerBound) {
409
+ resizer.addEventListener(
410
+ "pointerdown",
411
+ function(event) {
412
+ resizer.setPointerCapture(event.pointerId);
413
+ event.preventDefault();
414
+ event.stopPropagation();
415
+ },
416
+ false
417
+ );
418
+ resizer.addEventListener(
419
+ "pointerup",
420
+ function(event) {
421
+ resizer.releasePointerCapture(event.pointerId);
422
+ event.preventDefault();
423
+ event.stopPropagation();
424
+ },
425
+ false
426
+ );
427
+ resizer.addEventListener(
428
+ "pointermove",
429
+ function(event) {
430
+ if ((event.buttons & 1) === 0) return;
258
431
 
259
- if (sessionStorage.navWidth) {
260
- navResizeFn({which: 1, pageX: parseInt(sessionStorage.navWidth, 10)});
432
+ safeSessionStorage.navWidth = String(event.pageX);
433
+ queryAll(".nav_wrap").forEach(function(node) {
434
+ node.style.width = Math.max(200, event.pageX) + "px";
435
+ });
436
+ event.preventDefault();
437
+ event.stopPropagation();
438
+ },
439
+ false
440
+ );
441
+
442
+ appState.navResizerBound = true;
443
+ }
444
+
445
+ if (safeSessionStorage.navWidth) {
446
+ queryAll(".nav_wrap").forEach(function(node) {
447
+ node.style.width =
448
+ Math.max(200, parseInt(safeSessionStorage.navWidth, 10)) + "px";
449
+ });
450
+ }
261
451
  }
262
- }
263
-
264
- function navExpander() {
265
- var done = false, timer = setTimeout(postMessage, 500);
266
- function postMessage() {
267
- if (done) return;
268
- clearTimeout(timer);
269
- var opts = { action: 'expand', path: pathId };
270
- document.getElementById('nav').contentWindow.postMessage(opts, '*');
271
- done = true;
452
+
453
+ function navExpander() {
454
+ if (typeof pathId === "undefined") return;
455
+
456
+ var done = false;
457
+ var timer = setTimeout(postMessage, 500);
458
+
459
+ function postMessage() {
460
+ var frame;
461
+ if (done) return;
462
+ clearTimeout(timer);
463
+ frame = document.getElementById("nav");
464
+ if (!frame || !frame.contentWindow) return;
465
+ frame.contentWindow.postMessage({ action: "expand", path: pathId }, "*");
466
+ done = true;
467
+ }
272
468
  }
273
469
 
274
- window.addEventListener('message', function(event) {
275
- if (event.data === 'navReady') postMessage();
276
- return false;
277
- }, false);
278
- }
470
+ function focusHashTarget() {
471
+ var hash = window.location.hash;
472
+ if (!hash) return;
473
+
474
+ var targetId = hash.slice(1);
475
+ var decodedTargetId = targetId;
279
476
 
280
- function mainFocus() {
281
- var hash = window.location.hash;
282
- if (hash !== '' && $(hash)[0]) {
283
- $(hash)[0].scrollIntoView();
477
+ try {
478
+ decodedTargetId = decodeURIComponent(targetId);
479
+ } catch (error) {}
480
+
481
+ var target =
482
+ document.getElementById(decodedTargetId) ||
483
+ document.getElementById(targetId);
484
+
485
+ if (target) target.scrollIntoView();
284
486
  }
285
487
 
286
- setTimeout(function() { $('#main').focus(); }, 10);
287
- }
488
+ function mainFocus() {
489
+ focusHashTarget();
490
+ setTimeout(function() {
491
+ var main = query("#main");
492
+ if (main) main.focus();
493
+ }, 10);
494
+ }
288
495
 
289
- function navigationChange() {
290
- // This works around the broken anchor navigation with the YARD template.
291
- window.onpopstate = function() {
292
- var hash = window.location.hash;
293
- if (hash !== '' && $(hash)[0]) {
294
- $(hash)[0].scrollIntoView();
295
- }
496
+ function navigationChange() {
497
+ if (appState.navigationChangeBound) return;
498
+
499
+ window.onpopstate = focusHashTarget;
500
+ appState.navigationChangeBound = true;
501
+ }
502
+
503
+ window.__app = function() {
504
+ ready(function() {
505
+ navResizer();
506
+ navExpander();
507
+ createSourceLinks();
508
+ createDefineLinks();
509
+ createFullTreeLinks();
510
+ searchFrameButtons();
511
+ linkSummaries();
512
+ summaryToggle();
513
+ constantSummaryToggle();
514
+ generateTOC();
515
+ mainFocus();
516
+ navigationChange();
517
+ });
296
518
  };
297
- }
298
-
299
- $(document).ready(function() {
300
- navResizer();
301
- navExpander();
302
- createSourceLinks();
303
- createDefineLinks();
304
- createFullTreeLinks();
305
- searchFrameButtons();
306
- linkSummaries();
307
- summaryToggle();
308
- constantSummaryToggle();
309
- generateTOC();
310
- mainFocus();
311
- navigationChange();
312
- });
313
519
 
520
+ window.__app();
521
+
522
+ if (!appState.navigationListenerBound) {
523
+ window.addEventListener(
524
+ "message",
525
+ async function(event) {
526
+ if (!event.data || event.data.action !== "navigate") return;
527
+
528
+ var response = await fetch(event.data.url);
529
+ var text = await response.text();
530
+ var parser = new DOMParser();
531
+ var doc = parser.parseFromString(text, "text/html");
532
+ var classListLink = document.getElementById("class_list_link");
533
+ var content = doc.querySelector("#main").innerHTML;
534
+
535
+ document.querySelector("#main").innerHTML = content;
536
+ document.title = doc.head.querySelector("title").innerText;
537
+
538
+ queryAll("script", document.head).forEach(function(script) {
539
+ if (
540
+ !script.type ||
541
+ (script.type.indexOf("text/javascript") !== -1 && !script.src)
542
+ ) {
543
+ script.remove();
544
+ }
545
+ });
546
+
547
+ queryAll("script", doc.head).forEach(function(script) {
548
+ if (
549
+ !script.type ||
550
+ (script.type.indexOf("text/javascript") !== -1 && !script.src)
551
+ ) {
552
+ var newScript = document.createElement("script");
553
+ newScript.type = "text/javascript";
554
+ newScript.textContent = script.textContent;
555
+ document.head.appendChild(newScript);
556
+ }
557
+ });
558
+
559
+ window.__app();
560
+
561
+ if (classListLink && document.getElementById("class_list_link")) {
562
+ document.getElementById("class_list_link").className =
563
+ classListLink.className;
564
+ }
565
+
566
+ var url = new URL(event.data.url, "http://localhost");
567
+ var hash = decodeURIComponent(url.hash || "");
568
+ if (hash) {
569
+ var target = document.getElementById(hash.substring(1));
570
+ if (target) target.scrollIntoView();
571
+ }
572
+ history.pushState({}, document.title, event.data.url);
573
+ },
574
+ false
575
+ );
576
+
577
+ appState.navigationListenerBound = true;
578
+ }
314
579
  })();