Skip to content

Commit ddfd363

Browse files
committed
Support for pattern link.* shortcut inside pattern data objects.
Unit test to cover this Resolves #171 Marking this version 1.0.0 - having achieved broad feature parity with PL PHP v1
1 parent a66d0a8 commit ddfd363

19 files changed

+144
-15
lines changed

CHANGELOG

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
THIS CHANGELOG IS AN ATTEMPT TO DOCUMENT CHANGES TO THIS PROJECT.
22

3-
PL-node-v0.16.0
3+
PL-node-v1.0.0
44
- FIX: Resolve issue with not hiding underscored patterns.
55
- THX: Thanks @ivancamilov for reporting this regression.
66
- FIX: Fix misapplied error input class
@@ -11,6 +11,9 @@ PL-node-v0.16.0
1111
- ADD: Added unit tests for pattern states and pseudopatterns
1212
- CHG: Changed pseudopattern generation to use config.patterns.source directory instead of hardcode
1313
- CHG: Explicitly sorting patterns by name prior to building the UI
14+
- ADD: Added ability to specify link.* urls inside data objects
15+
- CHG: Incremented version to 1.0.0. Achieved near-parity with PL PHP 1!
16+
- THX: Thanks to each and every person who cared about Pattern Lab Node! - Brian
1417

1518
PL-node-v0.15.1
1619
- FIX: Resolve issue with styleModifiers not being replaced when the partial has spaces in it.

builder/lineage_hunter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v0.16.0 - 2015
2+
* patternlab-node - v1.0.0 - 2015
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.

builder/list_item_hunter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v0.16.0 - 2015
2+
* patternlab-node - v1.0.0 - 2015
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.

builder/media_hunter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v0.16.0 - 2015
2+
* patternlab-node - v1.0.0 - 2015
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.

builder/object_factory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v0.16.0 - 2015
2+
* patternlab-node - v1.0.0 - 2015
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.

builder/parameter_hunter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v0.16.0 - 2015
2+
* patternlab-node - v1.0.0 - 2015
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.

builder/pattern_assembler.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v0.16.0 - 2015
2+
* patternlab-node - v1.0.0 - 2015
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.
@@ -54,6 +54,7 @@
5454
}
5555

5656
function addPattern(pattern, patternlab){
57+
//add the link to the global object
5758
patternlab.data.link[pattern.patternGroup + '-' + pattern.patternName] = '/patterns/' + pattern.patternLink;
5859

5960
//only push to array if the array doesn't contain this pattern
@@ -317,6 +318,36 @@
317318
return o;
318319
}
319320

321+
//look for pattern links included in data files.
322+
//these will be in the form of link.* WITHOUT {{}}, which would still be there from direct pattern inclusion
323+
function parseDataLinks(patternlab){
324+
325+
//loop through all patterns
326+
for (var i = 0; i < patternlab.patterns.length; i++){
327+
var pattern = patternlab.patterns[i];
328+
//look for link.* such as link.pages-blog as a value
329+
var linkRE = /link.[A-z0-9-_]+/g;
330+
//convert to string for easier searching
331+
var dataObjAsString = JSON.stringify(pattern.jsonFileData);
332+
var linkMatches = dataObjAsString.match(linkRE);
333+
334+
//if no matches found, escape current loop iteration
335+
if(linkMatches === null) { continue; }
336+
337+
for(var i = 0; i < linkMatches.length; i++){
338+
//for each match, find the expanded link within the already constructed patternlab.data.link object
339+
var expandedLink = patternlab.data.link[linkMatches[i].split('.')[1]];
340+
if(patternlab.config.debug){
341+
console.log('expanded data link from ' + linkMatches[i] + ' to ' + expandedLink + ' inside ' + pattern.key);
342+
}
343+
//replace value with expandedLink on the pattern
344+
dataObjAsString = dataObjAsString.replace(linkMatches[i], expandedLink);
345+
}
346+
//write back to data on the pattern
347+
pattern.jsonFileData = JSON.parse(dataObjAsString);
348+
}
349+
}
350+
320351
return {
321352
find_pattern_partials: function(pattern){
322353
return findPartials(pattern);
@@ -356,6 +387,9 @@
356387
},
357388
is_object_empty: function(obj){
358389
return isObjectEmpty(obj);
390+
},
391+
parse_data_links: function(patternlab){
392+
parseDataLinks(patternlab);
359393
}
360394
};
361395

builder/pattern_exporter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v0.16.0 - 2015
2+
* patternlab-node - v1.0.0 - 2015
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.

builder/patternlab.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v0.16.0 - 2015
2+
* patternlab-node - v1.0.0 - 2015
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.
@@ -91,6 +91,10 @@ var patternlab_engine = function () {
9191
pattern_assembler.process_pattern_iterative(file.substring(2), patternlab);
9292
});
9393

94+
//now that all the main patterns are known, look for any links that might be within data and expand them
95+
//we need to do this before expanding patterns & partials into extendedTemplates, otherwise we could lose the data -> partial reference
96+
pattern_assembler.parse_data_links(patternlab);
97+
9498
//diveSync again to recursively include partials, filling out the
9599
//extendedTemplate property of the patternlab.patterns elements
96100
diveSync(patterns_dir, {
@@ -124,6 +128,7 @@ var patternlab_engine = function () {
124128
var allData = JSON.parse(JSON.stringify(patternlab.data));
125129
allData = pattern_assembler.merge_data(allData, pattern.jsonFileData);
126130

131+
//render the extendedTemplate with all data
127132
pattern.patternPartial = pattern_assembler.renderPattern(pattern.extendedTemplate, allData);
128133

129134
//add footer info before writing

builder/patternlab_grunt.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v0.16.0 - 2015
2+
* patternlab-node - v1.0.0 - 2015
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.

0 commit comments

Comments
 (0)