Files
smarthbs/ts/smarthbs.helpers.ts
T

35 lines
1.0 KiB
TypeScript
Raw Normal View History

2022-07-24 15:30:19 +02:00
import * as plugins from './smarthbs.plugins.js';
2017-03-19 17:14:28 +01:00
2017-05-31 23:59:39 +02:00
/**
* Helper:
* Allows you to analyze a context
*/
plugins.handlebars.registerHelper('__analyze', (analyzeContext: unknown) => {
2017-05-10 16:55:25 +02:00
if (typeof analyzeContext === 'string') {
if (plugins.handlebars.partials[analyzeContext]) {
console.log(`The analyzed partial ${analyzeContext} looks like this`);
console.log(plugins.handlebars.partials[analyzeContext]);
2017-05-10 16:55:25 +02:00
} else {
console.error(`The Partial ${analyzeContext} cannot be found`);
2017-05-10 16:55:25 +02:00
}
return 'analyzed';
2017-05-10 16:55:25 +02:00
}
});
2017-05-10 16:55:25 +02:00
2017-05-31 23:59:39 +02:00
/**
* Helper:
* logs all registered partials to console
*/
plugins.handlebars.registerHelper('__allPartialsLog', (_analyzeContext: unknown) => {
console.log(plugins.handlebars.partials);
return 'analyzed';
});
2017-05-10 16:55:25 +02:00
plugins.handlebars.registerHelper('__compile', (evaluationString: unknown, evaluationContext: unknown) => {
if (typeof evaluationString !== 'string') {
return '';
}
const template = plugins.handlebars.compile(evaluationString);
return template(evaluationContext);
});