initialize() { super.initialize(); const namedAnchors = this.application.options.getValue('namedAnchors'); const hideBreadcrumbs = this.application.options.getValue('hideBreadcrumbs'); const hideIndexes = this.application.options.getValue('hideIndexes'); const hideSourceFiles = this.application.options.getValue('hideSources'); MarkdownTheme.handlebars.registerHelper('ifNamedAnchors', function(options) { return namedAnchors ? options.fn(this) : options.inverse(this); }); MarkdownTheme.handlebars.registerHelper('ifBreadcrumbs', function(options) { return hideBreadcrumbs ? options.inverse(this) : options.fn(this); }); MarkdownTheme.handlebars.registerHelper('ifIndexes', function(options) { return hideIndexes ? options.inverse(this) : options.fn(this); }); MarkdownTheme.handlebars.registerHelper('ifSources', function(options) { return hideSourceFiles ? options.inverse(this) : options.fn(this); }); }
initialize() { super.initialize(); this.includes = this.application.options.getValue('includes'); this.mediaDirectory = this.application.options.getValue('media'); this.listInvalidSymbolLinks = this.application.options.getValue('listInvalidSymbolLinks'); this.listenTo( this.owner, { [RendererEvent.END]: this.onEndRenderer, }, undefined, 100, ); const component = this; MarkdownTheme.handlebars.registerHelper('comment', function(this: string) { return component.parseComments(this); }); MarkdownTheme.handlebars.registerHelper('breadcrumbs', function(this: PageEvent) { return component.breadcrumb(this.model, this.project, []); }); MarkdownTheme.handlebars.registerHelper('relativeURL', (url: string) => { return url ? this.getRelativeUrl(url) : url; }); }
/** * Checks if a collection of responses contains no success responses. */ Handlebars.registerHelper('ifNoSuccessResponses', (responses, options) => { const codes = responses ? Object.keys(responses) : []; if (codes.find(code => Number(code) >= 200 && Number(code) < 300)) return options.inverse(this); return options.fn(this); });
/** * Checks if a string ends with a provided value. */ Handlebars.registerHelper('endsWith', (lvalue, rvalue, options) => { if (arguments.length < 3) throw new Error('Handlebars Helper equal needs 2 parameters'); if (lvalue.lastIndexOf(rvalue) !== lvalue.length-1 || lvalue.length-1 < 0) { return options.inverse(this); } return options.fn(this); });
handlebars.registerHelper('pokemonName', (value) => { if (!+value) return '' const monster = Object.values(monsters).find((m) => m.id === +value) if (!monster) return '' return translator.translate(monster.name) })
Handlebars.registerHelper('dateFormat', function(context, format) { 'use strict'; if (format === 'fromNow') { return moment(context).fromNow(); } else { return moment(context).format(format); } });
/** * Converts a multi-line string to a single line. */ Handlebars.registerHelper('inline', (str) => { return str ? str.replace(/\n/g, '') : ''; });
/** * Checks if a string matches a RegExp. */ Handlebars.registerHelper('match', (lvalue, rvalue, options) => { if (arguments.length < 3) throw new Error('Handlebars Helper match needs 2 parameters'); if (!lvalue.match(rvalue)) { return options.inverse(this); } return options.fn(this); });
/** * Capitalizes a string. */ Handlebars.registerHelper('capitalize', (str) => { return _.capitalize(str); });
/** * Checks if a method is a valid HTTP method. */ Handlebars.registerHelper('validMethod', (method, options) => { const authorized_methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'COPY', 'HEAD', 'OPTIONS', 'LINK', 'UNLIK', 'PURGE', 'LOCK', 'UNLOCK', 'PROPFIND']; if (arguments.length < 3) throw new Error('Handlebars Helper validMethod needs 1 parameter'); if (authorized_methods.indexOf(method.toUpperCase()) === -1) { return options.inverse(this); } return options.fn(this); });
/** * Converts a string to its camel-cased version. */ Handlebars.registerHelper('camelCase', (str) => { return _.camelCase(str); });
hb.registerHelper('for', function(from, to, incr, options) { var accum = ''; for(var i = from; i < to; i += incr) accum += options.fn(i); return accum; });
/** * Compares two values. */ Handlebars.registerHelper('equal', (lvalue, rvalue, options) => { if (arguments.length < 3) throw new Error('Handlebars Helper equal needs 2 parameters'); if (lvalue!=rvalue) { return options.inverse(this); } return options.fn(this); });
handlebars.registerHelper('statusIcon', function (str) { switch (str) { case 'pass': return ':heavy_check_mark:' case 'fail': return ':x:' case 'error': return ':heavy_exclamation_mark:' default: return `Unknown Status given: ${str}` } })
hb.registerHelper('configIsTrue', function(key, value) { if(config[key] == value) { return true; } else { return false; } });