update dependencies and devDependencies, address lint issues
[squeep-indie-auther] / src / template / template-helper.js
index a33c8b004a35677925ba3e1c60b0ac8034b212c4..4c0ad9d3ec04b940765d0620ee84ed44ef30bf89 100644 (file)
@@ -5,8 +5,8 @@ const { TemplateHelper } = require('@squeep/html-template-helper');
 
 /**
  * Escape a string to be suitable as a CSS name.
- * @param {String} unsafeName 
- * @returns {String}
+ * @param {string} unsafeName unsafe name
+ * @returns {string} escaped name
  */
 function escapeCSS(unsafeName) {
   return unsafeName.replace(/([^0-9a-zA-Z-])/g, '\\$1');
@@ -18,9 +18,9 @@ function escapeCSS(unsafeName) {
  * return the comparison between the two, for sorting.
  * Scopes are sorted such that they are grouped by application, then name.
  * Empty applications are sorted ahead of extant applications.
- * @param {Array} a
- * @param {Array} b
- * @returns {Number}
+ * @param {[string, object]} a [scopeName, scopeDetails]
+ * @param {[string, object]} b [scopeName, scopeDetails]
+ * @returns {number} comparison
  */
 function scopeCompare([aScope, aDetails], [bScope, bDetails]) {
   const { application: aApp } = aDetails;
@@ -47,7 +47,34 @@ function scopeCompare([aScope, aDetails], [bScope, bDetails]) {
 }
 
 
+/**
+ * Populate common navLinks for page templates.
+ * @param {number} pagePathLevel depth from root
+ * @param {object} ctx context
+ * @param {object} options options
+ */
+function navLinks(pagePathLevel, ctx, options) {
+  if (!options.navLinks) {
+    options.navLinks = [];
+  }
+  const rootPath = '../'.repeat(pagePathLevel);
+
+  if (options.pageIdentifier !== 'admin') {
+    options.navLinks.push({
+      text: 'Admin',
+      href: `${rootPath}admin/`,
+    });
+  }
+  if (options.pageIdentifier !== 'ticketProffer') {
+    options.navLinks.push({
+      text: 'Ticket',
+      href: `${rootPath}admin/ticket`,
+    });
+  }
+}
+
 module.exports = Object.assign(Object.create(TemplateHelper), {
   escapeCSS,
   scopeCompare,
+  navLinks,
 });
\ No newline at end of file