Skip to content

Commit 6fc5f5e

Browse files
committed
Move writePatternFiles() into the class
1 parent 004bb18 commit 6fc5f5e

File tree

1 file changed

+31
-34
lines changed

1 file changed

+31
-34
lines changed

core/lib/patternlab.js

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,36 @@ class PatternLab {
211211
}
212212

213213

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+
}
214244
}
215245

216246
function buildPatternData(dataFilesPath, fsDep) {
@@ -429,39 +459,6 @@ const patternlab_engine = function (config) {
429459

430460

431461

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-
465462
function renderSinglePattern(pattern, head) {
466463
// Pattern does not need to be built and recompiled more than once
467464
if (!pattern.isPattern || pattern.compileState === CompileState.CLEAN) {
@@ -554,7 +551,7 @@ const patternlab_engine = function (config) {
554551
patternlab.events.emit('patternlab-pattern-write-begin', patternlab, pattern);
555552

556553
//write the compiled template to the public patterns directory
557-
writePatternFiles(headHTML, pattern, footerHTML);
554+
patternlab.writePatternFiles(headHTML, pattern, footerHTML);
558555

559556
patternlab.events.emit('patternlab-pattern-write-end', patternlab, pattern);
560557

0 commit comments

Comments
 (0)