Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DPL: Adding Ability for Markdown Files to Specify Which Pattern It Should Be Associated With (ex. README.md) #125

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c976fa4
making sure pattern type properly loads globalData var
dmolsen Jul 28, 2016
7dd6d48
install assets and save path appropriately
dmolsen Jul 28, 2016
884c995
Updating global data to use `yml` or `yaml`
EvanLovely Oct 31, 2016
44c0dd0
Fixing extra closing parentheses so dev branch works. Addresses https…
bolt-bot Apr 27, 2017
0c30ad1
Merge pull request #1 from drupal-pattern-lab/feature/fix-parse-error
EvanLovely May 9, 2017
d7506a0
Adding in lineage fix for PL when using Twig templates + line by line…
bolt-bot May 10, 2017
a1d3781
Merge pull request #4 from drupal-pattern-lab/patch-4
sghoweri May 19, 2017
a46d571
Merge pull request #6 from drupal-pattern-lab/dev
EvanLovely May 22, 2017
505f32c
updating composer to use Drupal Pattern Lab name
EvanLovely May 24, 2017
8a51a73
updating config path to use our vendor name
EvanLovely May 24, 2017
d45a334
Revert "updating config path to use our vendor name"
EvanLovely May 25, 2017
b6c7409
Revert "updating composer to use Drupal Pattern Lab name"
EvanLovely May 25, 2017
ad10d44
updating info
EvanLovely May 25, 2017
9b31f31
Merge branch 'master' into dev
EvanLovely May 25, 2017
741ebb7
Don't overwrite nameClean if it has already been set
aleksip Jun 19, 2017
4ae8878
Replace possible dots in pattern names with dashes
aleksip Jun 19, 2017
c8428db
Merge pull request #9 from aleksip/replace-pattern-name-dots-with-dashes
EvanLovely Jun 20, 2017
34fa945
Merge branch 'dev'
EvanLovely Jun 20, 2017
407f7bb
Merge pull request #5 from drupal-pattern-lab/feature/fix-pattern-lab…
EvanLovely Jun 20, 2017
5b2a789
Merge pull request #8 from aleksip/pseudo-pattern-nameclean
EvanLovely Jun 20, 2017
2db3557
Merge branch 'dev'
EvanLovely Jun 20, 2017
60fc319
Enabling the ability for Pattern Lab to follow any symlinks that may …
bolt-bot Jul 1, 2017
1fa44ec
Merge pull request #10 from drupal-pattern-lab/feature/follow-symlinks
EvanLovely Jul 12, 2017
bb83196
feat: adding optional ability for markdown files to specify which pat…
bolt-bot Sep 3, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions src/PatternLab/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions src/PatternLab/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand All @@ -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);

Expand Down
9 changes: 5 additions & 4 deletions src/PatternLab/InstallerUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

}
Expand Down
7 changes: 3 additions & 4 deletions src/PatternLab/PatternData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
45 changes: 45 additions & 0 deletions src/PatternLab/PatternData/Helpers/LineageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/PatternLab/PatternData/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
27 changes: 15 additions & 12 deletions src/PatternLab/PatternData/Rules/DocumentationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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"];
Expand All @@ -68,9 +72,8 @@ public function run($depth, $ext, $path, $pathName, $name) {
break;
}
}

}

$category = ($patternSubtypeDoc) ? "patternSubtype" : "pattern";
$patternStoreKey = ($patternSubtypeDoc) ? $docPartial."-plsubtype" : $docPartial;

Expand Down
9 changes: 8 additions & 1 deletion src/PatternLab/PatternData/Rules/PseudoPatternRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
Expand Down