Add some useful handelbars helpers

This commit is contained in:
2023-07-18 13:24:18 +01:00
parent 1ce6548849
commit d69a89a761
2 changed files with 35 additions and 0 deletions

View File

@@ -1,5 +1,15 @@
{ {
"bundle": { "bundle": {
"js/admin": {
"scripts": [
"uf-tweaks/js/handlebars-helpers.js"
],
"options": {
"sprinkle": {
"onCollision": "merge"
}
}
},
"js/pages/group": { "js/pages/group": {
"scripts": [ "scripts": [
"uf-tweaks/js/pages/group.js", "uf-tweaks/js/pages/group.js",

View File

@@ -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, ' ');
});