@@ -8,7 +8,6 @@ const smh = require('./style_modifier_hunter');
8
8
const addPattern = require ( './addPattern' ) ;
9
9
const jsonCopy = require ( './json_copy' ) ;
10
10
const getPartial = require ( './get' ) ;
11
- const processRecursive = require ( './processRecursive' ) ;
12
11
13
12
const lineage_hunter = new lh ( ) ;
14
13
const list_item_hunter = new lih ( ) ;
@@ -17,15 +16,19 @@ const style_modifier_hunter = new smh();
17
16
18
17
function expandPartials ( foundPatternPartials , patternlab , currentPattern ) {
19
18
19
+ // these needs to be inside the function call, unless there is a better way to handle the recursion
20
+ const processRecursive = require ( './processRecursive' ) ;
21
+
20
22
logger . debug ( `found partials for ${ currentPattern . patternPartial } ` ) ;
21
23
22
24
// determine if the template contains any pattern parameters. if so they
23
25
// must be immediately consumed
24
26
return parameter_hunter . find_parameters ( currentPattern , patternlab ) . then ( ( ) => {
25
27
26
28
//do something with the regular old partials
27
- for ( var i = 0 ; i < foundPatternPartials . length ; i ++ ) {
28
- var partial = currentPattern . findPartial ( foundPatternPartials [ i ] ) ;
29
+ foundPatternPartials . forEach ( ( foundPartial ) => {
30
+
31
+ var partial = currentPattern . findPartial ( foundPartial ) ;
29
32
var partialPath ;
30
33
31
34
//identify which pattern this partial corresponds to
@@ -37,8 +40,6 @@ function expandPartials(foundPatternPartials, patternlab, currentPattern) {
37
40
}
38
41
}
39
42
40
- console . log ( processRecursive ) ;
41
-
42
43
//recurse through nested partials to fill out this extended template.
43
44
processRecursive ( partialPath , patternlab ) . then ( ( ) => { //eslint-disable-line no-loop-func
44
45
//complete assembly of extended template
@@ -48,12 +49,16 @@ function expandPartials(foundPatternPartials, patternlab, currentPattern) {
48
49
49
50
//if partial has style modifier data, replace the styleModifier value
50
51
if ( currentPattern . stylePartials && currentPattern . stylePartials . length > 0 ) {
51
- style_modifier_hunter . consume_style_modifier ( cleanPartialPattern , foundPatternPartials [ i ] , patternlab ) ;
52
+ style_modifier_hunter . consume_style_modifier ( cleanPartialPattern , foundPartial , patternlab ) ;
52
53
}
53
54
54
- currentPattern . extendedTemplate = currentPattern . extendedTemplate . replace ( foundPatternPartials [ i ] , cleanPartialPattern . extendedTemplate ) ;
55
+ //this is what we came here for
56
+ logger . debug ( `within ${ currentPattern . patternPartial } , replacing extendedTemplate partial ${ foundPartial } with ${ cleanPartialPattern . patternPartial } 's extededTemplate` ) ;
57
+ currentPattern . extendedTemplate = currentPattern . extendedTemplate . replace ( foundPartial , cleanPartialPattern . extendedTemplate ) ;
55
58
} ) ;
56
- }
59
+ } ) ;
60
+ } ) . catch ( ( reason ) => {
61
+ logger . error ( reason ) ;
57
62
} ) ;
58
63
}
59
64
@@ -66,6 +71,7 @@ function expandPartials(foundPatternPartials, patternlab, currentPattern) {
66
71
*/
67
72
module . exports = function ( pattern , patternlab , ignoreLineage ) {
68
73
74
+ //set the extendedTemplate to operate on later if we find partials to replace
69
75
pattern . extendedTemplate = pattern . template ;
70
76
71
77
//find how many partials there may be for the given pattern
@@ -106,5 +112,8 @@ module.exports = function (pattern, patternlab, ignoreLineage) {
106
112
addPattern ( pattern , patternlab ) ;
107
113
} ) ;
108
114
109
- return Promise . all ( [ expandPartialPromise , lineagePromise , addPromise ] ) ;
115
+ return Promise . all ( [ expandPartialPromise , lineagePromise , addPromise ] )
116
+ . catch ( ( reason ) => {
117
+ logger . error ( reason ) ;
118
+ } ) ;
110
119
} ;
0 commit comments