diff --git a/composer.json b/composer.json index 1deda66d..56458f0d 100644 --- a/composer.json +++ b/composer.json @@ -18,9 +18,9 @@ } ], "support": { - "issues": "https://github.com/pattern-lab/patternlab-php-core/issues", + "issues": "https://github.com/drupal-pattern-lab/patternlab-php-core/issues", "wiki": "http://patternlab.io/docs/", - "source": "https://github.com/pattern-lab/patternlab-php-core/releases" + "source": "https://github.com/drupal-pattern-lab/patternlab-php-core/releases" }, "autoload": { "psr-0": { diff --git a/src/PatternLab/Builder.php b/src/PatternLab/Builder.php index a869e329..fb91068f 100644 --- a/src/PatternLab/Builder.php +++ b/src/PatternLab/Builder.php @@ -391,8 +391,8 @@ protected function generateViewAllPages() { $patternData["patternPartial"] = "viewall-".$patternStoreData["nameDash"]."-all"; // add the pattern lab specific mark-up - $partials["patternLabHead"] = $stringLoader->render(array("string" => $htmlHead, "data" => array("cacheBuster" => $partials["cacheBuster"]))); - $partials["patternLabFoot"] = $stringLoader->render(array("string" => $htmlFoot, "data" => array("cacheBuster" => $partials["cacheBuster"], "patternData" => json_encode($patternData)))); + $globalData["patternLabHead"] = $stringLoader->render(array("string" => $htmlHead, "data" => array("cacheBuster" => $partials["cacheBuster"]))); + $globalData["patternLabFoot"] = $stringLoader->render(array("string" => $htmlFoot, "data" => array("cacheBuster" => $partials["cacheBuster"], "patternData" => json_encode($patternData)))); // render the parts and join them $header = $patternLoader->render(array("pattern" => $patternHead, "data" => $globalData)); diff --git a/src/PatternLab/Data.php b/src/PatternLab/Data.php index e0da3fc7..75b05654 100644 --- a/src/PatternLab/Data.php +++ b/src/PatternLab/Data.php @@ -125,7 +125,7 @@ public static function gather($options = array()) { $pathName = $file->getPathname(); $pathNameClean = str_replace($sourceDir."/","",$pathName); - if (!$hidden && (($ext == "json") || ($ext == "yaml"))) { + if (!$hidden && (($ext == "json") || ($ext == "yaml") || ($ext == "yml"))) { if ($isListItems === false) { @@ -137,7 +137,7 @@ public static function gather($options = array()) { JSON::lastErrorMsg($pathNameClean,$jsonErrorMessage,$data); } - } else if ($ext == "yaml") { + } else if (($ext == "yaml") || ($ext == "yml")) { $file = file_get_contents($pathName); diff --git a/src/PatternLab/InstallerUtil.php b/src/PatternLab/InstallerUtil.php index 66a3fab5..fcc7fa99 100644 --- a/src/PatternLab/InstallerUtil.php +++ b/src/PatternLab/InstallerUtil.php @@ -349,14 +349,15 @@ protected static function parseComponentList($packageName,$sourceBase,$destinati // iterate over the returned objects foreach ($finder as $file) { - $ext = $file->getExtension(); + $ext = $file->getExtension(); + $pathName = $file->getPathname(); if ($ext == "css") { - $componentTypes["stylesheets"][] = str_replace($sourceBase.$source,$destination,$file->getPathname()); + $componentTypes["stylesheets"][] = str_replace(DIRECTORY_SEPARATOR,"/",str_replace($sourceBase.$source,$destination,$pathName)); } else if ($ext == "js") { - $componentTypes["javascripts"][] = str_replace($sourceBase.$source,$destination,$file->getPathname()); + $componentTypes["javascripts"][] = str_replace(DIRECTORY_SEPARATOR,"/",str_replace($sourceBase.$source,$destination,$pathName)); } else if ($ext == $templateExtension) { - $componentTypes["templates"][] = str_replace($sourceBase.$source,$destination,$file->getPathname()); + $componentTypes["templates"][] = str_replace(DIRECTORY_SEPARATOR,"/",str_replace($sourceBase.$source,$destination,$pathName)); } } diff --git a/src/PatternLab/PatternData.php b/src/PatternLab/PatternData.php index 39129553..7980305c 100644 --- a/src/PatternLab/PatternData.php +++ b/src/PatternLab/PatternData.php @@ -116,15 +116,14 @@ public static function gather($options = array()) { if (!is_dir(Config::getOption("patternSourceDir"))) { Console::writeError("having patterns is important. please make sure you've installed a starterkit and/or that ".Console::getHumanReadablePath(Config::getOption("patternSourceDir"))." exists..."); } - $patternObjects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(Config::getOption("patternSourceDir")), \RecursiveIteratorIterator::SELF_FIRST); - $patternObjects->setFlags(\FilesystemIterator::SKIP_DOTS); + + $patternSourceDir = Config::getOption("patternSourceDir"); + $patternObjects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($patternSourceDir, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS | \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST); // sort the returned objects $patternObjects = iterator_to_array($patternObjects); ksort($patternObjects); - $patternSourceDir = Config::getOption("patternSourceDir"); - foreach ($patternObjects as $name => $object) { $ext = $object->getExtension(); diff --git a/src/PatternLab/PatternData/Helpers/LineageHelper.php b/src/PatternLab/PatternData/Helpers/LineageHelper.php index 61185d65..1d5676e5 100644 --- a/src/PatternLab/PatternData/Helpers/LineageHelper.php +++ b/src/PatternLab/PatternData/Helpers/LineageHelper.php @@ -53,6 +53,51 @@ public function run() { foreach ($foundLineages as $lineage) { + /** + * Fix for Pattern Lab Lineages when using Twig Namespaces. + * Converts the full file path to PL-friendly shorthand so + * they are internally registered. + * + * 1. Only 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. + * 2. Strip off the @ sign at the beginning of our $lineage string. + * 3. Break apart the full lineage path based on any slashes that + * may exist. + * 4. Store the length of our broken up path for reference below + * 5. Store the first part of the string up to the first slash "/" + * 6. Now grab the last part of the pattern key, based on the length + * of the path we previously exploded. + * 7. Remove any "_" from pattern Name. + * 8. Remove any potential prefixed numbers or number + dash + * combos on our Pattern Name. + * 9. Strip off the pattern path extension (.twig, + * .mustache, etc) if it exists. + * 10. If the pattern name parsed had an extension, + * re-assign our Pattern Name to that. + * 11. Finally, re-assign $lineage to the default PL pattern key. + */ + + if ($lineage[0] == '@') { /* [1] */ + $lineage = ltrim($lineage, '@'); /* [2] */ + $lineageParts = explode('/', $lineage); /* [3] */ + $length = count($lineageParts); /* [4] */ + $patternType = $lineageParts[0]; /* [5] */ + + $patternName = $lineageParts[$length - 1]; /* [6] */ + $patternName = ltrim($patternName, '_'); /* [7] */ + $patternName = preg_replace('/^[0-9\-]+/', '', + $patternName); /* [8] */ + + $patternNameStripped = explode('.' . $patternExtension, $patternName); /* [9] */ + + if (count($patternNameStripped) > 1) { /* [10] */ + $patternName = $patternNameStripped[0]; + } + $lineage = $patternType . "-" . $patternName; /* [11] */ + } + if (PatternData::getOption($lineage)) { $patternLineages[] = array("lineagePattern" => $lineage, diff --git a/src/PatternLab/PatternData/Rule.php b/src/PatternLab/PatternData/Rule.php index a7c3ab25..bbb500b4 100644 --- a/src/PatternLab/PatternData/Rule.php +++ b/src/PatternLab/PatternData/Rule.php @@ -104,6 +104,9 @@ 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; + // replace possible dots with dashes. pattern names cannot contain dots + // since they are used as id/class names in the styleguidekit. + $patternName = str_replace('.', '-', $patternName); return ($clean) ? (str_replace("-"," ",$patternName)) : $patternName; } diff --git a/src/PatternLab/PatternData/Rules/DocumentationRule.php b/src/PatternLab/PatternData/Rules/DocumentationRule.php index 4e9ef3fa..bbea75cb 100644 --- a/src/PatternLab/PatternData/Rules/DocumentationRule.php +++ b/src/PatternLab/PatternData/Rules/DocumentationRule.php @@ -31,9 +31,20 @@ public function __construct($options) { $this->ignoreProp = ""; } - + public function run($depth, $ext, $path, $pathName, $name) { - + // default vars + $patternSourceDir = Config::getOption("patternSourceDir"); + + // parse data + $text = file_get_contents($patternSourceDir.DIRECTORY_SEPARATOR.$pathName); + list($yaml,$markdown) = Documentation::parse($text); + + if (isset($yaml["patternType"])) { + $name = $yaml["patternType"]; + unset($yaml["patternType"]); + } + // load default vars $patternType = PatternData::getPatternType(); $patternTypeDash = PatternData::getPatternTypeDash(); @@ -43,14 +54,7 @@ public function run($depth, $ext, $path, $pathName, $name) { $doc = str_replace(".".$this->extProp,"",$name); // 00-colors $docDash = $this->getPatternName(str_replace("_","",$doc),false); // colors $docPartial = $patternTypeDash."-".$docDash; - - // default vars - $patternSourceDir = Config::getOption("patternSourceDir"); - - // parse data - $text = file_get_contents($patternSourceDir.DIRECTORY_SEPARATOR.$pathName); - list($yaml,$markdown) = Documentation::parse($text); - + // grab the title and unset it from the yaml so it doesn't get duped in the meta if (isset($yaml["title"])) { $title = $yaml["title"]; @@ -68,9 +72,8 @@ public function run($depth, $ext, $path, $pathName, $name) { break; } } - } - + $category = ($patternSubtypeDoc) ? "patternSubtype" : "pattern"; $patternStoreKey = ($patternSubtypeDoc) ? $docPartial."-plsubtype" : $docPartial; diff --git a/src/PatternLab/PatternData/Rules/PseudoPatternRule.php b/src/PatternLab/PatternData/Rules/PseudoPatternRule.php index 426332e9..8575790c 100644 --- a/src/PatternLab/PatternData/Rules/PseudoPatternRule.php +++ b/src/PatternLab/PatternData/Rules/PseudoPatternRule.php @@ -171,7 +171,14 @@ public function run($depth, $ext, $path, $pathName, $name) { $patternStoreData["data"] = is_array($patternData) ? array_replace_recursive($patternDataBase, $patternData) : $patternDataBase; // if the pattern data store already exists make sure it is merged and overwrites this data - $patternStoreData = (PatternData::checkOption($patternStoreKey)) ? array_replace_recursive(PatternData::getOption($patternStoreKey),$patternStoreData) : $patternStoreData; + if (PatternData::checkOption($patternStoreKey)) { + $existingData = PatternData::getOption($patternStoreKey); + if (array_key_exists('nameClean', $existingData)) { + // don't overwrite nameClean + unset($patternStoreData['nameClean']); + } + $patternStoreData = array_replace_recursive($existingData, $patternStoreData); + } PatternData::setOption($patternStoreKey, $patternStoreData); }