@@ -211,6 +211,36 @@ class PatternLab {
211
211
}
212
212
213
213
214
+ writePatternFiles ( headHTML , pattern , footerHTML ) {
215
+ const nullFormatter = str => str ;
216
+ const defaultFormatter = codeString => cleanHtml ( codeString , { indent_size : 2 } ) ;
217
+ const makePath = type => path . join ( this . config . paths . public . patterns , pattern . getPatternLink ( this , type ) ) ;
218
+ const patternPage = headHTML + pattern . patternPartialCode + footerHTML ;
219
+ const eng = pattern . engine ;
220
+
221
+ //beautify the output if configured to do so
222
+ const formatters = this . config . cleanOutputHtml ? {
223
+ rendered : eng . renderedCodeFormatter || defaultFormatter ,
224
+ rawTemplate : eng . rawTemplateCodeFormatter || defaultFormatter ,
225
+ markupOnly : eng . markupOnlyCodeFormatter || defaultFormatter
226
+ } : {
227
+ rendered : nullFormatter ,
228
+ rawTemplate : nullFormatter ,
229
+ markupOnly : nullFormatter
230
+ } ;
231
+
232
+ //prepare the path and contents of each output file
233
+ const outputFiles = [
234
+ { path : makePath ( 'rendered' ) , content : formatters . rendered ( patternPage , pattern ) } ,
235
+ { path : makePath ( 'rawTemplate' ) , content : formatters . rawTemplate ( pattern . template , pattern ) } ,
236
+ { path : makePath ( 'markupOnly' ) , content : formatters . markupOnly ( pattern . patternPartialCode , pattern ) }
237
+ ] . concat (
238
+ eng . addOutputFiles ? eng . addOutputFiles ( this . config . paths , this ) : [ ]
239
+ ) ;
240
+
241
+ //write the compiled template to the public patterns directory
242
+ outputFiles . forEach ( outFile => fs . outputFileSync ( outFile . path , outFile . content ) ) ;
243
+ }
214
244
}
215
245
216
246
function buildPatternData ( dataFilesPath , fsDep ) {
@@ -429,39 +459,6 @@ const patternlab_engine = function (config) {
429
459
430
460
431
461
432
-
433
-
434
- function writePatternFiles ( headHTML , pattern , footerHTML ) {
435
- const nullFormatter = str => str ;
436
- const defaultFormatter = codeString => cleanHtml ( codeString , { indent_size : 2 } ) ;
437
- const makePath = type => path . join ( paths . public . patterns , pattern . getPatternLink ( patternlab , type ) ) ;
438
- const patternPage = headHTML + pattern . patternPartialCode + footerHTML ;
439
- const eng = pattern . engine ;
440
-
441
- //beautify the output if configured to do so
442
- const formatters = config . cleanOutputHtml ? {
443
- rendered : eng . renderedCodeFormatter || defaultFormatter ,
444
- rawTemplate : eng . rawTemplateCodeFormatter || defaultFormatter ,
445
- markupOnly : eng . markupOnlyCodeFormatter || defaultFormatter
446
- } : {
447
- rendered : nullFormatter ,
448
- rawTemplate : nullFormatter ,
449
- markupOnly : nullFormatter
450
- } ;
451
-
452
- //prepare the path and contents of each output file
453
- const outputFiles = [
454
- { path : makePath ( 'rendered' ) , content : formatters . rendered ( patternPage , pattern ) } ,
455
- { path : makePath ( 'rawTemplate' ) , content : formatters . rawTemplate ( pattern . template , pattern ) } ,
456
- { path : makePath ( 'markupOnly' ) , content : formatters . markupOnly ( pattern . patternPartialCode , pattern ) }
457
- ] . concat (
458
- eng . addOutputFiles ? eng . addOutputFiles ( paths , patternlab ) : [ ]
459
- ) ;
460
-
461
- //write the compiled template to the public patterns directory
462
- outputFiles . forEach ( outFile => fs . outputFileSync ( outFile . path , outFile . content ) ) ;
463
- }
464
-
465
462
function renderSinglePattern ( pattern , head ) {
466
463
// Pattern does not need to be built and recompiled more than once
467
464
if ( ! pattern . isPattern || pattern . compileState === CompileState . CLEAN ) {
@@ -554,7 +551,7 @@ const patternlab_engine = function (config) {
554
551
patternlab . events . emit ( 'patternlab-pattern-write-begin' , patternlab , pattern ) ;
555
552
556
553
//write the compiled template to the public patterns directory
557
- writePatternFiles ( headHTML , pattern , footerHTML ) ;
554
+ patternlab . writePatternFiles ( headHTML , pattern , footerHTML ) ;
558
555
559
556
patternlab . events . emit ( 'patternlab-pattern-write-end' , patternlab , pattern ) ;
560
557
0 commit comments