diff --git a/src/docs/index.html b/src/docs/index.html index d474bac..e233c24 100644 --- a/src/docs/index.html +++ b/src/docs/index.html @@ -18,9 +18,9 @@
- This page lists all registered Caddy modules. -
-- We recommend using your browser's "Find in page" feature for quick lookups. -
-Module ID | -Description | -
---|
+ This page lists all registered Caddy modules. Modules are plugins which extend Caddy's JSON configuration structure. +
++ We recommend using your browser's "Find in page" feature for quick lookups. +
++ | Module ID | +Description | +
---|
xcaddy build --with
\ No newline at end of file
+
\ No newline at end of file
diff --git a/src/resources/css/docs-json.css b/src/resources/css/docs-json.css
index ae0da31..cb31773 100644
--- a/src/resources/css/docs-json.css
+++ b/src/resources/css/docs-json.css
@@ -6,7 +6,7 @@ article h1 {
padding-top: 8%;
}
-#renderbox {
+.renderbox {
border-radius: 0;
font-size: 20px;
line-height: 1.6em;
diff --git a/src/resources/css/docs.css b/src/resources/css/docs.css
index 98895f4..5dadcea 100644
--- a/src/resources/css/docs.css
+++ b/src/resources/css/docs.css
@@ -224,6 +224,10 @@ main nav li li a {
max-width: 1100px;
}
+.pad {
+ padding-top: 8%;
+}
+
article {
padding-top: 8%;
padding-bottom: 8%;
@@ -238,7 +242,8 @@ width, a few elements should be allowed to
extend to the borders of the page
*/
article > :not(.fullwidth),
-article > .fullwidth > * {
+article > .fullwidth > *,
+.pad {
padding-left: 8%;
padding-right: 8%;
}
@@ -448,13 +453,13 @@ iframe {
padding: 10px;
color: #886c00;
line-height: 1.4em;
- display: none;
}
.nonstandard {
color: rgb(214, 145, 16);
}
+.standard-flag,
.nonstandard-flag {
cursor: help;
font-size: 8px;
@@ -462,10 +467,25 @@ iframe {
padding: 4px 8px;
text-transform: uppercase;
font-weight: bold;
- background-color: rgb(238, 167, 34);
color: white;
border-radius: 4px;
white-space: nowrap;
+ vertical-align: middle;
+}
+
+.standard-flag {
+ background-color: rgb(34, 163, 23);
+}
+
+.nonstandard-flag {
+ background-color: rgb(238, 167, 34);
+}
+
+.module-repo-differentiator {
+ font-size: 11px;
+ font-weight: bold;
+ color: #555;
+ line-height: 1em;
}
@@ -706,7 +726,8 @@ td code {
#module-docs-container,
-#module-list-container {
+#module-list-container,
+#module-template {
display: none;
}
@@ -729,7 +750,27 @@ td code {
}
+#module-multiple-repos {
+ display: none;
+ margin: 25px;
+}
+.module-repo-selector {
+ font-size: 26px;
+ padding: 25px;
+ font-weight: bold;
+ border-bottom: 1px solid #888;
+ cursor: pointer;
+}
+
+.module-repo-selector:hover {
+ color: #009cda;
+ background: rgb(246, 250, 252);
+}
+
+.module-repo-selector-arrow {
+ margin: 10px;
+}
diff --git a/src/resources/js/docs-api.js b/src/resources/js/docs-api.js
index 9cef567..1e52180 100644
--- a/src/resources/js/docs-api.js
+++ b/src/resources/js/docs-api.js
@@ -1,13 +1,14 @@
// TODO: sanitize all HTML renderings, especially markdown: https://github.com/cure53/DOMPurify
-var pageData = {}, pageDocs = {};
-
-var $renderbox, $hovercard;
+var pageDocs = {};
+var pageData = {};
+var $hovercard;
const nonStandardFlag = 'Non-standard';
+const standardFlag = 'Standard';
+
$(function() {
- $renderbox = $('#renderbox');
$hovercard = $('#hovercard');
var hoverTimeout;
@@ -19,7 +20,7 @@ $(function() {
});
// toggle an object as expanded or collapsed
- $('#renderbox').on('click', '.toggle-obj', function() {
+ $('body').on('click', '.renderbox .toggle-obj', function() {
if ($(this).hasClass('expanded')) {
// collapse
$(this).html('▸');
@@ -37,7 +38,9 @@ $(function() {
clearTimeout(hoverTimeout);
var pos = $(this).offset();
-
+ var moduleID = $(this).closest('.module-repo-container').data('module-id') || '';
+ var moduleData = pageData[moduleID];
+
// there is a gap between the hoverbox and the link that originated it;
// there may be a different link in this gap; if the hover box is visible,
// then we should ignore the hover on this link to allow cursor to visit
@@ -59,10 +62,10 @@ $(function() {
if ($(this).hasClass('module')) {
// module
var $list =$('');
- if (pageData.namespaces && pageData.namespaces[modNamespace]) {
- for (var i = 0; i < pageData.namespaces[modNamespace].length; i++) {
- var modInfo = pageData.namespaces[modNamespace][i];
- var href = canTraverse() ? '.'+elemPath+'/'+modInfo.name+'/' : './'+modNamespace+'.'+modInfo.name;
+ if (moduleData.namespaces && moduleData.namespaces[modNamespace]) {
+ for (var i = 0; i < moduleData.namespaces[modNamespace].length; i++) {
+ var modInfo = moduleData.namespaces[modNamespace][i];
+ var href = canTraverse(moduleData) ? '.'+elemPath+'/'+modInfo.name+'/' : './'+modNamespace+'.'+modInfo.name;
var content = ' '+modInfo.name;
if (!isStandard(modInfo.package)) {
content += nonStandardFlag;
@@ -83,7 +86,7 @@ $(function() {
// breadcrumb siblings
var siblingPath = $(this).data('sibling-path');
- var bcVal = pageData.breadcrumb[siblingPath];
+ var bcVal = moduleData.breadcrumb[siblingPath];
var bcSiblings = [];
// drill down to the true underlying type
@@ -101,8 +104,8 @@ $(function() {
case "module":
case "module_map":
- for (var j = 0; j < pageData.namespaces[bcVal.module_namespace].length; j++) {
- var mod = pageData.namespaces[bcVal.module_namespace][j];
+ for (var j = 0; j < moduleData.namespaces[bcVal.module_namespace].length; j++) {
+ var mod = moduleData.namespaces[bcVal.module_namespace][j];
bcSiblings.push({name: mod.name, path: siblingPath, isStandard: isStandard(mod.package)})
}
}
@@ -154,46 +157,58 @@ $(function() {
}, '.has-popup');
});
+function beginRenderingInto($tpl, moduleID, module) {
+ console.log("RENDERING:", moduleID, module);
+ $tpl.data('module-id', moduleID);
+ pageData[moduleID] = module;
-function beginRendering(json, moduleID) {
- pageData = json;
- console.log("PAGE DATA:", pageData);
-
// show notice if module is non-standard
- if (pageData.repo && !isStandard(pageData.structure.type_name)) {
- $('.nonstandard-project-link').attr('href', pageData.repo).text(pageData.repo);
- $('.nonstandard-notice').prepend(nonStandardFlag).show();
+ if (module.repo) {
+ if (isStandard(module.structure.type_name)) {
+ $('.nonstandard-notice', $tpl).remove();
+ } else {
+ let { pkg, _ } = splitTypeName(module.structure.type_name);
+ $('.nonstandard-project-link', $tpl).attr('href', module.repo).text(module.repo);
+ $('.nonstandard-package-path', $tpl).text(pkg);
+ $('.nonstandard-notice', $tpl).prepend(nonStandardFlag);
+ }
+
+ var $repoName = $('').text(stripScheme(module.repo));
+ $('.module-repo-selector', $tpl).html('▸').append($repoName);
}
// for most types, just render their docs; but for maps or arrays, fall through to underlying type for docs
- let rawDocs = pageData.structure.doc ?? pageData.structure.elems;
+ let rawDocs = module.structure.doc ?? module.structure.elems;
- $('#top-doc').html(markdown(replaceGoTypeNameWithCaddyModuleName(rawDocs, moduleID)));
- $('#top-doc').append(makeSubmoduleList("", pageData.structure));
+ $('.top-doc', $tpl).html(markdown(replaceGoTypeNameWithCaddyModuleName(rawDocs, module, moduleID)));
+ $('.top-doc', $tpl).append(makeSubmoduleList(module, "", module.structure));
- renderData(pageData.structure, 0, "", $(''));
+ let $group = newGroup();
+ renderData($tpl, module, module.structure, 0, "", $group);
+ $('.renderbox', $tpl).append($group);
- if ($('#field-list-contents').text().trim()) {
- $('#field-list-header').show();
+ if ($('.field-list-contents', $tpl).text().trim()) {
+ $('.field-list-header', $tpl).show();
}
- // if the browser tried to navigate directly to an element
- // on the page when it loaded, it would have failed since
- // we hadn't rendered it yet; but now we can scroll to it
- // directly since rendering has finished
- if (window.location.hash) {
- window.location.hash = window.location.hash;
- }
+ // TODO: see about fixing this for module and JSON docs pages
+ // // if the browser tried to navigate directly to an element
+ // // on the page when it loaded, it would have failed since
+ // // we hadn't rendered it yet; but now we can scroll to it
+ // // directly since rendering has finished
+ // if (window.location.hash.length > 1) {
+ // document.getElementById(window.location.hash.substr(1)).scrollIntoView();
+ // }
}
-function renderData(data, nesting, path, $group) {
+function renderData($tpl, module, data, nesting, path, $group) {
switch (data.type) {
case "struct":
$group.append('{▾');
nesting++;
- var $fieldGroup = $('');
- renderModuleInlineKey(data, nesting, $fieldGroup);
+ var $fieldGroup = newGroup();
+ renderModuleInlineKey($tpl, module, data, nesting, $fieldGroup);
$group.append($fieldGroup);
if (data.struct_fields) {
// TODO: Not sure if sorting the struct fields is a good idea...
@@ -216,19 +231,19 @@ function renderData(data, nesting, path, $group) {
// render the docs to the page
var fieldDoc = markdown(field.doc) || 'There are no docs for this property.
'; - fieldDoc += makeSubmoduleList(fieldPath, field.value); - appendToFieldDocs(cleanFieldPath, fieldDoc); + fieldDoc += makeSubmoduleList(module, fieldPath, field.value); + appendToFieldDocs($tpl, module, cleanFieldPath, fieldDoc); // render the field to the JSON box - var $fieldGroup = $(''); + var $fieldGroup = newGroup(); indent(nesting, $fieldGroup); var keyATag = ''+field.key+''; $fieldGroup.append('"'+keyATag+'": '); - renderData(field.value, nesting, fieldPath, $fieldGroup); + renderData($tpl, module, field.value, nesting, fieldPath, $fieldGroup); if (i < data.struct_fields.length-1) { $fieldGroup.append(','); } @@ -260,7 +275,7 @@ function renderData(data, nesting, path, $group) { if (data.elems.type == "module_map") { $group.append('{•••}'); } else { - renderData(data.elems, nesting, path, $group); + renderData($tpl, module, data.elems, nesting, path, $group); } $group.append(']'); break; @@ -268,11 +283,11 @@ function renderData(data, nesting, path, $group) { case "map": $group.append('{\n') nesting++; - renderModuleInlineKey(data, nesting, $group); + renderModuleInlineKey($tpl, module, data, nesting, $group); indent(nesting, $group); - renderData(data.map_keys, nesting, path, $group); + renderData($tpl, module, data.map_keys, nesting, path, $group); $group.append(': '); - renderData(data.elems, nesting, path, $group); + renderData($tpl, module, data.elems, nesting, path, $group); $group.append('\n'); nesting--; indent(nesting, $group); @@ -282,18 +297,16 @@ function renderData(data, nesting, path, $group) { case "module": case "module_map": var aTag = '•••'; $group.append('{'+aTag+'}'); break; } - - $renderbox.append($group); } -function renderModuleInlineKey(data, nesting, $group) { +function renderModuleInlineKey($tpl, module, data, nesting, $group) { if (!data.module_inline_key) { return } @@ -305,15 +318,15 @@ function renderModuleInlineKey(data, nesting, $group) { } $group.append('\n'); - appendToFieldDocs(data.module_inline_key, $('#hovercard-inline-key').html()); + appendToFieldDocs($tpl, module, data.module_inline_key, $('#hovercard-inline-key').html()); } -function appendToFieldDocs(cleanFieldPath, fieldDoc) { +function appendToFieldDocs($tpl, module, cleanFieldPath, fieldDoc) { var dt = cleanFieldPath; - if (canTraverse()) { + if (canTraverse(module)) { dt = ''+dt+''; } - $('#field-list-contents').append('