From c976fa4cbffac7a67c41df43f47899d09a965a49 Mon Sep 17 00:00:00 2001 From: Dave Olsen Date: Thu, 28 Jul 2016 17:12:01 -0400 Subject: [PATCH 01/14] making sure pattern type properly loads globalData var --- src/PatternLab/Builder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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)); From 7dd6d483c69b4684173247f9673e907621311af4 Mon Sep 17 00:00:00 2001 From: Dave Olsen Date: Thu, 28 Jul 2016 17:21:37 -0400 Subject: [PATCH 02/14] install assets and save path appropriately --- src/PatternLab/InstallerUtil.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/PatternLab/InstallerUtil.php b/src/PatternLab/InstallerUtil.php index 66a3fab5..fb934e4f 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)); } } From 884c9952ccba72e3b42afd29840a42f642e22a41 Mon Sep 17 00:00:00 2001 From: Evan Lovely Date: Mon, 31 Oct 2016 12:23:36 -0700 Subject: [PATCH 03/14] Updating global data to use `yml` or `yaml` --- src/PatternLab/Data.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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); From 44c0dd0caa5ddd63a7b298ab594d3f948a08da31 Mon Sep 17 00:00:00 2001 From: Salem Ghoweri Date: Thu, 27 Apr 2017 13:31:04 -0400 Subject: [PATCH 04/14] Fixing extra closing parentheses so dev branch works. Addresses https://github.com/pattern-lab/patternlab-php-core/pull/87 --- src/PatternLab/InstallerUtil.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PatternLab/InstallerUtil.php b/src/PatternLab/InstallerUtil.php index fb934e4f..fcc7fa99 100644 --- a/src/PatternLab/InstallerUtil.php +++ b/src/PatternLab/InstallerUtil.php @@ -350,7 +350,7 @@ protected static function parseComponentList($packageName,$sourceBase,$destinati foreach ($finder as $file) { $ext = $file->getExtension(); - $pathName = $file->getPathname()); + $pathName = $file->getPathname(); if ($ext == "css") { $componentTypes["stylesheets"][] = str_replace(DIRECTORY_SEPARATOR,"/",str_replace($sourceBase.$source,$destination,$pathName)); From d7506a09a188ed6ae3cc3fb420078d569758dbb8 Mon Sep 17 00:00:00 2001 From: Salem Ghoweri Date: Tue, 9 May 2017 22:57:33 -0400 Subject: [PATCH 05/14] Adding in lineage fix for PL when using Twig templates + line by line comments to explain my PHP chicken scratch. Addresses existing open issue https://github.com/drupal-pattern-lab/patternlab-php-core/issues/3 and corresponds with the 2nd half of work mentioned in https://github.com/drupal-pattern-lab/patternengine-php-twig/pull/1 --- .../PatternData/Helpers/LineageHelper.php | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) 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, From 505f32c35fdd899b986504a9a1524e1351d24256 Mon Sep 17 00:00:00 2001 From: Evan Lovely Date: Wed, 24 May 2017 11:06:27 -0700 Subject: [PATCH 06/14] updating composer to use Drupal Pattern Lab name --- composer.json | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 1deda66d..1d3339b3 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,8 @@ { - "name": "pattern-lab/core", + "name": "drupal-pattern-lab/core", "description": "The core functionality for Pattern Lab.", "keywords": ["pattern lab", "styleguide", "style guide", "atomic", "atomic design"], - "homepage": "http://patternlab.io", + "homepage": "http://drupal-pattern-lab.github.io", "license": "MIT", "authors": [ { @@ -18,9 +18,8 @@ } ], "support": { - "issues": "https://github.com/pattern-lab/patternlab-php-core/issues", - "wiki": "http://patternlab.io/docs/", - "source": "https://github.com/pattern-lab/patternlab-php-core/releases" + "issues": "https://github.com/drupal-pattern-lab/patternlab-php-core/issues", + "source": "https://github.com/drupal-pattern-lab/patternlab-php-core/releases" }, "autoload": { "psr-0": { From 8a51a732714a8e4809e62b5deba5618c5f1e9087 Mon Sep 17 00:00:00 2001 From: Evan Lovely Date: Wed, 24 May 2017 11:50:13 -0700 Subject: [PATCH 07/14] updating config path to use our vendor name --- src/PatternLab/Config.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PatternLab/Config.php b/src/PatternLab/Config.php index b07e90e3..a8ea4879 100644 --- a/src/PatternLab/Config.php +++ b/src/PatternLab/Config.php @@ -129,7 +129,8 @@ public static function init($baseDir = "", $verbose = true) { self::$userConfigDirDash = self::$options["baseDir"].self::$userConfigDirDash; self::$userConfigDir = (is_dir(self::$userConfigDirDash)) ? self::$userConfigDirDash : self::$userConfigDirClean; self::$userConfigPath = self::$userConfigDir.DIRECTORY_SEPARATOR.self::$userConfig; - self::$plConfigPath = self::$options["baseDir"]."vendor/pattern-lab/core/".self::$plConfigPath; + // @todo Make folder name (i.e. `drupal-pattern-lab`) a variable + self::$plConfigPath = self::$options["baseDir"]."vendor/drupal-pattern-lab/core/".self::$plConfigPath; // can't add __DIR__ above so adding here if (!is_dir(self::$userConfigDir)) { From d45a33451359a48234482c80166300dc1f11a99d Mon Sep 17 00:00:00 2001 From: Evan Lovely Date: Thu, 25 May 2017 15:55:50 -0700 Subject: [PATCH 08/14] Revert "updating config path to use our vendor name" This reverts commit 8a51a732714a8e4809e62b5deba5618c5f1e9087. --- src/PatternLab/Config.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/PatternLab/Config.php b/src/PatternLab/Config.php index a8ea4879..b07e90e3 100644 --- a/src/PatternLab/Config.php +++ b/src/PatternLab/Config.php @@ -129,8 +129,7 @@ public static function init($baseDir = "", $verbose = true) { self::$userConfigDirDash = self::$options["baseDir"].self::$userConfigDirDash; self::$userConfigDir = (is_dir(self::$userConfigDirDash)) ? self::$userConfigDirDash : self::$userConfigDirClean; self::$userConfigPath = self::$userConfigDir.DIRECTORY_SEPARATOR.self::$userConfig; - // @todo Make folder name (i.e. `drupal-pattern-lab`) a variable - self::$plConfigPath = self::$options["baseDir"]."vendor/drupal-pattern-lab/core/".self::$plConfigPath; + self::$plConfigPath = self::$options["baseDir"]."vendor/pattern-lab/core/".self::$plConfigPath; // can't add __DIR__ above so adding here if (!is_dir(self::$userConfigDir)) { From b6c7409c0f331db0c3b89586a22426b99bcc5da4 Mon Sep 17 00:00:00 2001 From: Evan Lovely Date: Thu, 25 May 2017 15:55:58 -0700 Subject: [PATCH 09/14] Revert "updating composer to use Drupal Pattern Lab name" This reverts commit 505f32c35fdd899b986504a9a1524e1351d24256. --- composer.json | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 1d3339b3..1deda66d 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,8 @@ { - "name": "drupal-pattern-lab/core", + "name": "pattern-lab/core", "description": "The core functionality for Pattern Lab.", "keywords": ["pattern lab", "styleguide", "style guide", "atomic", "atomic design"], - "homepage": "http://drupal-pattern-lab.github.io", + "homepage": "http://patternlab.io", "license": "MIT", "authors": [ { @@ -18,8 +18,9 @@ } ], "support": { - "issues": "https://github.com/drupal-pattern-lab/patternlab-php-core/issues", - "source": "https://github.com/drupal-pattern-lab/patternlab-php-core/releases" + "issues": "https://github.com/pattern-lab/patternlab-php-core/issues", + "wiki": "http://patternlab.io/docs/", + "source": "https://github.com/pattern-lab/patternlab-php-core/releases" }, "autoload": { "psr-0": { From ad10d44905776fb161e5be31af5b8ed1189614e3 Mon Sep 17 00:00:00 2001 From: Evan Lovely Date: Thu, 25 May 2017 16:12:39 -0700 Subject: [PATCH 10/14] updating info --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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": { From 741ebb74c5aa19646a4e127514a22bca55cd2d71 Mon Sep 17 00:00:00 2001 From: Aleksi Peebles Date: Mon, 19 Jun 2017 15:08:21 +0300 Subject: [PATCH 11/14] Don't overwrite nameClean if it has already been set --- src/PatternLab/PatternData/Rules/PseudoPatternRule.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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); } From 4ae8878d7e5d3fb68adc2168c661c7fd63a4d2bf Mon Sep 17 00:00:00 2001 From: Aleksi Peebles Date: Mon, 19 Jun 2017 19:54:13 +0300 Subject: [PATCH 12/14] Replace possible dots in pattern names with dashes --- src/PatternLab/PatternData/Rule.php | 3 +++ 1 file changed, 3 insertions(+) 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; } From 60fc319c66c28ec086799fb1b47964e0ee6a6c01 Mon Sep 17 00:00:00 2001 From: Salem Ghoweri Date: Sat, 1 Jul 2017 19:21:20 -0400 Subject: [PATCH 13/14] Enabling the ability for Pattern Lab to follow any symlinks that may exist when scanning the pattern source directory for patterns; adds the RecursiveIteratorIterator flag to follow symbolic links while still continuing to skip dots (. and ..). This opens the door for some creative workarounds to the rigid way Pattern Lab expects pattern templates to be organized at the file system level + how the physical path to a pattern determines how it's organized in Pattern Lab... https://github.com/pattern-lab/patternlab-php-core/issues/28 --- src/PatternLab/PatternData.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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(); From bb831963c56c7ed44eb8f6095f1e10f3d7fb8627 Mon Sep 17 00:00:00 2001 From: Salem Ghoweri Date: Sat, 2 Sep 2017 20:35:24 -0400 Subject: [PATCH 14/14] feat: adding optional ability for markdown files to specify which patternType it should be associated via frontmatter. --- .../PatternData/Rules/DocumentationRule.php | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) 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;