« get me outta code hell

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:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/html.js30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/util/html.js b/src/util/html.js
index 26dd6495..d7d03732 100644
--- a/src/util/html.js
+++ b/src/util/html.js
@@ -494,6 +494,10 @@ export class Attributes {
   }
 }
 
+export function resolve(tagOrTemplate) {
+  return Template.resolve(tagOrTemplate);
+}
+
 export function template(description) {
   return new Template(description);
 }
@@ -785,13 +789,7 @@ export class Template {
       slots[slotName] = this.getSlotValue(slotName);
     }
 
-    // Get outta here with that recursive Template bollocks!
-    const content = this.description.content(slots);
-    if (content instanceof Template) {
-      return content.content;
-    } else {
-      return content;
-    }
+    return this.description.content(slots);
   }
 
   set description(_value) {
@@ -806,6 +804,24 @@ export class Template {
     return this.content.toString();
   }
 
+  static resolve(tagOrTemplate) {
+    // Flattens contents of a template, recursively "resolving" until a
+    // non-template is ready (or just returns a provided non-template
+    // argument as-is).
+
+    if (!(tagOrTemplate instanceof Template)) {
+      return tagOrTemplate;
+    }
+
+    let {content} = tagOrTemplate;
+
+    while (content instanceof Template) {
+      content = content.content;
+    }
+
+    return content;
+  }
+
   [inspect.custom]() {
     const {annotation} = this.description;
     if (annotation) {