yard 0.9.37 → 0.9.41

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