Skip to content

Commit

Permalink
refactor: remove parameter hunter (#1467)
Browse files Browse the repository at this point in the history
* refactor: remove parameter hunter

* refactor: remove parameter hunter

* fix: issue in mustache runable

* docs: adapted documentation

---------

Co-authored-by: Josef Bredreck <[email protected]>
Co-authored-by: Josef Bredreck <[email protected]>
  • Loading branch information
3 people authored May 29, 2023
1 parent a4d9332 commit 4ff84d0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 941 deletions.
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

0 comments on commit 4ff84d0

Please sign in to comment.