summaryrefslogtreecommitdiff
path: root/app.js
diff options
context:
space:
mode:
authorlowercasename <raphaelkabo@gmail.com>2019-09-14 10:08:09 +0100
committerlowercasename <raphaelkabo@gmail.com>2019-09-14 10:08:09 +0100
commit9d3da3563ce13d54673cfa3468911caeb4836741 (patch)
treeb5a751b303552d68e1e406ea4ae110892f235153 /app.js
parent3b15d58ef86c041b44523462460fb3d70352ab1b (diff)
Functionality to limit number of attendees
Diffstat (limited to 'app.js')
-rwxr-xr-xapp.js24
1 files changed, 22 insertions, 2 deletions
diff --git a/app.js b/app.js
index 9a82abe..a8d2889 100755
--- a/app.js
+++ b/app.js
@@ -16,8 +16,28 @@ const app = express();
// View engine //
-
-app.engine('handlebars', hbs({defaultLayout: 'main'}));
+hbsInstance = hbs.create({
+ defaultLayout: 'main',
+ partialsDir: ['views/partials/'],
+ helpers: {
+ plural: function(number, text) {
+ var singular = number === 1;
+ // If no text parameter was given, just return a conditional s.
+ if (typeof text !== 'string') return singular ? '' : 's';
+ // Split with regex into group1/group2 or group1(group3)
+ var match = text.match(/^([^()\/]+)(?:\/(.+))?(?:\((\w+)\))?/);
+ // If no match, just append a conditional s.
+ if (!match) return text + (singular ? '' : 's');
+ // We have a good match, so fire away
+ return singular && match[1] // Singular case
+ ||
+ match[2] // Plural case: 'bagel/bagels' --> bagels
+ ||
+ match[1] + (match[3] || 's'); // Plural case: 'bagel(s)' or 'bagel' --> bagels
+ }
+ }
+});
+app.engine('handlebars', hbsInstance.engine);
app.set('view engine', 'handlebars');
// Static files //