@@ -4,6 +4,7 @@ const logger = require('./log');
4
4
const jsonCopy = require ( './json_copy' ) ;
5
5
const getPartial = require ( './get' ) ;
6
6
7
+ // TODO: remove when removing mustache
7
8
module . exports = function ( currentPattern , patternlab ) {
8
9
const processRecursive = require ( './processRecursive' ) ;
9
10
@@ -19,6 +20,47 @@ module.exports = function (currentPattern, patternlab) {
19
20
foundPatternPartials . length > 0
20
21
) {
21
22
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
+ } ) ;
22
64
}
23
65
return Promise . resolve ( ) ;
24
66
} ;
0 commit comments