« get me outta code hell

html: inspect.custom() annotations for html classes - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-06-12 18:15:05 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-06-12 18:15:59 -0300
commitea15c99d9ffa7ca59e9a44cdcccc492cca5a4ac0 (patch)
tree5d62e2a75f71cafe5a6c59dd7b81e5c915f09328 /src
parent85b797fe83af8206d81286770551021bdc606cce (diff)
html: inspect.custom() annotations for html classes
Diffstat (limited to 'src')
-rw-r--r--src/util/html.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/util/html.js b/src/util/html.js
index b75820e..f245656 100644
--- a/src/util/html.js
+++ b/src/util/html.js
@@ -1,5 +1,7 @@
 // Some really simple functions for formatting HTML content.
 
+import {inspect} from 'util';
+
 import * as commonValidators from '../data/things/validators.js';
 import {empty} from './sugar.js';
 
@@ -396,6 +398,22 @@ export class Tag {
       .filter(Boolean)
       .join(joiner);
   }
+
+  [inspect.custom]() {
+    if (this.tagName) {
+      if (empty(this.content)) {
+        return `Tag <${this.tagName} />`;
+      } else {
+        return `Tag <${this.tagName}> (${this.content.length} items)`;
+      }
+    } else {
+      if (empty(this.content)) {
+        return `Tag (no name)`;
+      } else {
+        return `Tag (no name, ${this.content.length} items)`;
+      }
+    }
+  }
 }
 
 export class Attributes {
@@ -781,6 +799,15 @@ export class Template {
   toString() {
     return this.content.toString();
   }
+
+  [inspect.custom]() {
+    const {annotation} = this.description;
+    if (annotation) {
+      return `Template "${annotation}"`;
+    } else {
+      return `Template (no annotation)`;
+    }
+  }
 }
 
 export function stationery(description) {
@@ -801,4 +828,13 @@ export class Stationery {
   template() {
     return new Template(this.#templateDescription);
   }
+
+  [inspect.custom]() {
+    const {annotation} = this.#templateDescription;
+    if (annotation) {
+      return `Stationery "${annotation}"`;
+    } else {
+      return `Stationery (no annotation)`;
+    }
+  }
 }