|
1 |
| -/* |
2 |
| - * patternlab-node - v1.1.3 - 2016 |
3 |
| - * |
| 1 | +/* |
| 2 | + * patternlab-node - v1.1.3 - 2016 |
| 3 | + * |
4 | 4 | * Brian Muenzenmeyer, and the web community.
|
5 |
| - * Licensed under the MIT license. |
6 |
| - * |
7 |
| - * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. |
| 5 | + * Licensed under the MIT license. |
| 6 | + * |
| 7 | + * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. |
8 | 8 | *
|
9 | 9 | */
|
10 | 10 |
|
11 |
| -(function () { |
12 |
| - "use strict"; |
13 |
| - |
14 |
| - var lineage_hunter = function(){ |
15 |
| - |
16 |
| - function findlineage(pattern, patternlab){ |
17 |
| - |
18 |
| - var pa = require('./pattern_assembler'); |
19 |
| - var pattern_assembler = new pa(); |
20 |
| - |
21 |
| - //find the {{> template-name }} within patterns |
22 |
| - var matches = pattern_assembler.find_pattern_partials(pattern); |
23 |
| - if(matches !== null){ |
24 |
| - matches.forEach(function(match, index, matches){ |
25 |
| - //strip out the template cruft |
26 |
| - var foundPatternKey = match.replace("{{> ", "").replace(" }}", "").replace("{{>", "").replace("}}", ""); |
27 |
| - |
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(foundPatternKey.indexOf('(') > 0){ |
30 |
| - foundPatternKey = foundPatternKey.substring(0, foundPatternKey.indexOf('(')); |
31 |
| - } |
32 |
| - |
33 |
| - //remove any potential stylemodifiers. |
34 |
| - foundPatternKey = foundPatternKey.split(':')[0]; |
35 |
| - |
36 |
| - //get the ancestorPattern |
37 |
| - var ancestorPattern = pattern_assembler.get_pattern_by_key(foundPatternKey, patternlab); |
38 |
| - |
39 |
| - if (ancestorPattern && pattern.lineageIndex.indexOf(ancestorPattern.key) === -1){ |
40 |
| - |
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)); |
49 |
| - |
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 |
58 |
| - }; |
59 |
| - ancestorPattern.lineageR.push(JSON.stringify(lr)); |
60 |
| - } |
61 |
| - } |
62 |
| - }); |
63 |
| - } |
64 |
| - } |
65 |
| - |
66 |
| - return { |
67 |
| - find_lineage: function(pattern, patternlab){ |
68 |
| - findlineage(pattern, patternlab); |
69 |
| - } |
70 |
| - }; |
71 |
| - |
72 |
| - }; |
73 |
| - |
74 |
| - module.exports = lineage_hunter; |
75 |
| - |
76 |
| -}()); |
| 11 | +"use strict"; |
| 12 | + |
| 13 | +var lineage_hunter = function () { |
| 14 | + |
| 15 | + function findlineage(pattern, patternlab) { |
| 16 | + |
| 17 | + var pa = require('./pattern_assembler'); |
| 18 | + var pattern_assembler = new pa(); |
| 19 | + |
| 20 | + //find the {{> template-name }} within patterns |
| 21 | + var matches = pattern_assembler.find_pattern_partials(pattern); |
| 22 | + if(matches !== null) { |
| 23 | + matches.forEach(function (match) { |
| 24 | + //strip out the template cruft |
| 25 | + var foundPatternKey = match |
| 26 | + .replace("{{> ", "") |
| 27 | + .replace(" }}", "") |
| 28 | + .replace("{{>", "") |
| 29 | + .replace("}}", ""); |
| 30 | + |
| 31 | + // remove any potential pattern parameters. this and the above are |
| 32 | + // rather brutish but I didn't want to do a regex at the time |
| 33 | + if(foundPatternKey.indexOf('(') > 0) { |
| 34 | + foundPatternKey = foundPatternKey.substring(0, foundPatternKey.indexOf('(')); |
| 35 | + } |
| 36 | + |
| 37 | + //remove any potential stylemodifiers. |
| 38 | + foundPatternKey = foundPatternKey.split(':')[0]; |
| 39 | + |
| 40 | + //get the ancestorPattern |
| 41 | + var ancestorPattern = pattern_assembler.get_pattern_by_key(foundPatternKey, patternlab); |
| 42 | + |
| 43 | + if (ancestorPattern && pattern.lineageIndex.indexOf(ancestorPattern.key) === -1) { |
| 44 | + |
| 45 | + //add it since it didnt exist |
| 46 | + pattern.lineageIndex.push(ancestorPattern.key); |
| 47 | + //create the more complex patternLineage object too |
| 48 | + var l = { |
| 49 | + "lineagePattern": ancestorPattern.key, |
| 50 | + "lineagePath": "../../patterns/" + ancestorPattern.patternLink |
| 51 | + }; |
| 52 | + pattern.lineage.push(JSON.stringify(l)); |
| 53 | + |
| 54 | + //also, add the lineageR entry if it doesn't exist |
| 55 | + if (ancestorPattern.lineageRIndex.indexOf(pattern.key) === -1) { |
| 56 | + ancestorPattern.lineageRIndex.push(pattern.key); |
| 57 | + |
| 58 | + //create the more complex patternLineage object in reverse |
| 59 | + var lr = { |
| 60 | + "lineagePattern": pattern.key, |
| 61 | + "lineagePath": "../../patterns/" + pattern.patternLink |
| 62 | + }; |
| 63 | + ancestorPattern.lineageR.push(JSON.stringify(lr)); |
| 64 | + } |
| 65 | + } |
| 66 | + }); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + return { |
| 71 | + find_lineage: function (pattern, patternlab) { |
| 72 | + findlineage(pattern, patternlab); |
| 73 | + } |
| 74 | + }; |
| 75 | + |
| 76 | +}; |
| 77 | + |
| 78 | +module.exports = lineage_hunter; |
0 commit comments