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

Commit b5fa8bb

Browse files
committed
initial lineage support
code-viewer.js line 300 had to change. VERY HACKISH and lazy for now.
1 parent b8d38b2 commit b5fa8bb

File tree

5 files changed

+65
-5
lines changed

5 files changed

+65
-5
lines changed

builder/lineage_hunter.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
(function () {
2+
"use strict";
3+
4+
var lineage_hunter = function(){
5+
6+
function findlineage(pattern, patternlab){
7+
8+
pattern.lineage = [];
9+
pattern.lineageIndex = [];
10+
//find the {{> template-name }} within patterns
11+
var matches = pattern.template.match(/{{>([ ]+)?([A-Za-z0-9-]+)(?:\:[A-Za-z0-9-]+)?(?:(| )\(.*)?([ ]+)}}/g);
12+
if(matches !== null){
13+
matches.forEach(function(match, index, matches){
14+
//strip out the template cruft
15+
var cleanPattern = match.replace("{{> ", "").replace(" }}", "");
16+
17+
//add if it doesnt exist
18+
if (pattern.lineageIndex.indexOf(cleanPattern) === -1){
19+
20+
pattern.lineageIndex.push(cleanPattern);
21+
22+
patternlab.patterns.forEach(function(p, index, patterns){
23+
24+
//find the pattern in question
25+
var searchPattern = p.patternGroup + "-" + p.patternName;
26+
27+
if(searchPattern === cleanPattern){
28+
//create the more complex patternLineage object too
29+
var l = {
30+
"lineagePattern": cleanPattern,
31+
"lineagePath": "../../patterns/" + p.patternLink
32+
}
33+
pattern.lineage.push(JSON.stringify(l));
34+
}
35+
36+
});
37+
38+
}
39+
});
40+
}
41+
}
42+
43+
return {
44+
find_lineage: function(pattern, patternlab){
45+
findlineage(pattern, patternlab);
46+
}
47+
};
48+
49+
};
50+
51+
module.exports = lineage_hunter;
52+
53+
}());

builder/patternlab.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var patternlab_engine = function(){
1616
of = require('./object_factory'),
1717
pa = require('./pattern_assembler'),
1818
mh = require('./media_hunter'),
19+
lh = require('./lineage_hunter'),
1920
patternlab = {};
2021

2122
patternlab.package =fs.readJSONSync('./package.json');
@@ -92,6 +93,8 @@ var patternlab_engine = function(){
9293
//see if this file has a state
9394
if(patternlab.config.patternStates[currentPattern.patternName]){
9495
currentPattern.patternState = patternlab.config.patternStates[currentPattern.patternName];
96+
} else{
97+
currentPattern.patternState = "";
9598
}
9699

97100
//look for a json file for this template
@@ -114,12 +117,16 @@ var patternlab_engine = function(){
114117

115118
//write the compiled template to the public patterns directory
116119
flatPatternPath = currentPattern.name + '/' + currentPattern.name + '.html';
120+
currentPattern.patternLink = flatPatternPath;
121+
122+
//find pattern lineage
123+
var lineage_hunter = new lh();
124+
lineage_hunter.find_lineage(currentPattern, patternlab);
117125

118126
//add footer info before writing
119127
var currentPatternFooter = renderPattern(patternlab.footer, currentPattern);
120128

121129
fs.outputFileSync('./public/patterns/' + flatPatternPath, patternlab.header + currentPattern.patternPartial + currentPatternFooter);
122-
currentPattern.patternLink = flatPatternPath;
123130

124131
//add as a partial in case this is referenced later. convert to syntax needed by existing patterns
125132
var sub = subdir.substring(subdir.indexOf('-') + 1);
@@ -296,9 +303,7 @@ var patternlab_engine = function(){
296303

297304
//ishControls
298305
var ishControlsTemplate = fs.readFileSync('./source/_patternlab-files/partials/ishControls.mustache', 'utf8');
299-
console.log(patternlab.mediaQueries);
300306
patternlab.config.mqs = patternlab.mediaQueries;
301-
console.log(patternlab.config);
302307
var ishControlsPartialHtml = renderPattern(ishControlsTemplate, patternlab.config);
303308

304309
//patternPaths

public/styleguide/images/spinner.gif

22.9 KB
Loading

public/styleguide/js/code-viewer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ var codeViewer = {
297297
e.preventDefault();
298298
$("#sg-code-loader").css("display","block");
299299
var obj = JSON.stringify({ "path": urlHandler.getFileName($(this).attr("data-patternpartial")) });
300-
document.getElementById("sg-viewport").contentWindow.postMessage(obj,codeViewer.targetOrigin);
300+
document.getElementById("sg-viewport").contentWindow.postMessage(JSON.parse(obj),codeViewer.targetOrigin);
301301
});
302302

303303
// show pattern state

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
<script>
1010
// handle injection of items from PHP
1111
var patternPartial = "{{ patternGroup }}-{{ patternName }}";
12-
var lineage = "{{ lineage }}";
12+
var lineage = [{{{ lineage }}}];
1313
var lineageR = "{{ lineageR }}";
14+
var patternState = "{{patternState}}"
15+
var cssEnabled = false; //TODO
1416
</script>
1517

1618
<script type="text/html" id="sg-pattern-html">

0 commit comments

Comments
 (0)