Skip to content

Commit 1021702

Browse files
committed
refactor(expandPartials): Use getPartial
1 parent c706267 commit 1021702

File tree

1 file changed

+3
-24
lines changed

1 file changed

+3
-24
lines changed

core/lib/expandPartials.js

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,14 @@ module.exports = function (currentPattern, patternlab) {
1313

1414
const processRecursive = require('./processRecursive');
1515

16-
console.log('15 currentPattern', currentPattern.patternPartial)
17-
1816
//find how many partials there may be for the given pattern
1917
const foundPatternPartials = currentPattern.findPartials();
2018

21-
console.log(20, currentPattern.patternPartial, foundPatternPartials)
22-
2319
// expand any partials present in this pattern; that is, drill down into
2420
// the template and replace their calls in this template with rendered
2521
// results
2622
if (currentPattern.engine.expandPartials && (foundPatternPartials !== null && foundPatternPartials.length > 0)) {
2723

28-
2924
logger.debug(`found partials for ${currentPattern.patternPartial}`);
3025

3126
// determine if the template contains any pattern parameters. if so they
@@ -36,22 +31,13 @@ module.exports = function (currentPattern, patternlab) {
3631
foundPatternPartials.forEach((foundPartial) => {
3732

3833
var partial = currentPattern.findPartial(foundPartial);
39-
var partialPath;
40-
41-
//identify which pattern this partial corresponds to
42-
for (var j = 0; j < patternlab.patterns.length; j++) {
43-
if (patternlab.patterns[j].patternPartial === partial ||
44-
patternlab.patterns[j].relPath.indexOf(partial) > -1)
45-
{
46-
partialPath = patternlab.patterns[j].relPath;
47-
}
48-
}
34+
var partialPattern = getPartial(partial, patternlab);
4935

5036
//recurse through nested partials to fill out this extended template.
51-
return processRecursive(partialPath, patternlab).then(() => { //eslint-disable-line no-loop-func
37+
return processRecursive(partialPattern.relPath, patternlab).then(() => { //eslint-disable-line no-loop-func
38+
5239
//complete assembly of extended template
5340
//create a copy of the partial so as to not pollute it after the getPartial call.
54-
var partialPattern = getPartial(partial, patternlab);
5541
var cleanPartialPattern = jsonCopy(partialPattern, `partial pattern ${partial}`);
5642

5743
//if partial has style modifier data, replace the styleModifier value
@@ -62,24 +48,17 @@ module.exports = function (currentPattern, patternlab) {
6248
//this is what we came here for
6349
logger.debug(`within ${currentPattern.patternPartial}, replacing extendedTemplate partial ${foundPartial} with ${cleanPartialPattern.patternPartial}'s extendedTemplate`);
6450

65-
//console.log(`decompose 58 within ${currentPattern.patternPartial}, replacing extendedTemplate partial ${foundPartial} with ${cleanPartialPattern.patternPartial}'s extededTemplate`)
66-
//console.log(currentPattern.extendedTemplate);
67-
//console.log(cleanPartialPattern.extendedTemplate);
6851
currentPattern.extendedTemplate = currentPattern.extendedTemplate.replace(foundPartial, cleanPartialPattern.extendedTemplate);
6952

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

74-
//console.log(62, `currentPattern ${currentPattern.patternPartial} .extendedTemplate now ${currentPattern.extendedTemplate}`)
7557
return Promise.resolve();
7658
}).catch(reason => {
7759
console.log(reason)
7860
logger.error(reason);
7961
});
80-
81-
console.log('82 is bad')
82-
8362
});
8463

8564
}).catch(reason => {

0 commit comments

Comments
 (0)