|
23 | 23 | if(matches !== null){ |
24 | 24 | matches.forEach(function(match, index, matches){ |
25 | 25 | //strip out the template cruft |
26 | | - var foundPattern = match.replace("{{> ", "").replace(" }}", "").replace("{{>", "").replace("}}", ""); |
| 26 | + var foundPatternKey = match.replace("{{> ", "").replace(" }}", "").replace("{{>", "").replace("}}", ""); |
27 | 27 |
|
28 | 28 | // remove any potential pattern parameters. this and the above are rather brutish but I didn't want to do a regex at the time |
29 | | - if(foundPattern.indexOf('(') > 0){ |
30 | | - foundPattern = foundPattern.substring(0, foundPattern.indexOf('(')); |
| 29 | + if(foundPatternKey.indexOf('(') > 0){ |
| 30 | + foundPatternKey = foundPatternKey.substring(0, foundPatternKey.indexOf('(')); |
31 | 31 | } |
32 | 32 |
|
33 | | - //add if it doesnt exist |
34 | | - if (pattern.lineageIndex.indexOf(foundPattern) === -1){ |
| 33 | + //remove any potential stylemodifiers. |
| 34 | + foundPatternKey = foundPatternKey.split(':')[0]; |
35 | 35 |
|
36 | | - pattern.lineageIndex.push(foundPattern); |
| 36 | + //get the ancestorPattern |
| 37 | + var ancestorPattern = pattern_assembler.get_pattern_by_key(foundPatternKey, patternlab); |
37 | 38 |
|
38 | | - patternlab.patterns.forEach(function(ancestorPattern, index, patterns){ |
| 39 | + if (ancestorPattern && pattern.lineageIndex.indexOf(ancestorPattern.key) === -1){ |
39 | 40 |
|
40 | | - //find the pattern in question |
41 | | - var searchPattern = ancestorPattern.patternGroup + "-" + ancestorPattern.patternName; |
| 41 | + //add it since it didnt exist |
| 42 | + pattern.lineageIndex.push(ancestorPattern.key); |
| 43 | + //create the more complex patternLineage object too |
| 44 | + var l = { |
| 45 | + "lineagePattern": ancestorPattern.key, |
| 46 | + "lineagePath": "../../patterns/" + ancestorPattern.patternLink |
| 47 | + }; |
| 48 | + pattern.lineage.push(JSON.stringify(l)); |
42 | 49 |
|
43 | | - if(searchPattern === foundPattern){ |
44 | | - //create the more complex patternLineage object too |
45 | | - var l = { |
46 | | - "lineagePattern": foundPattern, |
47 | | - "lineagePath": "../../patterns/" + ancestorPattern.patternLink |
| 50 | + //also, add the lineageR entry if it doesn't exist |
| 51 | + if (ancestorPattern.lineageRIndex.indexOf(pattern.key) === -1){ |
| 52 | + ancestorPattern.lineageRIndex.push(pattern.key); |
| 53 | + |
| 54 | + //create the more complex patternLineage object in reverse |
| 55 | + var lr = { |
| 56 | + "lineagePattern": pattern.key, |
| 57 | + "lineagePath": "../../patterns/" + pattern.patternLink |
48 | 58 | }; |
49 | | - pattern.lineage.push(JSON.stringify(l)); |
50 | | - |
51 | | - //also, add the lineageR entry if it doesn't exist |
52 | | - var patternLabel = pattern.patternGroup + "-" + pattern.patternName; |
53 | | - if (ancestorPattern.lineageRIndex.indexOf(patternLabel) === -1){ |
54 | | - ancestorPattern.lineageRIndex.push(patternLabel); |
55 | | - |
56 | | - //create the more complex patternLineage object in reverse |
57 | | - var lr = { |
58 | | - "lineagePattern": patternLabel, |
59 | | - "lineagePath": "../../patterns/" + pattern.patternLink |
60 | | - }; |
61 | | - ancestorPattern.lineageR.push(JSON.stringify(lr)); |
62 | | - } |
| 59 | + ancestorPattern.lineageR.push(JSON.stringify(lr)); |
63 | 60 | } |
64 | | - |
65 | | - }); |
66 | | - |
67 | 61 | } |
68 | 62 | }); |
69 | 63 | } |
|
0 commit comments