@@ -40,6 +40,14 @@ function escapeAtPartialBlock(partialString) {
40
40
return partial ;
41
41
}
42
42
43
+ function loadHelpers ( helpers ) {
44
+ helpers . forEach ( globPattern => {
45
+ glob . sync ( globPattern ) . forEach ( filePath => {
46
+ require ( path . join ( process . cwd ( ) , filePath ) ) ( Handlebars ) ;
47
+ } ) ;
48
+ } ) ;
49
+ }
50
+
43
51
const engine_handlebars = {
44
52
engine : Handlebars ,
45
53
engineName : 'handlebars' ,
@@ -125,26 +133,32 @@ const engine_handlebars = {
125
133
} ,
126
134
127
135
/**
128
- * Accept a Pattern Lab config object from the core and put it in
129
- * this module's closure scope so we can configure engine behavior .
136
+ * Accept a Pattern Lab config object from the core and use the settings to
137
+ * load helpers .
130
138
*
131
139
* @param {object } config - the global config object from core
132
140
*/
133
141
usePatternLabConfig : function ( config ) {
142
+ let helpers ;
143
+
134
144
try {
135
- let helpers = config . engines . handlebars . helpers ;
145
+ // Look for helpers in the config
146
+ helpers = config . engines . handlebars . helpers ;
136
147
137
148
if ( typeof helpers === 'string' ) {
138
149
helpers = [ helpers ] ;
139
150
}
140
-
141
- helpers . forEach ( globPattern => {
142
- glob . sync ( globPattern ) . forEach ( filePath => {
143
- require ( path . join ( process . cwd ( ) , filePath ) ) ( Handlebars ) ;
144
- } ) ;
145
- } ) ;
146
151
} catch ( error ) {
147
- // No helpers to load
152
+ // Look for helpers in default location
153
+ const configPath = 'patternlab-handlebars-config.js' ;
154
+ if ( fs . existsSync ( path . join ( process . cwd ( ) , configPath ) ) ) {
155
+ helpers = [ configPath ] ;
156
+ }
157
+ }
158
+
159
+ // Load helpers if they were found
160
+ if ( helpers ) {
161
+ loadHelpers ( helpers ) ;
148
162
}
149
163
} ,
150
164
} ;
0 commit comments