From d69a89a761db95b7c9f7b961bdd129de89a9f2d7 Mon Sep 17 00:00:00 2001 From: Craig Williams Date: Tue, 18 Jul 2023 13:24:18 +0100 Subject: [PATCH] Add some useful handelbars helpers --- asset-bundles.json | 10 +++++++++ assets/uf-tweaks/js/handlebars-helpers.js | 25 +++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 assets/uf-tweaks/js/handlebars-helpers.js diff --git a/asset-bundles.json b/asset-bundles.json index 012655d..43af0cf 100644 --- a/asset-bundles.json +++ b/asset-bundles.json @@ -1,5 +1,15 @@ { "bundle": { + "js/admin": { + "scripts": [ + "uf-tweaks/js/handlebars-helpers.js" + ], + "options": { + "sprinkle": { + "onCollision": "merge" + } + } + }, "js/pages/group": { "scripts": [ "uf-tweaks/js/pages/group.js", diff --git a/assets/uf-tweaks/js/handlebars-helpers.js b/assets/uf-tweaks/js/handlebars-helpers.js new file mode 100644 index 0000000..7cf9658 --- /dev/null +++ b/assets/uf-tweaks/js/handlebars-helpers.js @@ -0,0 +1,25 @@ +/** + * This file contains extra helper functions for Handlebars.js. + * + * @see http://handlebarsjs.com/#helpers + */ + +function ucwords (str) { + return (str + '').replace(/^([a-z])|\s+([a-z])/g, function ($1) { + return $1.toUpperCase(); + }); +} + +/** +* Uppercase words +*/ +Handlebars.registerHelper('ucwords', function (str) { + return ucwords(str); +}); + +/** +* Split snake case into words +*/ +Handlebars.registerHelper('splitSnakeCase', function (str) { + return str.replace(/_/g, ' '); +});