diff --git a/CHANGELOG b/CHANGELOG index b17f7fbdb..66d1bd4ec 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,11 +1,12 @@ THIS CHANGELOG IS AN ATTEMPT TO DOCUMENT CHANGES TO THIS PROJECT. -PL-node-v1.0.1 -- FIX: Fix issue where partials containing styleModifiers with integers were not found correctly under all circumstances -- FIX: Fix issue where excluded patterns were still rendered on the Pattern Lab site. Now they do not directly get rendered via the menu, view all links, or the styleguide, but are accessible for inclusion as pattern partials, and can be accessed via lineage. +PL-node-v1.1.0 +- FIX: Fixed issue where partials containing styleModifiers with integers were not found correctly under all circumstances +- FIX: Fixed issue where excluded patterns were still rendered on the Pattern Lab site. Now they do not directly get rendered via the menu, view all links, or the styleguide, but are accessible for inclusion as pattern partials, and can be accessed via lineage. - THX: Thanks @theorise for reporting these issues. - THX: Thanks @dmolsen for input on desired behavior. -- FIX: Fix issue where style modifier partials within list item blocks where not uniquely being applied. this seems like a regression. added a unit test with fix +- FIX: Fixed issue where style modifier partials within list item blocks where not uniquely being applied. this seems like a regression. added a unit test with fix +- ADD: Added fuzzy pattern matching support based on patternType-substring(patternName) to align with PL PHP PL-node-v1.0.0 - FIX: Resolve issue with not hiding underscored patterns. diff --git a/builder/lineage_hunter.js b/builder/lineage_hunter.js index 62321d5cb..7d4c78242 100644 --- a/builder/lineage_hunter.js +++ b/builder/lineage_hunter.js @@ -23,47 +23,41 @@ if(matches !== null){ matches.forEach(function(match, index, matches){ //strip out the template cruft - var foundPattern = match.replace("{{> ", "").replace(" }}", "").replace("{{>", "").replace("}}", ""); + var foundPatternKey = match.replace("{{> ", "").replace(" }}", "").replace("{{>", "").replace("}}", ""); // remove any potential pattern parameters. this and the above are rather brutish but I didn't want to do a regex at the time - if(foundPattern.indexOf('(') > 0){ - foundPattern = foundPattern.substring(0, foundPattern.indexOf('(')); + if(foundPatternKey.indexOf('(') > 0){ + foundPatternKey = foundPatternKey.substring(0, foundPatternKey.indexOf('(')); } - //add if it doesnt exist - if (pattern.lineageIndex.indexOf(foundPattern) === -1){ + //remove any potential stylemodifiers. + foundPatternKey = foundPatternKey.split(':')[0]; - pattern.lineageIndex.push(foundPattern); + //get the ancestorPattern + var ancestorPattern = pattern_assembler.get_pattern_by_key(foundPatternKey, patternlab); - patternlab.patterns.forEach(function(ancestorPattern, index, patterns){ + if (ancestorPattern && pattern.lineageIndex.indexOf(ancestorPattern.key) === -1){ - //find the pattern in question - var searchPattern = ancestorPattern.patternGroup + "-" + ancestorPattern.patternName; + //add it since it didnt exist + pattern.lineageIndex.push(ancestorPattern.key); + //create the more complex patternLineage object too + var l = { + "lineagePattern": ancestorPattern.key, + "lineagePath": "../../patterns/" + ancestorPattern.patternLink + }; + pattern.lineage.push(JSON.stringify(l)); - if(searchPattern === foundPattern){ - //create the more complex patternLineage object too - var l = { - "lineagePattern": foundPattern, - "lineagePath": "../../patterns/" + ancestorPattern.patternLink + //also, add the lineageR entry if it doesn't exist + if (ancestorPattern.lineageRIndex.indexOf(pattern.key) === -1){ + ancestorPattern.lineageRIndex.push(pattern.key); + + //create the more complex patternLineage object in reverse + var lr = { + "lineagePattern": pattern.key, + "lineagePath": "../../patterns/" + pattern.patternLink }; - pattern.lineage.push(JSON.stringify(l)); - - //also, add the lineageR entry if it doesn't exist - var patternLabel = pattern.patternGroup + "-" + pattern.patternName; - if (ancestorPattern.lineageRIndex.indexOf(patternLabel) === -1){ - ancestorPattern.lineageRIndex.push(patternLabel); - - //create the more complex patternLineage object in reverse - var lr = { - "lineagePattern": patternLabel, - "lineagePath": "../../patterns/" + pattern.patternLink - }; - ancestorPattern.lineageR.push(JSON.stringify(lr)); - } + ancestorPattern.lineageR.push(JSON.stringify(lr)); } - - }); - } }); } diff --git a/builder/pattern_assembler.js b/builder/pattern_assembler.js index 608289495..2bbcd1830 100644 --- a/builder/pattern_assembler.js +++ b/builder/pattern_assembler.js @@ -255,6 +255,17 @@ case patternlab.patterns[i].subdir + '/' + patternlab.patterns[i].fileName + '.mustache': return patternlab.patterns[i]; } + //look for exact key matches + if(key === patternlab.patterns[i].key){ + return patternlab.patterns[i]; + } + //return the fuzzy match within the type if it exists + var keyParts = key.split('-'), + keyType = keyParts[0], + keyName = keyParts.slice(1).join('-'); + if(patternlab.patterns[i].key.split('-')[0] === keyType && patternlab.patterns[i].key.indexOf(keyName) > -1){ + return patternlab.patterns[i]; + } } throw 'Could not find pattern with key ' + key; } diff --git a/test/lineage_hunter_tests.js b/test/lineage_hunter_tests.js index d773f6d6e..0cd6a4aea 100644 --- a/test/lineage_hunter_tests.js +++ b/test/lineage_hunter_tests.js @@ -4,7 +4,7 @@ var lh = require('../builder/lineage_hunter'); exports['lineage hunter '] = { - 'test lineage hunter finds lineage' : function(test){ + 'find_lineage - finds lineage' : function(test){ //setup current pattern from what we would have during execution var currentPattern = { @@ -19,6 +19,7 @@ "patternGroup": "organisms", "patternSubGroup": "organisms\\00-global", "flatPatternPath": "02-organisms\\00-global", + "key": "organisms-header", "patternState": "", "lineage": [], "lineageIndex": [], @@ -39,6 +40,7 @@ "patternGroup": "atoms", "patternSubGroup": "atoms\\03-images", "flatPatternPath": "00-atoms\\03-images", + "key": "atoms-logo", "patternState": "", "lineage": [], "lineageIndex": [], @@ -57,6 +59,7 @@ "patternGroup": "molecules", "patternSubGroup": "molecules\\05-navigation", "flatPatternPath": "01-molecules\\05-navigation", + "key": "molecules-primary-nav", "patternState": "", "lineage": [], "lineageIndex": [], @@ -75,6 +78,7 @@ "patternGroup": "molecules", "patternSubGroup": "molecules\\04-forms", "flatPatternPath": "01-molecules\\04-forms", + "key": "molecules-search", "patternState": "", "lineage": [], "lineageIndex": [], @@ -95,7 +99,7 @@ test.done(); }, - 'test lineage hunter finds lineage with spaced pattern parameters' : function(test){ + 'find_lineage - finds lineage with spaced pattern parameters' : function(test){ //setup current pattern from what we would have during execution var currentPattern = { "name": "01-molecules-01-toast-00-error", @@ -109,6 +113,7 @@ "patternGroup": "molecules", "patternSubGroup": "molecules\\01-toast", "flatPatternPath": "01-molecules\\01-toast", + "key": "molecules-error", "patternState": "", "lineage": [], "lineageIndex": [], @@ -129,6 +134,7 @@ "patternGroup": "atoms", "patternSubGroup": "atoms\\05-alerts", "flatPatternPath": "01-atoms\\05-alerts", + "key": "atoms-error", "patternState": "", "lineage": [], "lineageIndex": [], @@ -147,7 +153,7 @@ test.done(); }, - 'test lineage hunter finds lineage with unspaced pattern parameters' : function(test){ + 'find_lineage - finds lineage with unspaced pattern parameters' : function(test){ //setup current pattern from what we would have during execution var currentPattern = { "name": "01-molecules-01-toast-00-error", @@ -161,6 +167,7 @@ "patternGroup": "molecules", "patternSubGroup": "molecules\\01-toast", "flatPatternPath": "01-molecules\\01-toast", + "key": "molecules-error", "patternState": "", "lineage": [], "lineageIndex": [], @@ -181,6 +188,7 @@ "patternGroup": "atoms", "patternSubGroup": "atoms\\05-alerts", "flatPatternPath": "01-atoms\\05-alerts", + "key": "atoms-error", "patternState": "", "lineage": [], "lineageIndex": [], @@ -201,7 +209,169 @@ test.done(); }, - 'test lineage hunter does not apply lineage twice' : function(test){ + 'find_lineage - finds lineage with spaced styleModifier' : function(test){ + //setup current pattern from what we would have during execution + var currentPattern = { + "name": "01-molecules-01-toast-00-error", + "subdir": "01-molecules\\01-toast", + "filename": "00-error.mustache", + "data": null, + "template": "{{> atoms-error:foo }}", + "patternPartial": "{{> atoms-error:foo }}", + "patternName": "error", + "patternLink": "01-molecules-01-toast-00-error/01-molecules-01-toast-00-error.html", + "patternGroup": "molecules", + "patternSubGroup": "molecules\\01-toast", + "flatPatternPath": "01-molecules\\01-toast", + "key": "molecules-error", + "patternState": "", + "lineage": [], + "lineageIndex": [], + "lineageR": [], + "lineageRIndex": [] + }; + var patternlab = { + patterns: [ + { + "name": "01-atoms-05-alerts-00-error", + "subdir": "01-atoms\\05-alerts", + "filename": "00-error.mustache", + "data": null, + "template": "