smarthbs/ts/smarthbs.helpers.ts
2022-07-24 15:30:19 +02:00

32 lines
938 B
TypeScript

import * as plugins from './smarthbs.plugins.js';
/**
* Helper:
* Allows you to analyze a context
*/
plugins.handlebars.registerHelper('__analyze', (analyzeContext) => {
if (typeof analyzeContext === 'string') {
if (plugins.handlebars.partials[analyzeContext]) {
console.log(`The analyzed partial ${analyzeContext} looks like this`);
console.log(plugins.handlebars.partials[analyzeContext]);
} else {
console.error(`The Partial ${analyzeContext} cannot be found`);
}
return 'analyzed';
}
});
/**
* Helper:
* logs all registered partials to console
*/
plugins.handlebars.registerHelper('__allPartialsLog', (analyzeContext) => {
console.log(plugins.handlebars.partials);
return 'analyzed';
});
plugins.handlebars.registerHelper('__compile', (evaluationString, evaluationContext) => {
let template = plugins.handlebars.compile(evaluationString);
return template(evaluationContext);
});