Skip to content

Commit d47d974

Browse files
author
Dan White
committed
Use patterns created by processMetaPattern instead of empty ones for rendering
1 parent 578a9af commit d47d974

File tree

5 files changed

+13
-19
lines changed

5 files changed

+13
-19
lines changed

core/index.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,6 @@ const patternlab_module = function (config) {
195195
//cascade any patternStates
196196
lineage_hunter.cascade_pattern_states(patternlab);
197197

198-
//set pattern-specific header if necessary
199-
let head;
200-
if (patternlab.userHead) {
201-
head = patternlab.userHead;
202-
} else {
203-
head = patternlab.header;
204-
}
205-
206198
//set the pattern-specific header by compiling the general-header with data, and then adding it to the meta header
207199
return render(Pattern.createEmpty({extendedTemplate: patternlab.header}), {
208200
cacheBuster: patternlab.cacheBuster
@@ -239,7 +231,7 @@ const patternlab_module = function (config) {
239231
//render all patterns last, so lineageR works
240232
return patternsToBuild
241233
.reduce((previousPromise, pattern) => {
242-
return previousPromise.then(() => patternlab.renderSinglePattern(pattern, head));
234+
return previousPromise.then(() => patternlab.renderSinglePattern(pattern));
243235
}, Promise.resolve())
244236
.then(() => {
245237
// Saves the pattern graph when all files have been compiled

core/lib/buildFooter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = function (patternlab, patternPartial) {
3131
}
3232
allFooterData.patternLabFoot = footerPartial;
3333

34-
return render(Pattern.createEmpty({extendedTemplate: patternlab.userFoot}), allFooterData);
34+
return render(patternlab.userFoot, allFooterData);
3535
}).catch(reason => {
3636
console.log(reason);
3737
logger.error('Error building buildFooterHTML');

core/lib/patternlab.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ module.exports = class PatternLab {
275275
}
276276
}
277277

278-
renderSinglePattern(pattern, head) {
278+
renderSinglePattern(pattern) {
279279
// Pattern does not need to be built and recompiled more than once
280280
if (!pattern.isPattern || pattern.compileState === CompileState.CLEAN) {
281281
return Promise.resolve(false);
@@ -309,10 +309,12 @@ module.exports = class PatternLab {
309309
///////////////
310310

311311
//re-rendering the headHTML each time allows pattern-specific data to influence the head of the pattern
312-
pattern.header = head;
313-
314-
// const headHTML
315-
const headPromise = render(Pattern.createEmpty({extendedTemplate: pattern.header}), allData);
312+
let headPromise;
313+
if (this.userHead) {
314+
headPromise = render(this.userHead, allData);
315+
} else {
316+
headPromise = render(Pattern.createEmpty({ extendedTemplate: this.header }), allData);
317+
}
316318

317319
///////////////
318320
// PATTERN
@@ -388,7 +390,7 @@ module.exports = class PatternLab {
388390
allFooterData = _.merge(allFooterData, pattern.jsonFileData);
389391
allFooterData.patternLabFoot = footerPartial;
390392

391-
return render(Pattern.createEmpty({extendedTemplate: self.userFoot}), allFooterData).then(footerHTML => {
393+
return render(self.userFoot, allFooterData).then(footerHTML => {
392394

393395
///////////////
394396
// WRITE FILES

core/lib/processMetaPattern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = function (fileName, metaType, patternlab) {
1616
metaPattern.isPattern = false;
1717
metaPattern.isMetaPattern = true;
1818
return decompose(metaPattern, patternlab, true).then(() => {
19-
patternlab[metaType] = metaPattern.extendedTemplate;
19+
patternlab[metaType] = metaPattern;
2020
}).catch(reason => {
2121
logger.warning(`Could not find the user-editable template ${fileName}, currently configured to be at ${patternlab.config.paths.source.meta}. Your configured path may be incorrect (check paths.source.meta in your config file), the file may have been deleted, or it may have been left in the wrong place during a migration or update.`);
2222
logger.warning(reason);

core/lib/ui_builder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ const ui_builder = function () {
639639
const headFootData = patternlab.data;
640640
headFootData.patternLabHead = headerPartial;
641641
headFootData.cacheBuster = patternlab.cacheBuster;
642-
return render(Pattern.createEmpty({extendedTemplate: patternlab.userHead}), headFootData);
642+
return render(patternlab.userHead, headFootData);
643643
}).catch(reason => {
644644
console.log(reason);
645645
logger.error('error during header render()');
@@ -652,7 +652,7 @@ const ui_builder = function () {
652652
}).then(footerPartial => {
653653
const headFootData = patternlab.data;
654654
headFootData.patternLabFoot = footerPartial;
655-
return render(Pattern.createEmpty({extendedTemplate: patternlab.userFoot}), headFootData);
655+
return render(patternlab.userFoot, headFootData);
656656
}).catch(reason => {
657657
console.log(reason);
658658
logger.error('error during footer render()');

0 commit comments

Comments
 (0)