From c976fa4cbffac7a67c41df43f47899d09a965a49 Mon Sep 17 00:00:00 2001 From: Dave Olsen Date: Thu, 28 Jul 2016 17:12:01 -0400 Subject: [PATCH 01/18] 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/18] 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/18] 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/18] 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/18] 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/18] 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/18] 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/18] 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/18] 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/18] 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/18] 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/18] 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/18] 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 b8af4a4b1fbe938e3c2bbf166e2d4fca91380da8 Mon Sep 17 00:00:00 2001 From: Salem Ghoweri Date: Sat, 26 Aug 2017 12:54:15 -0400 Subject: [PATCH 14/18] Working solution to automatically regenerate any Styleguidekit Assets Default files in the public dir if entire directory gets wiped. Solves https://github.com/drupal-pattern-lab/patternlab-php-core/issues/14 --- src/PatternLab/Builder.php | 225 ++++++++++++++++++++++--------------- 1 file changed, 133 insertions(+), 92 deletions(-) diff --git a/src/PatternLab/Builder.php b/src/PatternLab/Builder.php index fb91068f..a7ac535d 100644 --- a/src/PatternLab/Builder.php +++ b/src/PatternLab/Builder.php @@ -29,77 +29,118 @@ use \Symfony\Component\Finder\Finder; class Builder { - + /** * When initializing the Builder class make sure the template helper is set-up */ public function __construct() { - + // set-up the pattern engine PatternEngine::init(); - + // set-up the various attributes for rendering templates Template::init(); - + } - + /** * Generates the annotations js file */ protected function generateAnnotations() { - + // set-up the dispatcher $dispatcherInstance = Dispatcher::getInstance(); - + // note the start of the operation $dispatcherInstance->dispatch("builder.generateAnnotationsStart"); - + // default var $publicDir = Config::getOption("publicDir"); - + // encode the content so it can be written out $json = json_encode(Annotations::get()); - + // make sure annotations/ exists if (!is_dir($publicDir."/annotations")) { mkdir($publicDir."/annotations"); } - + // write out the new annotations.js file file_put_contents($publicDir."/annotations/annotations.js","var comments = ".$json.";"); - + // note the end of the operation $dispatcherInstance->dispatch("builder.generateAnnotationsEnd"); - + } - + /** * Generates the data that powers the index page */ protected function generateIndex() { - - // bomb if missing index.html + + /** + * Handle missing index.html. Solves https://github.com/drupal-pattern-lab/patternlab-php-core/issues/14 + * Could also be used to re-add missing styleguidekit assets with a few edits? + * + * 1. @TODO: What would be a better way to find our base vendor directory from here? + * 2. Locate the current theme's styleguidekit assets via the patternlab-styleguidekit `type` in composer.json + * 3. @TODO: Figure out a better way to future-proof path resolution for styleguidekit `dist` folder + * 4. Recusirively copy files from styleguidekit to publicDir via https://stackoverflow.com/a/7775949 + * 5. Make sure we only try to create new directories if they don't already exist + * 6. Only copy files if they are missing (vs changed, etc) + */ if (!file_exists(Config::getOption("publicDir")."/index.html")) { $index = Console::getHumanReadablePath(Config::getOption("publicDir")).DIRECTORY_SEPARATOR."index.html"; - Console::writeError("".$index." is missing. grab a copy from your StyleguideKit..."); + Console::writeWarning($index . " is missing. No biggie. Grabbing a copy from your StyleguideKit..."); + + $finder = new Finder(); + $base = __DIR__."/../../../"; /* [1] */ + $finder->files()->name("composer.json")->in($base)->contains('patternlab-styleguidekit')->sortByName(); /* [2] */ + + foreach ($finder as $file) { + $src = dirname($file->getRealPath()) . DIRECTORY_SEPARATOR . 'dist'; /* [3] */ + $dest= Config::getOption("publicDir"); + + if (is_dir($src)){ + + if(!is_dir($dest)) { + mkdir($dest, 0755); + } + + foreach ( /* [4] */ + $iterator = new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator($src, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item + ) { + if ($item->isDir()) { + if(!is_dir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName())) { /* [5] */ + mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName()); + } + } else { + if(!file_exists($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName())) { /* [6] */ + copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName()); + } + } + } + } + } } - + // set-up the dispatcher $dispatcherInstance = Dispatcher::getInstance(); - + // note the start of the operation $dispatcherInstance->dispatch("builder.generateIndexStart"); - + // default var $dataDir = Config::getOption("publicDir")."/styleguide/data"; - + // double-check that the data directory exists if (!is_dir($dataDir)) { FileUtil::makeDir($dataDir); } - + $output = ""; - + // load and write out the config options $config = array(); $exposedOptions = Config::getOption("exposedOptions"); @@ -107,7 +148,7 @@ protected function generateIndex() { $config[$exposedOption] = Config::getOption($exposedOption); } $output .= "var config = ".json_encode($config).";\n"; - + // load the ish Controls $ishControls = array(); $controlsToHide = array(); @@ -119,24 +160,24 @@ protected function generateIndex() { } $ishControls["ishControlsHide"] = $controlsToHide; $output .= "var ishControls = ".json_encode($ishControls).";\n"; - + // load and write out the items for the navigation $niExporter = new NavItemsExporter(); $navItems = $niExporter->run(); $output .= "var navItems = ".json_encode($navItems).";\n"; - + // load and write out the items for the pattern paths $patternPaths = array(); $ppdExporter = new PatternPathDestsExporter(); $patternPaths = $ppdExporter->run(); $output .= "var patternPaths = ".json_encode($patternPaths).";\n"; - + // load and write out the items for the view all paths $viewAllPaths = array(); $vapExporter = new ViewAllPathsExporter(); $viewAllPaths = $vapExporter->run($navItems); $output .= "var viewAllPaths = ".json_encode($viewAllPaths).";\n"; - + // gather plugin package information $packagesInfo = array(); $componentDir = Config::getOption("componentDir"); @@ -167,27 +208,27 @@ protected function generateIndex() { } } $output .= "var plugins = ".json_encode($packagesInfo).";"; - + // write out the data file_put_contents($dataDir."/patternlab-data.js",$output); - + // note the end of the operation $dispatcherInstance->dispatch("builder.generateIndexEnd"); - + } - + /** * Generates all of the patterns and puts them in the public directory * @param {Array} various options that might affect the export. primarily the location. */ protected function generatePatterns($options = array()) { - + // set-up the dispatcher $dispatcherInstance = Dispatcher::getInstance(); - + // note the beginning of the operation $dispatcherInstance->dispatch("builder.generatePatternsStart"); - + // set-up common vars $exportFiles = (isset($options["exportFiles"]) && $options["exportFiles"]); $exportDir = Config::getOption("exportDir"); @@ -197,66 +238,66 @@ protected function generatePatterns($options = array()) { $suffixRendered = Config::getOption("outputFileSuffixes.rendered"); $suffixRaw = Config::getOption("outputFileSuffixes.rawTemplate"); $suffixMarkupOnly = Config::getOption("outputFileSuffixes.markupOnly"); - + // make sure the export dir exists if ($exportFiles && !is_dir($exportDir)) { mkdir($exportDir); } - + // make sure patterns exists if (!is_dir($patternPublicDir)) { mkdir($patternPublicDir); } - + // loop over the pattern data store to render the individual patterns $store = PatternData::get(); foreach ($store as $patternStoreKey => $patternStoreData) { - + if (($patternStoreData["category"] == "pattern") && isset($patternStoreData["hidden"]) && (!$patternStoreData["hidden"])) { - + $path = $patternStoreData["pathDash"]; $pathName = (isset($patternStoreData["pseudo"])) ? $patternStoreData["pathOrig"] : $patternStoreData["pathName"]; - + // modify the pattern mark-up $markup = $patternStoreData["code"]; $markupFull = $patternStoreData["header"].$markup.$patternStoreData["footer"]; $markupEngine = file_get_contents($patternSourceDir."/".$pathName.".".$patternExtension); - + // if the pattern directory doesn't exist create it if (!is_dir($patternPublicDir."/".$path)) { mkdir($patternPublicDir."/".$path); } - + // write out the various pattern files file_put_contents($patternPublicDir."/".$path."/".$path.$suffixRendered.".html",$markupFull); if (!$exportFiles) { file_put_contents($patternPublicDir."/".$path."/".$path.$suffixMarkupOnly.".html",$markup); file_put_contents($patternPublicDir."/".$path."/".$path.$suffixRaw.".".$patternExtension,$markupEngine); } - + } - + } - + // note the end of the operation $dispatcherInstance->dispatch("builder.generatePatternsEnd"); - + } - + /** * Generates the style guide view */ protected function generateStyleguide() { - + // set-up the dispatcher $dispatcherInstance = Dispatcher::getInstance(); - + // note the beginning of the operation $dispatcherInstance->dispatch("builder.generateStyleguideStart"); - + // default var $publicDir = Config::getOption("publicDir"); - + // load the pattern loader $ppdExporter = new PatternPathSrcExporter(); $patternPathSrc = $ppdExporter->run(); @@ -265,56 +306,56 @@ protected function generateStyleguide() { $patternEngineBasePath = PatternEngine::getInstance()->getBasePath(); $patternLoaderClass = $patternEngineBasePath."\Loaders\PatternLoader"; $patternLoader = new $patternLoaderClass($options); - + // check directories i need if (!is_dir($publicDir."/styleguide/")) { mkdir($publicDir."/styleguide/"); } - + if (!is_dir($publicDir."/styleguide/html/")) { mkdir($publicDir."/styleguide/html/"); } - + // grab the partials into a data object for the style guide $ppExporter = new PatternPartialsExporter(); $partials = $ppExporter->run(); - + // add the pattern data so it can be exported $patternData = array(); - + // add the pattern lab specific mark-up $filesystemLoader = Template::getFilesystemLoader(); $stringLoader = Template::getStringLoader(); - + $globalData = Data::get(); $globalData["patternLabHead"] = $stringLoader->render(array("string" => Template::getHTMLHead(), "data" => array("cacheBuster" => $partials["cacheBuster"]))); $globalData["patternLabFoot"] = $stringLoader->render(array("string" => Template::getHTMLFoot(), "data" => array("cacheBuster" => $partials["cacheBuster"], "patternData" => json_encode($patternData)))); $globalData["viewall"] = true; - + $header = $patternLoader->render(array("pattern" => Template::getPatternHead(), "data" => $globalData)); $code = $filesystemLoader->render(array("template" => "viewall", "data" => $partials)); $footer = $patternLoader->render(array("pattern" => Template::getPatternFoot(), "data" => $globalData)); - + $styleGuidePage = $header.$code.$footer; - + file_put_contents($publicDir."/styleguide/html/styleguide.html",$styleGuidePage); - + // note the end of the operation $dispatcherInstance->dispatch("builder.generateStyleguideEnd"); - + } - + /** * Generates the view all pages */ protected function generateViewAllPages() { - + // set-up the dispatcher $dispatcherInstance = Dispatcher::getInstance(); - + // note the beginning of the operation $dispatcherInstance->dispatch("builder.generateViewAllPagesStart"); - + // default vars $patternPublicDir = Config::getOption("patternPublicDir"); $htmlHead = Template::getHTMLHead(); @@ -324,7 +365,7 @@ protected function generateViewAllPages() { $filesystemLoader = Template::getFilesystemLoader(); $stringLoader = Template::getStringLoader(); $globalData = Data::get(); - + // load the pattern loader $ppdExporter = new PatternPathSrcExporter(); $patternPathSrc = $ppdExporter->run(); @@ -333,40 +374,40 @@ protected function generateViewAllPages() { $patternEngineBasePath = PatternEngine::getInstance()->getBasePath(); $patternLoaderClass = $patternEngineBasePath."\Loaders\PatternLoader"; $patternLoader = new $patternLoaderClass($options); - + // make sure view all is set $globalData["viewall"] = true; - + // make sure the pattern dir exists if (!is_dir($patternPublicDir)) { mkdir($patternPublicDir); } - + // add view all to each list $store = PatternData::get(); foreach ($store as $patternStoreKey => $patternStoreData) { - + if ($patternStoreData["category"] == "patternSubtype") { - + // grab the partials into a data object for the style guide $ppExporter = new PatternPartialsExporter(); $partials = $ppExporter->run($patternStoreData["type"],$patternStoreData["name"]); - + if (!empty($partials["partials"])) { - + // add the pattern data so it can be exported $patternData = array(); $patternData["patternPartial"] = "viewall-".$patternStoreData["typeDash"]."-".$patternStoreData["nameDash"]; - + $globalData["patternLabHead"] = $stringLoader->render(array("string" => Template::getHTMLHead(), "data" => array("cacheBuster" => $partials["cacheBuster"]))); $globalData["patternLabFoot"] = $stringLoader->render(array("string" => Template::getHTMLFoot(), "data" => array("cacheBuster" => $partials["cacheBuster"], "patternData" => json_encode($patternData)))); - + // render the parts and join them $header = $patternLoader->render(array("pattern" => $patternHead, "data" => $globalData)); $code = $filesystemLoader->render(array("template" => "viewall", "data" => $partials)); $footer = $patternLoader->render(array("pattern" => $patternFoot, "data" => $globalData)); $viewAllPage = $header.$code.$footer; - + // if the pattern directory doesn't exist create it $patternPath = $patternStoreData["pathDash"]; if (!is_dir($patternPublicDir."/".$patternPath)) { @@ -375,31 +416,31 @@ protected function generateViewAllPages() { } else { file_put_contents($patternPublicDir."/".$patternPath."/index.html",$viewAllPage); } - + } - + } else if (($patternStoreData["category"] == "patternType") && PatternData::hasPatternSubtype($patternStoreData["nameDash"])) { - + // grab the partials into a data object for the style guide $ppExporter = new PatternPartialsExporter(); $partials = $ppExporter->run($patternStoreData["name"]); - + if (!empty($partials["partials"])) { - + // add the pattern data so it can be exported $patternData = array(); $patternData["patternPartial"] = "viewall-".$patternStoreData["nameDash"]."-all"; - + // add the pattern lab specific mark-up $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)); $code = $filesystemLoader->render(array("template" => "viewall", "data" => $partials)); $footer = $patternLoader->render(array("pattern" => $patternFoot, "data" => $globalData)); $viewAllPage = $header.$code.$footer; - + // if the pattern directory doesn't exist create it $patternPath = $patternStoreData["pathDash"]; if (!is_dir($patternPublicDir."/".$patternPath)) { @@ -408,16 +449,16 @@ protected function generateViewAllPages() { } else { file_put_contents($patternPublicDir."/".$patternPath."/index.html",$viewAllPage); } - + } - + } - + } - + // note the end of the operation $dispatcherInstance->dispatch("builder.generateViewAllPagesEnd"); - + } - + } From 0eace9ea6b2926c1126d1437b923298225851f27 Mon Sep 17 00:00:00 2001 From: Evan Lovely Date: Mon, 28 Aug 2017 11:33:00 -0700 Subject: [PATCH 15/18] adding styleguidekit path var --- src/PatternLab/Builder.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PatternLab/Builder.php b/src/PatternLab/Builder.php index a7ac535d..39034273 100644 --- a/src/PatternLab/Builder.php +++ b/src/PatternLab/Builder.php @@ -95,6 +95,7 @@ protected function generateIndex() { $finder = new Finder(); $base = __DIR__."/../../../"; /* [1] */ + $kit_path = Config::getOption("styleguideKitPath"); $finder->files()->name("composer.json")->in($base)->contains('patternlab-styleguidekit')->sortByName(); /* [2] */ foreach ($finder as $file) { From b16f3f6f7b0a6b0da7ec04d7ca28e091f43c11fa Mon Sep 17 00:00:00 2001 From: Salem Ghoweri Date: Sat, 2 Sep 2017 18:51:22 -0400 Subject: [PATCH 16/18] fix: cleaning up base path directory logic to make a little less prone to breaking --- src/PatternLab/Builder.php | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/PatternLab/Builder.php b/src/PatternLab/Builder.php index 39034273..bceb8147 100644 --- a/src/PatternLab/Builder.php +++ b/src/PatternLab/Builder.php @@ -82,24 +82,23 @@ protected function generateIndex() { * Handle missing index.html. Solves https://github.com/drupal-pattern-lab/patternlab-php-core/issues/14 * Could also be used to re-add missing styleguidekit assets with a few edits? * - * 1. @TODO: What would be a better way to find our base vendor directory from here? - * 2. Locate the current theme's styleguidekit assets via the patternlab-styleguidekit `type` in composer.json - * 3. @TODO: Figure out a better way to future-proof path resolution for styleguidekit `dist` folder - * 4. Recusirively copy files from styleguidekit to publicDir via https://stackoverflow.com/a/7775949 - * 5. Make sure we only try to create new directories if they don't already exist - * 6. Only copy files if they are missing (vs changed, etc) + * 1. @TODO: Figure out a better way to future-proof path resolution for styleguidekit `dist` folder + * 2. Recusirively copy files from styleguidekit to publicDir via https://stackoverflow.com/a/7775949 + * 3. Make sure we only try to create new directories if they don't already exist + * 4. Only copy files if they are missing (vs changed, etc) */ if (!file_exists(Config::getOption("publicDir")."/index.html")) { $index = Console::getHumanReadablePath(Config::getOption("publicDir")).DIRECTORY_SEPARATOR."index.html"; - Console::writeWarning($index . " is missing. No biggie. Grabbing a copy from your StyleguideKit..."); + Console::writeWarning($index . " is missing. No biggie. Grabbing a fresh copy from your StyleguideKit..."); + $baseDir = Config::getOption("baseDir") . '/vendor'; $finder = new Finder(); - $base = __DIR__."/../../../"; /* [1] */ - $kit_path = Config::getOption("styleguideKitPath"); - $finder->files()->name("composer.json")->in($base)->contains('patternlab-styleguidekit')->sortByName(); /* [2] */ + + // Locate the current theme's styleguidekit assets via the patternlab-styleguidekit `type` in composer.json + $finder->files()->name("composer.json")->in($baseDir)->contains('patternlab-styleguidekit')->sortByName(); foreach ($finder as $file) { - $src = dirname($file->getRealPath()) . DIRECTORY_SEPARATOR . 'dist'; /* [3] */ + $src = dirname($file->getRealPath()) . DIRECTORY_SEPARATOR . 'dist'; /* [1] */ $dest= Config::getOption("publicDir"); if (is_dir($src)){ @@ -108,16 +107,16 @@ protected function generateIndex() { mkdir($dest, 0755); } - foreach ( /* [4] */ + foreach ( /* [2] */ $iterator = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator($src, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item ) { if ($item->isDir()) { - if(!is_dir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName())) { /* [5] */ + if(!is_dir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName())) { /* [3] */ mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName()); } } else { - if(!file_exists($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName())) { /* [6] */ + if(!file_exists($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName())) { /* [4] */ copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName()); } } From 30ab3d0e7278bdd8500ee732d4d26ec908028f5e Mon Sep 17 00:00:00 2001 From: Evan Lovely Date: Sun, 3 Sep 2017 11:24:46 -0700 Subject: [PATCH 17/18] Cleanup packages badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e49258e8..a7c88949 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ![license](https://img.shields.io/github/license/pattern-lab/patternlab-php-core.svg) -[![Packagist](https://img.shields.io/packagist/v/pattern-lab/core.svg)](https://packagist.org/packages/pattern-lab/core) [![Gitter](https://img.shields.io/gitter/room/pattern-lab/php.svg)](https://gitter.im/pattern-lab/php) +[![Gitter](https://img.shields.io/gitter/room/pattern-lab/php.svg)](https://gitter.im/pattern-lab/php) # Pattern Lab Core From e38ee4d16868543b405ff99a719f4b5295fa2c3d Mon Sep 17 00:00:00 2001 From: Salem Date: Sat, 7 Oct 2017 15:25:45 -0400 Subject: [PATCH 18/18] Removing references to drupal-pattern-lab Chore as part of mega merge back into the main PL mothership repo --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 56458f0d..1deda66d 100644 --- a/composer.json +++ b/composer.json @@ -18,9 +18,9 @@ } ], "support": { - "issues": "https://github.com/drupal-pattern-lab/patternlab-php-core/issues", + "issues": "https://github.com/pattern-lab/patternlab-php-core/issues", "wiki": "http://patternlab.io/docs/", - "source": "https://github.com/drupal-pattern-lab/patternlab-php-core/releases" + "source": "https://github.com/pattern-lab/patternlab-php-core/releases" }, "autoload": { "psr-0": {