File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
packages/engine-handlebars Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 25
25
const fs = require ( 'fs-extra' ) ;
26
26
const path = require ( 'path' ) ;
27
27
const Handlebars = require ( 'handlebars' ) ;
28
+ const glob = require ( 'glob' ) ;
28
29
29
30
// regexes, stored here so they're only compiled once
30
31
const findPartialsRE = / { { # ? > \s * ( [ \w -\/ . ] + ) (?: .| \s + ) * ?} } / g;
@@ -122,6 +123,30 @@ const engine_handlebars = {
122
123
this . spawnFile ( config , '_00-head.hbs' ) ;
123
124
this . spawnFile ( config , '_01-foot.hbs' ) ;
124
125
} ,
126
+
127
+ /**
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.
130
+ *
131
+ * @param {object } config - the global config object from core
132
+ */
133
+ usePatternLabConfig : function ( config ) {
134
+ try {
135
+ let helpers = config . engines . handlebars . helpers ;
136
+
137
+ if ( typeof helpers === 'string' ) {
138
+ helpers = [ helpers ] ;
139
+ }
140
+
141
+ helpers . forEach ( globPattern => {
142
+ glob . sync ( globPattern ) . forEach ( filePath => {
143
+ require ( path . join ( process . cwd ( ) , filePath ) ) ( Handlebars ) ;
144
+ } ) ;
145
+ } ) ;
146
+ } catch ( error ) {
147
+ // No helpers to load
148
+ }
149
+ } ,
125
150
} ;
126
151
127
152
module . exports = engine_handlebars ;
Original file line number Diff line number Diff line change 5
5
"main" : " lib/engine_handlebars.js" ,
6
6
"dependencies" : {
7
7
"fs-extra" : " 0.30.0" ,
8
- "handlebars" : " 4.0.5"
8
+ "handlebars" : " 4.0.5" ,
9
+ "glob" : " 7.0.0"
9
10
},
10
11
"keywords" : [
11
12
" Pattern Lab" ,
You can’t perform that action at this time.
0 commit comments