Skip to content
This repository was archived by the owner on Dec 10, 2019. It is now read-only.

Commit b0e6fd5

Browse files
committed
reverse lineage
1 parent fc4d420 commit b0e6fd5

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

builder/lineage_hunter.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,45 @@
1717

1818
pattern.lineage = [];
1919
pattern.lineageIndex = [];
20+
pattern.lineageR = [];
21+
pattern.lineageRIndex = [];
2022
//find the {{> template-name }} within patterns
2123
var matches = pattern.template.match(/{{>([ ]+)?([A-Za-z0-9-]+)(?:\:[A-Za-z0-9-]+)?(?:(| )\(.*)?([ ]+)}}/g);
2224
if(matches !== null){
2325
matches.forEach(function(match, index, matches){
2426
//strip out the template cruft
25-
var cleanPattern = match.replace("{{> ", "").replace(" }}", "");
27+
var foundPattern = match.replace("{{> ", "").replace(" }}", "");
2628

2729
//add if it doesnt exist
28-
if (pattern.lineageIndex.indexOf(cleanPattern) === -1){
30+
if (pattern.lineageIndex.indexOf(foundPattern) === -1){
2931

30-
pattern.lineageIndex.push(cleanPattern);
32+
pattern.lineageIndex.push(foundPattern);
3133

32-
patternlab.patterns.forEach(function(p, index, patterns){
34+
patternlab.patterns.forEach(function(ancestorPattern, index, patterns){
3335

3436
//find the pattern in question
35-
var searchPattern = p.patternGroup + "-" + p.patternName;
37+
var searchPattern = ancestorPattern.patternGroup + "-" + ancestorPattern.patternName;
3638

37-
if(searchPattern === cleanPattern){
39+
if(searchPattern === foundPattern){
3840
//create the more complex patternLineage object too
3941
var l = {
40-
"lineagePattern": cleanPattern,
41-
"lineagePath": "../../patterns/" + p.patternLink
42-
}
42+
"lineagePattern": foundPattern,
43+
"lineagePath": "../../patterns/" + ancestorPattern.patternLink
44+
};
4345
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+
}
4459
}
4560

4661
});

builder/patternlab.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,12 @@ var patternlab_engine = function(){
116116
}
117117

118118
//write the compiled template to the public patterns directory
119-
flatPatternPath = currentPattern.name + '/' + currentPattern.name + '.html';
120-
currentPattern.patternLink = flatPatternPath;
119+
currentPattern.patternLink = currentPattern.name + '/' + currentPattern.name + '.html';;
121120

122121
//find pattern lineage
123122
var lineage_hunter = new lh();
124123
lineage_hunter.find_lineage(currentPattern, patternlab);
125124

126-
//add footer info before writing
127-
var currentPatternFooter = renderPattern(patternlab.footer, currentPattern);
128-
129-
fs.outputFileSync('./public/patterns/' + flatPatternPath, patternlab.header + currentPattern.patternPartial + currentPatternFooter);
130-
131125
//add as a partial in case this is referenced later. convert to syntax needed by existing patterns
132126
var sub = subdir.substring(subdir.indexOf('-') + 1);
133127
var folderIndex = sub.indexOf(path.sep);
@@ -148,6 +142,17 @@ var patternlab_engine = function(){
148142
patternlab.patterns.push(currentPattern);
149143
});
150144

145+
//render all patterns last, so lineageR works
146+
patternlab.patterns.forEach(function(pattern, index, patterns){
147+
148+
//add footer info before writing
149+
var patternFooter = renderPattern(patternlab.footer, pattern);
150+
151+
fs.outputFileSync('./public/patterns/' + pattern.patternLink, patternlab.header + pattern.patternPartial + patternFooter);
152+
153+
});
154+
155+
151156
}
152157

153158
function buildFrontEnd(){

source/_patternlab-files/pattern-header-footer/footer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// handle injection of items from PHP
1111
var patternPartial = "{{ patternGroup }}-{{ patternName }}";
1212
var lineage = [{{{ lineage }}}];
13-
var lineageR = "{{ lineageR }}";
13+
var lineageR = [{{{ lineageR }}}];
1414
var patternState = "{{patternState}}"
1515
var cssEnabled = false; //TODO
1616
</script>

0 commit comments

Comments
 (0)