Skip to content

Use patterns created by processMetaPattern for rendering #770

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Jan 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,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 @@ -239,7 +231,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 @@ -275,7 +275,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 @@ -309,10 +309,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 headHTML
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 @@ -388,7 +390,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 @@ -639,7 +639,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 @@ -652,7 +652,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