From 338d8014165522907f000a3f0db63997629fe667 Mon Sep 17 00:00:00 2001 From: Salem Ghoweri Date: Sun, 20 Nov 2016 20:59:01 -0500 Subject: [PATCH 1/2] 1st pass at updating how PL template lineage matches are handled, even if the regex for a lineage matches up. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses an ongoing issue where the pattern viewer doesn’t correctly display matched lineages of Twig partials when the @ namespace full path is used (vs the shorthand PL path syntax). --- .../PatternData/Helpers/LineageHelper.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/PatternLab/PatternData/Helpers/LineageHelper.php b/src/PatternLab/PatternData/Helpers/LineageHelper.php index 61185d65..11ab4ae5 100644 --- a/src/PatternLab/PatternData/Helpers/LineageHelper.php +++ b/src/PatternLab/PatternData/Helpers/LineageHelper.php @@ -53,6 +53,40 @@ public function run() { foreach ($foundLineages as $lineage) { + //Handle instances where we aren't or can't use the shorthand PL path reference in templates, specifically in Twig / D8 when we need to use Twig namespaces in our template paths. + if ($lineage[0] == '@'){ + + //Grab the template extension getting used so we can strip it off down below. + $patternExtension = Config::getOption("patternExtension"); + + //Store the length of our broken up path for reference below + $length = count($lineageParts); + + //Strip off the @ sign at the beginning of our $lineage string. + $lineage = ltrim($lineage, '@'); + //Break apart the full lineage path based on any slashes that may exist. + $lineageParts = explode('/', $lineage); + + //Store the first part of the string up to the first slash "/" + $patternType = $lineageParts[0]; + + //Now grab the last part of the pattern key, based on the length of the path we previously exploded. + $patternName = $lineageParts[$length - 1]; + + //Remove any "_" from pattern Name. + $patternName = ltrim($patternName, '_'); + + //Remove any potential prefixed numbers or number + dash combos on our Pattern Name. + $patternName = preg_replace('/^[0-9\-]+/', '', $patternName); + + //Strip off the pattern path extension (.twig, .mustache, etc) + $patternName = explode('.' . $patternExtension, $patternName); + $patternName = $patternName[0]; + + //Finally, re-assign $lineage to the default PL pattern key. + $lineage = $patternType . "-" . $patternName; + } + if (PatternData::getOption($lineage)) { $patternLineages[] = array("lineagePattern" => $lineage, From 7018eff1c8c00ea383ad050e240d9cb91af9f756 Mon Sep 17 00:00:00 2001 From: Salem Ghoweri Date: Wed, 30 Nov 2016 22:34:09 -0500 Subject: [PATCH 2/2] Fixing an issue with the lineage parsing logic to account for instances where the matched pattern might be hidden (and subsequently not match properly) --- .../PatternData/Helpers/LineageHelper.php | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/PatternLab/PatternData/Helpers/LineageHelper.php b/src/PatternLab/PatternData/Helpers/LineageHelper.php index 11ab4ae5..3f1cdc90 100644 --- a/src/PatternLab/PatternData/Helpers/LineageHelper.php +++ b/src/PatternLab/PatternData/Helpers/LineageHelper.php @@ -59,14 +59,15 @@ public function run() { //Grab the template extension getting used so we can strip it off down below. $patternExtension = Config::getOption("patternExtension"); - //Store the length of our broken up path for reference below - $length = count($lineageParts); - //Strip off the @ sign at the beginning of our $lineage string. $lineage = ltrim($lineage, '@'); + //Break apart the full lineage path based on any slashes that may exist. $lineageParts = explode('/', $lineage); + //Store the length of our broken up path for reference below + $length = count($lineageParts); + //Store the first part of the string up to the first slash "/" $patternType = $lineageParts[0]; @@ -79,9 +80,18 @@ public function run() { //Remove any potential prefixed numbers or number + dash combos on our Pattern Name. $patternName = preg_replace('/^[0-9\-]+/', '', $patternName); - //Strip off the pattern path extension (.twig, .mustache, etc) - $patternName = explode('.' . $patternExtension, $patternName); - $patternName = $patternName[0]; + //Flag any "_" hidden patterns so we skip over for now. + if ($patternName[0] == '_'){ + $hidden = true; + } + + //Strip off the pattern path extension (.twig, .mustache, etc) if it exists. + $patternNameStripped = explode('.' . $patternExtension, $patternName); + + // If the pattern name parsed had an extension, re-assign our Pattern Name to that. + if (count($patternNameStripped) > 1){ + $patternName = $patternNameStripped[0]; + } //Finally, re-assign $lineage to the default PL pattern key. $lineage = $patternType . "-" . $patternName; @@ -94,7 +104,7 @@ public function run() { } else { - if (strpos($lineage, '/') === false) { + if (strpos($lineage, '/') === false && !$hidden) { $fileName = $patternStoreData["pathName"].".".$patternExtension; Console::writeWarning("you may have a typo in ".$fileName.". `".$lineage."` is not a valid pattern..."); }