@@ -40,6 +40,14 @@ function escapeAtPartialBlock(partialString) {
4040 return partial ;
4141}
4242
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+
4351const engine_handlebars = {
4452 engine : Handlebars ,
4553 engineName : 'handlebars' ,
@@ -125,26 +133,32 @@ const engine_handlebars = {
125133 } ,
126134
127135 /**
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 .
130138 *
131139 * @param {object } config - the global config object from core
132140 */
133141 usePatternLabConfig : function ( config ) {
142+ let helpers ;
143+
134144 try {
135- let helpers = config . engines . handlebars . helpers ;
145+ // Look for helpers in the config
146+ helpers = config . engines . handlebars . helpers ;
136147
137148 if ( typeof helpers === 'string' ) {
138149 helpers = [ helpers ] ;
139150 }
140-
141- helpers . forEach ( globPattern => {
142- glob . sync ( globPattern ) . forEach ( filePath => {
143- require ( path . join ( process . cwd ( ) , filePath ) ) ( Handlebars ) ;
144- } ) ;
145- } ) ;
146151 } 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 ) ;
148162 }
149163 } ,
150164} ;
0 commit comments