File tree Expand file tree Collapse file tree 5 files changed +40
-11
lines changed
Expand file tree Collapse file tree 5 files changed +40
-11
lines changed Original file line number Diff line number Diff line change @@ -12,9 +12,11 @@ npm install handlebars-helpers-ctrf
1212
1313``` javascript
1414import Handlebars from ' handlebars'
15- import { registry } from ' handlebars-helpers-ctrf' ;
15+ import { loadHelpers } from ' handlebars-helpers-ctrf' ;
16+
1617// Register all helpers with Handlebars
17- registry .loadHandlebars (Handlebars);
18+ loadHelpers (Handlebars);
19+
1820
1921// Now you can use the helpers in your templates
2022const template = Handlebars .compile (' {{append "test" ".html"}}' );
Original file line number Diff line number Diff line change 11{
22 "name" : " handlebars-helpers-ctrf" ,
3- "version" : " 0.0.4-next.7 " ,
4- "description" : " " ,
3+ "version" : " 0.0.4-next.8 " ,
4+ "description" : " A collection of Handlebars helpers for working with Common Test Report Format " ,
55 "type" : " module" ,
66 "main" : " dist/index.js" ,
77 "types" : " dist/index.d.ts" ,
3131 " types/" ,
3232 " README.md"
3333 ],
34- "repository" : {
35- "type" : " git" ,
36- "url" : " https://github.com/ctrf-io/handlebars-helpers-ctrf"
37- },
34+ "repository" : " github:ctrf-io/handlebars-helpers-ctrf" ,
3835 "homepage" : " https://ctrf.io" ,
3936 "author" : " Matthew Thomas" ,
4037 "license" : " MIT" ,
Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ export interface HandlebarsInstance {
88 helpers : Record < string , unknown > ;
99}
1010
11+ export type Handlebars = HandlebarsInstance ;
12+
1113/**
1214 * Describes a filter for selecting helpers by name or category.
1315 */
@@ -93,7 +95,25 @@ export class HelperRegistry {
9395 * Loads all registered helpers into a Handlebars instance.
9496 * @param handlebars - The Handlebars instance.
9597 */
96- public loadHandlebars ( handlebars : HandlebarsInstance ) {
98+ public loadHandlebars (
99+ handlebars :
100+ | HandlebarsInstance
101+ | {
102+ registerHelper : (
103+ name : string ,
104+ fn : ( ...args : unknown [ ] ) => unknown ,
105+ ) => void ;
106+ } ,
107+ ) {
108+ // Type guard to ensure handlebars has the required methods
109+ if ( typeof handlebars !== "object" || handlebars === null ) {
110+ throw new Error ( "Handlebars instance must be an object" ) ;
111+ }
112+
113+ if ( typeof handlebars . registerHelper !== "function" ) {
114+ throw new Error ( "Handlebars instance must have a registerHelper method" ) ;
115+ }
116+
97117 for ( const helper of this . _helpers ) {
98118 handlebars . registerHelper ( helper . name , helper . fn ) ;
99119 }
Original file line number Diff line number Diff line change @@ -43,6 +43,16 @@ registry.registerHelpers([
4343
4444registry . loadHandlebars ( Handlebars ) ;
4545
46+ /**
47+ * load helpers into Handlebars instance.
48+ * @param handlebarsInstance - The Handlebars instance to load helpers into
49+ */
50+ export function loadHelpers ( handlebarsInstance : {
51+ registerHelper : ( name : string , fn : ( ...args : unknown [ ] ) => unknown ) => void ;
52+ } ) {
53+ registry . loadHandlebars ( handlebarsInstance ) ;
54+ }
55+
4656/**
4757 * Exports the default helper registry and the HelperRegistry class.
4858 */
You can’t perform that action at this time.
0 commit comments