Skip to content

Commit 1955516

Browse files
Merge pull request #775 from pattern-lab/danwhite85-issue/766-engine-meta-files
Danwhite85 issue/766 engine meta files
2 parents 1ed75af + 9c11320 commit 1955516

File tree

5 files changed

+14
-19
lines changed

5 files changed

+14
-19
lines changed

core/index.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ const patternlab_module = function (config) {
182182

183183
//dive again to recursively include partials, filling out the
184184
//extendedTemplate property of the patternlab.patterns elements
185+
185186
return patternlab.processAllPatternsRecursive(paths.source.patterns).then(() => {
186187

187188
//take the user defined head and foot and process any data and patterns that apply
@@ -193,14 +194,6 @@ const patternlab_module = function (config) {
193194
//cascade any patternStates
194195
lineage_hunter.cascade_pattern_states(patternlab);
195196

196-
//set pattern-specific header if necessary
197-
let head;
198-
if (patternlab.userHead) {
199-
head = patternlab.userHead;
200-
} else {
201-
head = patternlab.header;
202-
}
203-
204197
//set the pattern-specific header by compiling the general-header with data, and then adding it to the meta header
205198
return render(Pattern.createEmpty({extendedTemplate: patternlab.header}), {
206199
cacheBuster: patternlab.cacheBuster
@@ -237,7 +230,7 @@ const patternlab_module = function (config) {
237230
//render all patterns last, so lineageR works
238231
return patternsToBuild
239232
.reduce((previousPromise, pattern) => {
240-
return previousPromise.then(() => patternlab.renderSinglePattern(pattern, head));
233+
return previousPromise.then(() => patternlab.renderSinglePattern(pattern));
241234
}, Promise.resolve())
242235
.then(() => {
243236
// 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
@@ -271,8 +271,7 @@ module.exports = class PatternLab {
271271
}
272272
}
273273

274-
renderSinglePattern(pattern, head) {
275-
274+
renderSinglePattern(pattern) {
276275
// Pattern does not need to be built and recompiled more than once
277276
if (!pattern.isPattern || pattern.compileState === CompileState.CLEAN) {
278277
return Promise.resolve(false);
@@ -306,9 +305,12 @@ module.exports = class PatternLab {
306305
///////////////
307306

308307
//re-rendering the headHTML each time allows pattern-specific data to influence the head of the pattern
309-
pattern.header = head;
310-
311-
const headPromise = render(Pattern.createEmpty({extendedTemplate: pattern.header}), allData);
308+
let headPromise;
309+
if (this.userHead) {
310+
headPromise = render(this.userHead, allData);
311+
} else {
312+
headPromise = render(Pattern.createEmpty({ extendedTemplate: this.header }), allData);
313+
}
312314

313315
///////////////
314316
// PATTERN
@@ -383,7 +385,7 @@ module.exports = class PatternLab {
383385
allFooterData = _.merge(allFooterData, pattern.jsonFileData);
384386
allFooterData.patternLabFoot = footerPartial;
385387

386-
return render(Pattern.createEmpty({extendedTemplate: self.userFoot}), allFooterData).then(footerHTML => {
388+
return render(self.userFoot, allFooterData).then(footerHTML => {
387389

388390
///////////////
389391
// 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
@@ -596,7 +596,7 @@ const ui_builder = function () {
596596
const headFootData = patternlab.data;
597597
headFootData.patternLabHead = headerPartial;
598598
headFootData.cacheBuster = patternlab.cacheBuster;
599-
return render(Pattern.createEmpty({extendedTemplate: patternlab.userHead}), headFootData);
599+
return render(patternlab.userHead, headFootData);
600600
}).catch(reason => {
601601
console.log(reason);
602602
logger.error('error during header render()');
@@ -609,7 +609,7 @@ const ui_builder = function () {
609609
}).then(footerPartial => {
610610
const headFootData = patternlab.data;
611611
headFootData.patternLabFoot = footerPartial;
612-
return render(Pattern.createEmpty({extendedTemplate: patternlab.userFoot}), headFootData);
612+
return render(patternlab.userFoot, headFootData);
613613
}).catch(reason => {
614614
console.log(reason);
615615
logger.error('error during footer render()');

0 commit comments

Comments
 (0)