How to use the handlebars/dist/handlebars.js.registerHelper function in handlebars

To help you get started, we’ve selected a few handlebars examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github opfab / operatorfabric-core / ui / main / src / app / modules / cards / services / handlebars.service.ts View on Github external
private registerSplit() {
        Handlebars.registerHelper('split', function (...args: any[]) {
            if(args.length === 3)
                return args[0].split(args[1]);
            if(args.length === 4)
                return args[0].split(args[1])[args[2]];
        });
    }
github opfab / operatorfabric-core / ui / main / src / app / modules / cards / services / handlebars.service.ts View on Github external
private registerI18n() {
        Handlebars.registerHelper('i18n', (...fctArgs) => {
            let args = [],
                options = fctArgs[fctArgs.length - 1];
            for (let i = 0; i < fctArgs.length - 1; i++) {
                args.push(fctArgs[i]);
            }

            let i18nKey: string, i18nParams: string[];
            if (typeof args[0] == 'object') {
                i18nKey = args[0].key;
                i18nParams = args[0].parameters;
            } else {
                i18nKey = "";
                for (let i = 0; i < args.length; i++) {
                    if (i18nKey)
                        i18nKey += "."
                    i18nKey += args[i];
github opfab / operatorfabric-core / ui / main / src / app / modules / cards / services / handlebars.service.ts View on Github external
private registerMath(){
        Handlebars.registerHelper("math", function(lvalue, operator, rvalue, options) {
            let result;
            switch(operator) {
                case "+": result = lvalue + rvalue; break;
                case "-": result = lvalue - rvalue; break;
                case "*": result = lvalue * rvalue; break;
                case "/": result = lvalue / rvalue; break;
                case "%": result = lvalue % rvalue; break;
            }
            return result;
        });
    }
github opfab / operatorfabric-core / ui / main / src / app / modules / cards / services / handlebars.service.ts View on Github external
private registerPreserveSpace() {
        Handlebars.registerHelper("preserveSpace", function (value, options) {
            return value.replace(/ /g, '\u00A0')
        });
    }
}
github opfab / operatorfabric-core / ui / main / src / app / modules / cards / services / handlebars.service.ts View on Github external
private registerNow() {
        const that = this;
        Handlebars.registerHelper('now', function (options) {
            return that.time.currentTime().valueOf();
        })
    }
github opfab / operatorfabric-core / ui / main / src / app / modules / cards / services / handlebars.service.ts View on Github external
private registerSort() {
        Handlebars.registerHelper('sort', function () {
            let args = [];
            for (let index = 0; index < arguments.length - 1; index++) {
                args.push(arguments[index]);
            }
            const context: any | any[] = args[0];
            const sortKey = args[1];
            let arrayToSort: any[];
            let isObject:boolean;
            if (typeof context == 'object') {
                if (context.length !== undefined && context.length !== null) {
                    arrayToSort = context;
                    isObject = (typeof arrayToSort[0] == 'object')
                } else {
                    isObject = true;
                    arrayToSort = [];
                    for (let property in context) {
github opfab / operatorfabric-core / ui / main / src / app / modules / cards / services / handlebars.service.ts View on Github external
private registerJson() {
        Handlebars.registerHelper('json', function (obj) {
            return new Handlebars.SafeString(JSON.stringify(obj))
        });
    }
github opfab / operatorfabric-core / ui / main / src / app / modules / cards / services / handlebars.service.ts View on Github external
private registerArrayAtIndexLength() {
        Handlebars.registerHelper('arrayAtIndexLength', function (value, index, options) {
            return value[index].length;
        });
    }