« 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/content-function.js
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/content-function.js
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/content-function.js')
-rw-r--r--src/content-function.js57
1 files changed, 25 insertions, 32 deletions
diff --git a/src/content-function.js b/src/content-function.js
index 93bef6b..5cd5392 100644
--- a/src/content-function.js
+++ b/src/content-function.js
@@ -34,9 +34,8 @@ export function expectDependencies({
     throw new Error(`Expected generate function`);
   }
 
-  if (!data) {
-    throw new Error(`Expected data function`);
-  }
+  const hasDataFunction = !!data;
+  const hasRelationsFunction = !!relations;
 
   const fulfilledDependencyKeys = Object.keys(fulfilledDependencies);
 
@@ -63,10 +62,22 @@ export function expectDependencies({
 
   if (empty(missingContentDependencyKeys) && empty(missingExtraDependencyKeys)) {
     wrappedGenerate ??= function(data, relations) {
-      if (relations) {
+      if (hasDataFunction && !data) {
+        throw new Error(`Expected data`);
+      }
+
+      if (hasRelationsFunction && !relations) {
+        throw new Error(`Expected relations`);
+      }
+
+      if (hasDataFunction && hasRelationsFunction) {
         return generate(data, relations, fulfilledDependencies);
-      } else {
+      } else if (hasDataFunction) {
         return generate(data, fulfilledDependencies);
+      } else if (hasRelationsFunction) {
+        return generate(relations, fulfilledDependencies);
+      } else {
+        return generate(fulfilledDependencies);
       }
     };
 
@@ -89,40 +100,22 @@ export function expectDependencies({
 
   wrappedGenerate[contentFunction.identifyingSymbol] = true;
 
-  if (empty(missingContentDependencyKeys)) {
-    /*
-    const dataDependencies = {};
-
-    for (const key of expectedContentDependencyKeys) {
-      const wrappedDependency = function() {
-        throw new Error(`Expected call to this dependency's .data()`);
+  if (hasDataFunction) {
+    if (empty(missingContentDependencyKeys)) {
+      wrappedGenerate.data = data;
+    } else {
+      wrappedGenerate.data = function() {
+        throw new Error(`Dependencies still needed: ${missingContentDependencyKeys.join(', ')}`);
       };
 
-      annotateFunction(wrappedGenerate, {name: fulfilledDependencies[key], description: 'data only'});
-      wrappedDependency.data = fulfilledDependencies[key].data;
-      dataDependencies[key] = wrappedDependency;
+      annotateFunction(wrappedGenerate.data, {name: data, trait: 'unfulfilled'});
     }
-
-    wrappedGenerate.data = function(...args) {
-      return data(...args, dataDependencies);
-    };
-
-    annotateFunction(wrappedGenerate.data, {name: data, trait: 'fulfilled'});
-    */
-
-    wrappedGenerate.data = data;
   }
 
-  if (!wrappedGenerate.data) {
-    wrappedGenerate.data = function() {
-      throw new Error(`Dependencies still needed: ${missingContentDependencyKeys.join(', ')}`);
-    };
-
-    annotateFunction(wrappedGenerate.data, {name: data, trait: 'unfulfilled'});
+  if (hasRelationsFunction) {
+    wrappedGenerate.relations = relations;
   }
 
-  wrappedGenerate.relations = relations;
-
   wrappedGenerate.fulfill ??= function fulfill(dependencies) {
     return expectDependencies({
       data,