|
1 | 1 | /* |
2 | | - * patternlab-node - v0.15.1 - 2015 |
| 2 | + * patternlab-node - v1.0.0 - 2015 |
3 | 3 | * |
4 | 4 | * Brian Muenzenmeyer, and the web community. |
5 | 5 | * Licensed under the MIT license. |
|
21 | 21 | var config = fs.readJSONSync('./config.json'); |
22 | 22 |
|
23 | 23 | function setState(pattern, patternlab){ |
24 | | - if(patternlab.config.patternStates[pattern.patternName]){ |
| 24 | + if(patternlab.config.patternStates && patternlab.config.patternStates[pattern.patternName]){ |
25 | 25 | pattern.patternState = patternlab.config.patternStates[pattern.patternName]; |
26 | 26 | } else{ |
27 | 27 | pattern.patternState = ""; |
28 | 28 | } |
29 | 29 | } |
30 | 30 |
|
31 | 31 | function addPattern(pattern, patternlab){ |
| 32 | + //add the link to the global object |
32 | 33 | patternlab.data.link[pattern.patternGroup + '-' + pattern.patternName] = '/patterns/' + pattern.patternLink; |
33 | 34 |
|
34 | 35 | //only push to array if the array doesn't contain this pattern |
|
87 | 88 |
|
88 | 89 | //if file is named in the syntax for variants |
89 | 90 | if(patternEngines.isPseudoPatternJSON(filename)){ |
90 | | - //add current pattern to patternlab object with minimal data |
91 | | - //processPatternRecursive() will run find_pseudopatterns() to fill out |
92 | | - //the object in the next diveSync |
93 | | - addPattern(currentPattern, patternlab); |
94 | | - //no need to process further |
95 | 91 | return currentPattern; |
96 | 92 | } |
97 | 93 |
|
98 | 94 | //can ignore all non-supported files at this point |
99 | 95 | if(patternEngines.isFileExtensionSupported(ext) === false){ |
100 | | - if (config.debug) { |
101 | | - console.log('==================== FOUND NON-MUSTACHE FILE'); |
102 | | - } |
103 | 96 | return currentPattern; |
104 | 97 | } |
105 | 98 |
|
|
276 | 269 |
|
277 | 270 |
|
278 | 271 |
|
| 272 | + //look for pattern links included in data files. |
| 273 | + //these will be in the form of link.* WITHOUT {{}}, which would still be there from direct pattern inclusion |
| 274 | + function parseDataLinks(patternlab){ |
| 275 | + |
| 276 | + //loop through all patterns |
| 277 | + for (var i = 0; i < patternlab.patterns.length; i++){ |
| 278 | + var pattern = patternlab.patterns[i]; |
| 279 | + //look for link.* such as link.pages-blog as a value |
| 280 | + var linkRE = /link.[A-z0-9-_]+/g; |
| 281 | + //convert to string for easier searching |
| 282 | + var dataObjAsString = JSON.stringify(pattern.jsonFileData); |
| 283 | + var linkMatches = dataObjAsString.match(linkRE); |
| 284 | + |
| 285 | + //if no matches found, escape current loop iteration |
| 286 | + if(linkMatches === null) { continue; } |
| 287 | + |
| 288 | + for(var i = 0; i < linkMatches.length; i++){ |
| 289 | + //for each match, find the expanded link within the already constructed patternlab.data.link object |
| 290 | + var expandedLink = patternlab.data.link[linkMatches[i].split('.')[1]]; |
| 291 | + if(patternlab.config.debug){ |
| 292 | + console.log('expanded data link from ' + linkMatches[i] + ' to ' + expandedLink + ' inside ' + pattern.key); |
| 293 | + } |
| 294 | + //replace value with expandedLink on the pattern |
| 295 | + dataObjAsString = dataObjAsString.replace(linkMatches[i], expandedLink); |
| 296 | + } |
| 297 | + //write back to data on the pattern |
| 298 | + pattern.jsonFileData = JSON.parse(dataObjAsString); |
| 299 | + } |
| 300 | + } |
| 301 | + |
279 | 302 | return { |
280 | 303 | find_pattern_partials: function(pattern){ |
281 | 304 | return pattern.findPartials(); |
|
309 | 332 | }, |
310 | 333 | combine_listItems: function(patternlab){ |
311 | 334 | buildListItems(patternlab); |
| 335 | + }, |
| 336 | + parse_data_links: function(patternlab){ |
| 337 | + parseDataLinks(patternlab); |
312 | 338 | } |
313 | 339 | }; |
314 | 340 |
|
|
0 commit comments