Skip to content

Commit 2db3557

Browse files
committed
Merge branch 'dev'
2 parents 34fa945 + 5b2a789 commit 2db3557

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

Diff for: src/PatternLab/PatternData/Helpers/LineageHelper.php

+45
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,51 @@ public function run() {
5353

5454
foreach ($foundLineages as $lineage) {
5555

56+
/**
57+
* Fix for Pattern Lab Lineages when using Twig Namespaces.
58+
* Converts the full file path to PL-friendly shorthand so
59+
* they are internally registered.
60+
*
61+
* 1. Only handle instances where we aren't or can't use the
62+
* shorthand PL path reference in templates, specifically
63+
* in Twig / D8 when we need to use Twig namespaces in
64+
* our template paths.
65+
* 2. Strip off the @ sign at the beginning of our $lineage string.
66+
* 3. Break apart the full lineage path based on any slashes that
67+
* may exist.
68+
* 4. Store the length of our broken up path for reference below
69+
* 5. Store the first part of the string up to the first slash "/"
70+
* 6. Now grab the last part of the pattern key, based on the length
71+
* of the path we previously exploded.
72+
* 7. Remove any "_" from pattern Name.
73+
* 8. Remove any potential prefixed numbers or number + dash
74+
* combos on our Pattern Name.
75+
* 9. Strip off the pattern path extension (.twig,
76+
* .mustache, etc) if it exists.
77+
* 10. If the pattern name parsed had an extension,
78+
* re-assign our Pattern Name to that.
79+
* 11. Finally, re-assign $lineage to the default PL pattern key.
80+
*/
81+
82+
if ($lineage[0] == '@') { /* [1] */
83+
$lineage = ltrim($lineage, '@'); /* [2] */
84+
$lineageParts = explode('/', $lineage); /* [3] */
85+
$length = count($lineageParts); /* [4] */
86+
$patternType = $lineageParts[0]; /* [5] */
87+
88+
$patternName = $lineageParts[$length - 1]; /* [6] */
89+
$patternName = ltrim($patternName, '_'); /* [7] */
90+
$patternName = preg_replace('/^[0-9\-]+/', '',
91+
$patternName); /* [8] */
92+
93+
$patternNameStripped = explode('.' . $patternExtension, $patternName); /* [9] */
94+
95+
if (count($patternNameStripped) > 1) { /* [10] */
96+
$patternName = $patternNameStripped[0];
97+
}
98+
$lineage = $patternType . "-" . $patternName; /* [11] */
99+
}
100+
56101
if (PatternData::getOption($lineage)) {
57102

58103
$patternLineages[] = array("lineagePattern" => $lineage,

Diff for: src/PatternLab/PatternData/Rules/PseudoPatternRule.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,14 @@ public function run($depth, $ext, $path, $pathName, $name) {
171171
$patternStoreData["data"] = is_array($patternData) ? array_replace_recursive($patternDataBase, $patternData) : $patternDataBase;
172172

173173
// if the pattern data store already exists make sure it is merged and overwrites this data
174-
$patternStoreData = (PatternData::checkOption($patternStoreKey)) ? array_replace_recursive(PatternData::getOption($patternStoreKey),$patternStoreData) : $patternStoreData;
174+
if (PatternData::checkOption($patternStoreKey)) {
175+
$existingData = PatternData::getOption($patternStoreKey);
176+
if (array_key_exists('nameClean', $existingData)) {
177+
// don't overwrite nameClean
178+
unset($patternStoreData['nameClean']);
179+
}
180+
$patternStoreData = array_replace_recursive($existingData, $patternStoreData);
181+
}
175182
PatternData::setOption($patternStoreKey, $patternStoreData);
176183

177184
}

0 commit comments

Comments
 (0)