From 372be19301ca8ce5eb9c54fd6289a0dfa2aaea37 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Mon, 19 Dec 2022 16:13:51 -0800 Subject: [PATCH] Make it possible to jump to sections you need and back to the top. --- admin/pages/DocsBrowser.svelte | 64 ++++++++++++++++++++++++++-------- commands/codedoc.js | 6 ++++ 2 files changed, 55 insertions(+), 15 deletions(-) diff --git a/admin/pages/DocsBrowser.svelte b/admin/pages/DocsBrowser.svelte index ab9c321..58f6f36 100644 --- a/admin/pages/DocsBrowser.svelte +++ b/admin/pages/DocsBrowser.svelte @@ -1,11 +1,8 @@ @@ -151,19 +167,34 @@ + {#if docs_data}

{ url }

{#if docs_data.comment} {@html docs_data.comment} {/if} -
+ + + {#each docs_data.exports as exp} + {#if exp.isa == "class"} + jump(exp.slug) }>{ exp.name } + + {#each exp.methods as member} + jump(member.slug) }>.{ member.name } + {/each} + {:else} + jump(exp.slug) }>{ exp.name } + {/if} + {/each} + + {#each docs_data.exports as exp} {#if exp.isa === "class"} -

class { exp.name }

+

jump_top() } id={ exp.slug }>class { exp.name }

@@ -176,7 +207,8 @@ {#each exp.methods as member} -

.{member.name}{ type_to_syntax[member.isa] || "" }

+

jump(exp.slug) }>.{member.name}{ type_to_syntax[member.isa] || "" } +

{docs_data.source}:{ member.line_start } { member.isa } of { exp.name } @@ -198,15 +230,17 @@ {:else} -

{exp.name}{ type_to_syntax[exp.isa] || "" }

+

jump_top() } + id={ exp.slug }>{exp.name}{ type_to_syntax[exp.isa] || "" } +

{docs_data.source}:{ exp.line_start } { exp.isa } {#if exp.static}static{/if} {#if exp.async}async{/if} {#if exp.generator}generator{/if} - -
+
+
{#if exp.comment} diff --git a/commands/codedoc.js b/commands/codedoc.js index f0807e6..05a1c5e 100644 --- a/commands/codedoc.js +++ b/commands/codedoc.js @@ -5,6 +5,7 @@ import logging from '../lib/logging.js'; import { mkdir, mkdir_to, glob } from "../lib/builderator.js"; import { create_renderer } from "../lib/docgen.js"; import path from "path"; +import slugify from "slugify"; import template from "lodash/template.js"; import * as acorn from "acorn"; import * as acorn_walk from "acorn-walk"; @@ -27,6 +28,8 @@ export const required = [ const RENDERER = create_renderer(); +const slug = (instring) => slugify(instring, { lower: true, strict: true, trim: true}); + /* Strips 1 leading space from the comments, or the \s\* combinations in traditional documentation comments. @@ -63,6 +66,7 @@ class ParseWalker { handle_class(root) { const new_class = { isa: "class", + slug: slug(root.declaration.id.name), name: root.declaration.id.name, line_start: root.loc.start.line, methods: [], @@ -81,6 +85,7 @@ class ParseWalker { static: meth_node.static, async: meth_node.value.async, generator: meth_node.value.generator, + slug: slug(`${new_class.name}-${meth_node.key.name}`), name: meth_node.key.name, line_start: meth_node.loc.start.line, range: [meth_node.start, meth_node.value.body.start], @@ -124,6 +129,7 @@ class ParseWalker { add_export(id, exp) { exp.name = id.name; + exp.slug = exp.slug ? exp.slug : slug(id.name); exp.line_start = id.loc.start.line; exp.comment = this.find_comment(exp.line_start); exp.code = this.slice_code(exp.range);