Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

refactor: remove parameter hunter #1467

Merged
merged 16 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from 11 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
80 changes: 34 additions & 46 deletions packages/core/src/lib/expandPartials.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
'use strict';

const logger = require('./log');
const ph = require('./parameter_hunter');
const jsonCopy = require('./json_copy');
const getPartial = require('./get');

const parameter_hunter = new ph();

// TODO: remove when removing mustache
module.exports = function (currentPattern, patternlab) {
const processRecursive = require('./processRecursive');

Expand All @@ -23,56 +21,46 @@ module.exports = function (currentPattern, patternlab) {
) {
logger.debug(`found partials for ${currentPattern.patternPartial}`);

// determine if the template contains any pattern parameters. if so they
// must be immediately consumed
return parameter_hunter
.find_parameters(currentPattern, patternlab)
.then(() => {
//do something with the regular old partials
foundPatternPartials.forEach((foundPartial) => {
const partial = currentPattern.findPartial(foundPartial);
const partialPattern = getPartial(partial, patternlab);
//do something with the regular old partials
foundPatternPartials.forEach((foundPartial) => {
const partial = currentPattern.findPartial(foundPartial);
const partialPattern = getPartial(partial, patternlab);

//recurse through nested partials to fill out this extended template.
return processRecursive(partialPattern.relPath, patternlab)
.then(() => {
//eslint-disable-line no-loop-func
//recurse through nested partials to fill out this extended template.
return processRecursive(partialPattern.relPath, patternlab)
.then(() => {
//eslint-disable-line no-loop-func

//complete assembly of extended template
//create a copy of the partial so as to not pollute it after the getPartial call.
const cleanPartialPattern = jsonCopy(
partialPattern,
`partial pattern ${partial}`
);
//complete assembly of extended template
//create a copy of the partial so as to not pollute it after the getPartial call.
const cleanPartialPattern = jsonCopy(
partialPattern,
`partial pattern ${partial}`
);

//this is what we came here for
logger.debug(
`within ${currentPattern.patternPartial}, replacing extendedTemplate partial ${foundPartial} with ${cleanPartialPattern.patternPartial}'s extendedTemplate`
);
//this is what we came here for
logger.debug(
`within ${currentPattern.patternPartial}, replacing extendedTemplate partial ${foundPartial} with ${cleanPartialPattern.patternPartial}'s extendedTemplate`
);

currentPattern.extendedTemplate =
currentPattern.extendedTemplate.replace(
foundPartial,
cleanPartialPattern.extendedTemplate
);
currentPattern.extendedTemplate =
currentPattern.extendedTemplate.replace(
foundPartial,
cleanPartialPattern.extendedTemplate
);

// update the extendedTemplate in the partials object in case this
// pattern is consumed later
patternlab.partials[currentPattern.patternPartial] =
currentPattern.extendedTemplate;
// update the extendedTemplate in the partials object in case this
// pattern is consumed later
patternlab.partials[currentPattern.patternPartial] =
currentPattern.extendedTemplate;

return Promise.resolve();
})
.catch((reason) => {
console.log(reason);
logger.error(reason);
});
return Promise.resolve();
})
.catch((reason) => {
console.log(reason);
logger.error(reason);
});
})
.catch((reason) => {
console.log(reason);
logger.error(reason);
});
});
}
return Promise.resolve();
};
Loading