Skip to content

Commit

Permalink
Merge pull request #775 from pattern-lab/danwhite85-issue/766-engine-…
Browse files Browse the repository at this point in the history
…meta-files

Danwhite85 issue/766 engine meta files
  • Loading branch information
bmuenzenmeyer authored Jan 16, 2018
2 parents 1ed75af + 9c11320 commit 1955516
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
11 changes: 2 additions & 9 deletions core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ const patternlab_module = function (config) {

//dive again to recursively include partials, filling out the
//extendedTemplate property of the patternlab.patterns elements

return patternlab.processAllPatternsRecursive(paths.source.patterns).then(() => {

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

//set pattern-specific header if necessary
let head;
if (patternlab.userHead) {
head = patternlab.userHead;
} else {
head = patternlab.header;
}

//set the pattern-specific header by compiling the general-header with data, and then adding it to the meta header
return render(Pattern.createEmpty({extendedTemplate: patternlab.header}), {
cacheBuster: patternlab.cacheBuster
Expand Down Expand Up @@ -237,7 +230,7 @@ const patternlab_module = function (config) {
//render all patterns last, so lineageR works
return patternsToBuild
.reduce((previousPromise, pattern) => {
return previousPromise.then(() => patternlab.renderSinglePattern(pattern, head));
return previousPromise.then(() => patternlab.renderSinglePattern(pattern));
}, Promise.resolve())
.then(() => {
// Saves the pattern graph when all files have been compiled
Expand Down
2 changes: 1 addition & 1 deletion core/lib/buildFooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = function (patternlab, patternPartial) {
}
allFooterData.patternLabFoot = footerPartial;

return render(Pattern.createEmpty({extendedTemplate: patternlab.userFoot}), allFooterData);
return render(patternlab.userFoot, allFooterData);
}).catch(reason => {
console.log(reason);
logger.error('Error building buildFooterHTML');
Expand Down
14 changes: 8 additions & 6 deletions core/lib/patternlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,7 @@ module.exports = class PatternLab {
}
}

renderSinglePattern(pattern, head) {

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

//re-rendering the headHTML each time allows pattern-specific data to influence the head of the pattern
pattern.header = head;

const headPromise = render(Pattern.createEmpty({extendedTemplate: pattern.header}), allData);
let headPromise;
if (this.userHead) {
headPromise = render(this.userHead, allData);
} else {
headPromise = render(Pattern.createEmpty({ extendedTemplate: this.header }), allData);
}

///////////////
// PATTERN
Expand Down Expand Up @@ -383,7 +385,7 @@ module.exports = class PatternLab {
allFooterData = _.merge(allFooterData, pattern.jsonFileData);
allFooterData.patternLabFoot = footerPartial;

return render(Pattern.createEmpty({extendedTemplate: self.userFoot}), allFooterData).then(footerHTML => {
return render(self.userFoot, allFooterData).then(footerHTML => {

///////////////
// WRITE FILES
Expand Down
2 changes: 1 addition & 1 deletion core/lib/processMetaPattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function (fileName, metaType, patternlab) {
metaPattern.isPattern = false;
metaPattern.isMetaPattern = true;
return decompose(metaPattern, patternlab, true).then(() => {
patternlab[metaType] = metaPattern.extendedTemplate;
patternlab[metaType] = metaPattern;
}).catch(reason => {
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.`);
logger.warning(reason);
Expand Down
4 changes: 2 additions & 2 deletions core/lib/ui_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ const ui_builder = function () {
const headFootData = patternlab.data;
headFootData.patternLabHead = headerPartial;
headFootData.cacheBuster = patternlab.cacheBuster;
return render(Pattern.createEmpty({extendedTemplate: patternlab.userHead}), headFootData);
return render(patternlab.userHead, headFootData);
}).catch(reason => {
console.log(reason);
logger.error('error during header render()');
Expand All @@ -609,7 +609,7 @@ const ui_builder = function () {
}).then(footerPartial => {
const headFootData = patternlab.data;
headFootData.patternLabFoot = footerPartial;
return render(Pattern.createEmpty({extendedTemplate: patternlab.userFoot}), headFootData);
return render(patternlab.userFoot, headFootData);
}).catch(reason => {
console.log(reason);
logger.error('error during footer render()');
Expand Down

0 comments on commit 1955516

Please sign in to comment.