|
17 | 17 |
|
18 | 18 | pattern.lineage = []; |
19 | 19 | pattern.lineageIndex = []; |
| 20 | + pattern.lineageR = []; |
| 21 | + pattern.lineageRIndex = []; |
20 | 22 | //find the {{> template-name }} within patterns |
21 | 23 | var matches = pattern.template.match(/{{>([ ]+)?([A-Za-z0-9-]+)(?:\:[A-Za-z0-9-]+)?(?:(| )\(.*)?([ ]+)}}/g); |
22 | 24 | if(matches !== null){ |
23 | 25 | matches.forEach(function(match, index, matches){ |
24 | 26 | //strip out the template cruft |
25 | | - var cleanPattern = match.replace("{{> ", "").replace(" }}", ""); |
| 27 | + var foundPattern = match.replace("{{> ", "").replace(" }}", ""); |
26 | 28 |
|
27 | 29 | //add if it doesnt exist |
28 | | - if (pattern.lineageIndex.indexOf(cleanPattern) === -1){ |
| 30 | + if (pattern.lineageIndex.indexOf(foundPattern) === -1){ |
29 | 31 |
|
30 | | - pattern.lineageIndex.push(cleanPattern); |
| 32 | + pattern.lineageIndex.push(foundPattern); |
31 | 33 |
|
32 | | - patternlab.patterns.forEach(function(p, index, patterns){ |
| 34 | + patternlab.patterns.forEach(function(ancestorPattern, index, patterns){ |
33 | 35 |
|
34 | 36 | //find the pattern in question |
35 | | - var searchPattern = p.patternGroup + "-" + p.patternName; |
| 37 | + var searchPattern = ancestorPattern.patternGroup + "-" + ancestorPattern.patternName; |
36 | 38 |
|
37 | | - if(searchPattern === cleanPattern){ |
| 39 | + if(searchPattern === foundPattern){ |
38 | 40 | //create the more complex patternLineage object too |
39 | 41 | var l = { |
40 | | - "lineagePattern": cleanPattern, |
41 | | - "lineagePath": "../../patterns/" + p.patternLink |
42 | | - } |
| 42 | + "lineagePattern": foundPattern, |
| 43 | + "lineagePath": "../../patterns/" + ancestorPattern.patternLink |
| 44 | + }; |
43 | 45 | pattern.lineage.push(JSON.stringify(l)); |
| 46 | + |
| 47 | + //also, add the lineageR entry if it doesn't exist |
| 48 | + var patternLabel = pattern.patternGroup + "-" + pattern.patternName; |
| 49 | + if (ancestorPattern.lineageRIndex.indexOf(patternLabel) === -1){ |
| 50 | + ancestorPattern.lineageRIndex.push(patternLabel); |
| 51 | + |
| 52 | + //create the more complex patternLineage object in reverse |
| 53 | + var lr = { |
| 54 | + "lineagePattern": patternLabel, |
| 55 | + "lineagePath": "../../patterns/" + pattern.patternLink |
| 56 | + }; |
| 57 | + ancestorPattern.lineageR.push(JSON.stringify(lr)); |
| 58 | + } |
44 | 59 | } |
45 | 60 |
|
46 | 61 | }); |
|
0 commit comments