@@ -4,6 +4,7 @@ const logger = require('./log');
44const jsonCopy = require ( './json_copy' ) ;
55const getPartial = require ( './get' ) ;
66
7+ // TODO: remove when removing mustache
78module . exports = function ( currentPattern , patternlab ) {
89 const processRecursive = require ( './processRecursive' ) ;
910
@@ -19,6 +20,47 @@ module.exports = function (currentPattern, patternlab) {
1920 foundPatternPartials . length > 0
2021 ) {
2122 logger . debug ( `found partials for ${ currentPattern . patternPartial } ` ) ;
23+
24+ //do something with the regular old partials
25+ foundPatternPartials . forEach ( ( foundPartial ) => {
26+ const partial = currentPattern . findPartial ( foundPartial ) ;
27+ const partialPattern = getPartial ( partial , patternlab ) ;
28+
29+ //recurse through nested partials to fill out this extended template.
30+ return processRecursive ( partialPattern . relPath , patternlab )
31+ . then ( ( ) => {
32+ //eslint-disable-line no-loop-func
33+
34+ //complete assembly of extended template
35+ //create a copy of the partial so as to not pollute it after the getPartial call.
36+ const cleanPartialPattern = jsonCopy (
37+ partialPattern ,
38+ `partial pattern ${ partial } `
39+ ) ;
40+
41+ //this is what we came here for
42+ logger . debug (
43+ `within ${ currentPattern . patternPartial } , replacing extendedTemplate partial ${ foundPartial } with ${ cleanPartialPattern . patternPartial } 's extendedTemplate`
44+ ) ;
45+
46+ currentPattern . extendedTemplate =
47+ currentPattern . extendedTemplate . replace (
48+ foundPartial ,
49+ cleanPartialPattern . extendedTemplate
50+ ) ;
51+
52+ // update the extendedTemplate in the partials object in case this
53+ // pattern is consumed later
54+ patternlab . partials [ currentPattern . patternPartial ] =
55+ currentPattern . extendedTemplate ;
56+
57+ return Promise . resolve ( ) ;
58+ } )
59+ . catch ( ( reason ) => {
60+ console . log ( reason ) ;
61+ logger . error ( reason ) ;
62+ } ) ;
63+ } ) ;
2264 }
2365 return Promise . resolve ( ) ;
2466} ;
0 commit comments