Skip to content

Commit

Permalink
adding in swap for helpers from registry
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredwray committed Nov 2, 2024
1 parent 6284b71 commit 2423df9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/helper-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,13 @@ export class HelperRegistry {
handlebars.registerHelper(helper.name, helper.fn);
}
}

public swapHelpers(handlebars: any) {
for (const helper of this._helpers) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
handlebars.unregisterHelper(helper.name);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
handlebars.registerHelper(helper.name, helper.fn);
}
}
}
2 changes: 1 addition & 1 deletion src/helpers/date.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {type Helper} from '../helper-registry.js';

const year = () => new Date().getFullYear();
const year = () => new Date().getFullYear().toString();

export const helpers: Helper[] = [
{
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ export const helpers = helpersLib;
* @returns {Promise<Handlebars>}
*/
export async function createHandlebars() {
const registry = new HelperRegistry();
const handlebars = HandlebarsLib.create();
const helpersFunction = await import('../helpers/helpers.js');
helpersFunction.default({ handlebars: handlebars });
registry.swapHelpers(handlebars);
return handlebars;
}

Expand Down

0 comments on commit 2423df9

Please sign in to comment.