From 0ff1cc6775686b137370db787e983ba8a8fa4cdd Mon Sep 17 00:00:00 2001 From: Abed Islam Date: Thu, 20 Jul 2017 18:54:35 -0400 Subject: [PATCH] Support for digits at start of pseudo pattern filename. Resolves https://github.com/pattern-lab/patternlab-php-core/issues/114 --- src/PatternLab/PatternData/Rule.php | 2 +- .../PatternData/Rules/PseudoPatternRule.php | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/PatternLab/PatternData/Rule.php b/src/PatternLab/PatternData/Rule.php index a7c3ab25..a266e404 100644 --- a/src/PatternLab/PatternData/Rule.php +++ b/src/PatternLab/PatternData/Rule.php @@ -103,7 +103,7 @@ protected function compareProp($name, $propCompare, $exact = false) { */ protected function getPatternName($pattern, $clean = true) { $patternBits = explode("-",$pattern,2); - $patternName = (((int)$patternBits[0] != 0) || ($patternBits[0] == '00')) ? $patternBits[1] : $pattern; + $patternName = (((int)$patternBits[0] != 0) || (preg_match('/^0+$/', $patternBits[0]) === 1)) ? $patternBits[1] : $pattern; return ($clean) ? (str_replace("-"," ",$patternName)) : $patternName; } diff --git a/src/PatternLab/PatternData/Rules/PseudoPatternRule.php b/src/PatternLab/PatternData/Rules/PseudoPatternRule.php index 426332e9..13da72d6 100644 --- a/src/PatternLab/PatternData/Rules/PseudoPatternRule.php +++ b/src/PatternLab/PatternData/Rules/PseudoPatternRule.php @@ -79,11 +79,21 @@ public function run($depth, $ext, $path, $pathName, $name) { // check the original pattern path. if it doesn't exist make a guess $patternPathOrig = PatternData::getPatternOption($patternBaseOrig,"pathName"); // 04-pages/00-homepage - $patternPathOrigDash = PatternData::getPatternOption($patternBaseOrig,"pathDash"); // 04-pages-00-homepage + $patternPathOrigDash = PatternData::getPatternOption($patternBaseOrig,"pathDash"); // 04-pages-00-homepage if (!$patternPathOrig) { - $patternPathOrigBits = explode("~",$pathName); - $patternPathOrig = $patternPathOrigBits[0]; // 04-pages/00-homepage - $patternPathOrigDash = str_replace($dirSep,"-",$patternPathOrig); // 04-pages-00-homepage + + if (($patternBase . $ext) != $patternFull) { + $patternPathOrig = $path . DIRECTORY_SEPARATOR . $patternBaseDash; // 04-pages/homepage + $patternPathOrigDash = str_replace($dirSep,"-",$patternPathOrig); // 04-pages-homepage + + if ( ! file_exists(Config::getOption("patternSourceDir").DIRECTORY_SEPARATOR.$patternPathOrig.'.'.Config::getOption("patternExtension"))) { + $patternPathOrig = $path . DIRECTORY_SEPARATOR . '_' . $patternBaseDash; // 04-pages/_homepage + } + } else { + $patternPathOrigBits = explode("~",$pathName); + $patternPathOrig = $patternPathOrigBits[0]; // 04-pages/00-homepage + $patternPathOrigDash = str_replace($dirSep,"-",$patternPathOrig); // 04-pages-00-homepage + } } // create a key for the data store