« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/write/bind-utilities.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/write/bind-utilities.js')
-rw-r--r--src/write/bind-utilities.js73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/write/bind-utilities.js b/src/write/bind-utilities.js
new file mode 100644
index 0000000..3d4ecc7
--- /dev/null
+++ b/src/write/bind-utilities.js
@@ -0,0 +1,73 @@
+// Ties lots and lots of functions together in a convenient package accessible
+// to page write functions. This is kept in a separate file from other write
+// areas to keep imports neat and isolated.
+
+import chroma from 'chroma-js';
+
+import {getColors} from '#colors';
+import {bindFind} from '#find';
+import * as html from '#html';
+import {bindOpts} from '#sugar';
+import {thumb} from '#urls';
+
+import {
+  checkIfImagePathHasCachedThumbnails,
+  getDimensionsOfImagePath,
+  getThumbnailEqualOrSmaller,
+  getThumbnailsAvailableForDimensions,
+} from '#thumbs';
+
+export function bindUtilities({
+  absoluteTo,
+  cachebust,
+  defaultLanguage,
+  getSizeOfAdditionalFile,
+  getSizeOfImagePath,
+  language,
+  languages,
+  missingImagePaths,
+  pagePath,
+  thumbsCache,
+  to,
+  urls,
+  wikiData,
+}) {
+  const bound = {};
+
+  Object.assign(bound, {
+    absoluteTo,
+    cachebust,
+    defaultLanguage,
+    getSizeOfAdditionalFile,
+    getSizeOfImagePath,
+    getThumbnailsAvailableForDimensions,
+    html,
+    language,
+    languages,
+    missingImagePaths,
+    pagePath,
+    thumb,
+    to,
+    urls,
+    wikiData,
+    wikiInfo: wikiData.wikiInfo,
+  });
+
+  bound.getColors = bindOpts(getColors, {chroma});
+
+  bound.find = bindFind(wikiData, {mode: 'warn'});
+
+  bound.checkIfImagePathHasCachedThumbnails =
+    (imagePath) =>
+      checkIfImagePathHasCachedThumbnails(imagePath, thumbsCache);
+
+  bound.getDimensionsOfImagePath =
+    (imagePath) =>
+      getDimensionsOfImagePath(imagePath, thumbsCache);
+
+  bound.getThumbnailEqualOrSmaller =
+    (preferred, imagePath) =>
+      getThumbnailEqualOrSmaller(preferred, imagePath, thumbsCache);
+
+  return bound;
+}