« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/thing
diff options
context:
space:
mode:
Diffstat (limited to 'src/thing')
-rw-r--r--src/thing/static-page.js2
-rw-r--r--src/thing/validators.js9
-rw-r--r--src/thing/wiki-info.js90
3 files changed, 100 insertions, 1 deletions
diff --git a/src/thing/static-page.js b/src/thing/static-page.js
index 18e9d142..e2b51507 100644
--- a/src/thing/static-page.js
+++ b/src/thing/static-page.js
@@ -15,7 +15,7 @@ export default class StaticPage extends Thing {
 
         name: {
             flags: {update: true, expose: true},
-            update: {validate: isName}
+            update: {validate: isName, default: 'Unnamed Static Page'}
         },
 
         nameShort: {
diff --git a/src/thing/validators.js b/src/thing/validators.js
index 49463473..1bc7fd72 100644
--- a/src/thing/validators.js
+++ b/src/thing/validators.js
@@ -241,6 +241,15 @@ export function isFileExtension(string) {
     return true;
 }
 
+export function isLanguageCode(string) {
+    // TODO: This is a stub function because really we don't need a detailed
+    // is-language-code parser right now.
+
+    isString(string);
+
+    return true;
+}
+
 export function isName(name) {
     return isString(name);
 }
diff --git a/src/thing/wiki-info.js b/src/thing/wiki-info.js
new file mode 100644
index 00000000..b805bf76
--- /dev/null
+++ b/src/thing/wiki-info.js
@@ -0,0 +1,90 @@
+import CacheableObject from './cacheable-object.js';
+
+import {
+    isBoolean,
+    isColor,
+    isLanguageCode,
+    isName,
+    isString,
+    isURL,
+} from './validators.js';
+
+export default class WikiInfo extends CacheableObject {
+    static propertyDescriptors = {
+        // Update & expose
+
+        name: {
+            flags: {update: true, expose: true},
+            update: {validate: isName, default: 'Unnamed Wiki'}
+        },
+
+        // Displayed in nav bar.
+        shortName: {
+            flags: {update: true, expose: true},
+            update: {validate: isName},
+
+            expose: {
+                dependencies: ['name'],
+                transform: (value, { name }) => value ?? name
+            }
+        },
+
+        color: {
+            flags: {update: true, expose: true},
+            update: {validate: isColor}
+        },
+
+        // One-line description used for <meta rel="description"> tag.
+        description: {
+            flags: {update: true, expose: true},
+            update: {validate: isString}
+        },
+
+        footerContent: {
+            flags: {update: true, expose: true},
+            update: {validate: isString}
+        },
+
+        defaultLanguage: {
+            flags: {update: true, expose: true},
+            update: {validate: isLanguageCode}
+        },
+
+        canonicalBase: {
+            flags: {update: true, expose: true},
+            update: {validate: isURL}
+        },
+
+        // Feature toggles
+
+        enableArtistAvatars: {
+            flags: {update: true, expose: true},
+            update: {validate: isBoolean, default: false}
+        },
+
+        enableFlashesAndGames: {
+            flags: {update: true, expose: true},
+            update: {validate: isBoolean, default: false}
+        },
+
+        enableListings: {
+            flags: {update: true, expose: true},
+            update: {validate: isBoolean, default: false}
+        },
+
+        enableNews: {
+            flags: {update: true, expose: true},
+            update: {validate: isBoolean, default: false}
+        },
+
+        enableArtTagUI: {
+            flags: {update: true, expose: true},
+            update: {validate: isBoolean, default: false}
+        },
+
+        enableGroupUI: {
+            flags: {update: true, expose: true},
+            update: {validate: isBoolean, default: false}
+        },
+    };
+}