From 2e2c7c35fb6e56c072e9b094d271bf41a541b45c Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Mon, 19 Dec 2022 18:39:03 -0800 Subject: [PATCH] Add little icons to the toc at the top to easily identify any comments mentioning TODO, BUG, WARNING, FOOTGUN, or DEPRECATED. --- admin/pages/DocsBrowser.svelte | 23 +++++++++++++++++------ commands/codedoc.js | 16 ++++++++++++++++ lib/models.js | 6 ++++-- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/admin/pages/DocsBrowser.svelte b/admin/pages/DocsBrowser.svelte index 58f6f36..d52a426 100644 --- a/admin/pages/DocsBrowser.svelte +++ b/admin/pages/DocsBrowser.svelte @@ -11,6 +11,14 @@ let url; export let params; + const caps_to_icon = { + "BUG": "bug", + "TODO": "clipboard-check", + "WARNING": "alert-triangle", + "FOOTGUN": "bomb", + "DEPRECATED": "axe" + } + const jump = (id) => { let node = document.getElementById(id); if(node) node.scrollIntoView(); @@ -144,7 +152,7 @@ toc { display: grid; - grid-template-columns: repeat(6, 1fr); + grid-template-columns: repeat(5, 1fr); } toc span { @@ -177,15 +185,18 @@ {#each docs_data.exports as exp} - {#if exp.isa == "class"} - jump(exp.slug) }>{ exp.name } + jump(exp.slug) }>{ exp.name } + {#each exp.caps as cap_word}{/each} + + {#if exp.isa == "class"} {#each exp.methods as member} - jump(member.slug) }>.{ member.name } + jump(member.slug) }>.{ member.name } + {#each member.caps as cap_word}{/each} + {/each} - {:else} - jump(exp.slug) }>{ exp.name } {/if} + {/each} diff --git a/commands/codedoc.js b/commands/codedoc.js index 05a1c5e..83f5166 100644 --- a/commands/codedoc.js +++ b/commands/codedoc.js @@ -27,6 +27,7 @@ export const required = [ ] const RENDERER = create_renderer(); +const CAPS_WORDS = ["BUG", "TODO", "WARNING", "FOOTGUN", "DEPRECATED"]; const slug = (instring) => slugify(instring, { lower: true, strict: true, trim: true}); @@ -93,6 +94,8 @@ class ParseWalker { comment: this.find_comment(meth_node.loc.start.line), } + this.has_CAPS(new_method); + new_method.code = this.slice_code(new_method.range); new_class.methods.push(new_method); @@ -127,11 +130,24 @@ class ParseWalker { return result; } + /* + Used to add information when something is mentioned in the + comment like BUG, TODO, etc. + */ + has_CAPS(exp) { + if(exp.comment) { + exp.caps = CAPS_WORDS.filter(phrase => exp.comment.includes(phrase)); + } else { + exp.caps = []; + } + } + 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); + this.has_CAPS(exp); exp.code = this.slice_code(exp.range); this.exported.push(exp); } diff --git a/lib/models.js b/lib/models.js index 370820e..004a941 100644 --- a/lib/models.js +++ b/lib/models.js @@ -100,7 +100,10 @@ export class User extends Model.from_table('user') { /* Performs all the cleanup and checks needed for a registration. It will ensure that the password and password_repeat are the same, lowercase the email, - clean out unwanted attrbiutes with User.clean, generate required keys, etc. + clean out unwanted attributes with `User.clean`, generate required keys, etc. + + - BUG: Test out bugs feature. + - TODO: Test out todo feature. + `attr Object` - attributes usually from a web form + ___return___ `Object`, `undefined` or the new user on success @@ -124,7 +127,6 @@ export class User extends Model.from_table('user') { log.error("User exists", user.email); return undefined; } else { - // BUG: accepting unfiltered user input user.password = User.encrypt_password(user.password); user.unsubkey = User.random_hex(UNSUB_CODE_SIZE);