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