« get me outta code hell

data steps: album additional files list - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-03-21 23:28:38 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-03-21 23:34:23 -0300
commitec0dd58271eabd0dd9fa12fbf51f5b46b8ceb014 (patch)
treea10b342ae97f0554eca9179734f27ceecf6e2f90 /src/util
parent7783afa2eeba6eb3b876d325cd83c41fb96b4792 (diff)
data steps: album additional files list
This is WIP but seems to be working! Pretty big test of
the new html.template system, which needed some extension
here.
Diffstat (limited to 'src/util')
-rw-r--r--src/util/html.js20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/util/html.js b/src/util/html.js
index 63d7c1cf..e808eefa 100644
--- a/src/util/html.js
+++ b/src/util/html.js
@@ -411,8 +411,9 @@ export class Template {
 
 export class Slot {
   #defaultTag = new Tag();
+  #handleContent = null;
 
-  constructor(template, slotName, defaultContent) {
+  constructor(template, slotName, defaultContentOrHandleContent) {
     if (!template) {
       throw new Error(`Expected template`);
     }
@@ -423,7 +424,12 @@ export class Slot {
 
     this.template = template;
     this.slotName = slotName;
-    this.defaultContent = defaultContent;
+
+    if (typeof defaultContentOrHandleContent === 'function') {
+      this.#handleContent = defaultContentOrHandleContent;
+    } else {
+      this.defaultContent = defaultContentOrHandleContent;
+    }
   }
 
   set defaultContent(value) {
@@ -447,6 +453,14 @@ export class Slot {
   }
 
   toString() {
-    return this.content.toString();
+    return this.valueOf().toString();
+  }
+
+  valueOf() {
+    if (this.#handleContent) {
+      return this.#handleContent(this.content);
+    } else {
+      return this.content;
+    }
   }
 }