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

Fix for Pattern Lab Pattern Viewer Not Displaying Namespaced Lineage Twig Paths #105

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
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
46 changes: 45 additions & 1 deletion src/PatternLab/PatternData/Helpers/LineageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,58 @@ public function run() {

foreach ($foundLineages as $lineage) {

//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.
if ($lineage[0] == '@'){

//Grab the template extension getting used so we can strip it off down below.
$patternExtension = Config::getOption("patternExtension");

//Strip off the @ sign at the beginning of our $lineage string.
$lineage = ltrim($lineage, '@');

//Break apart the full lineage path based on any slashes that may exist.
$lineageParts = explode('/', $lineage);

//Store the length of our broken up path for reference below
$length = count($lineageParts);

//Store the first part of the string up to the first slash "/"
$patternType = $lineageParts[0];

//Now grab the last part of the pattern key, based on the length of the path we previously exploded.
$patternName = $lineageParts[$length - 1];

//Remove any "_" from pattern Name.
$patternName = ltrim($patternName, '_');

//Remove any potential prefixed numbers or number + dash combos on our Pattern Name.
$patternName = preg_replace('/^[0-9\-]+/', '', $patternName);

//Flag any "_" hidden patterns so we skip over for now.
if ($patternName[0] == '_'){
$hidden = true;
}

//Strip off the pattern path extension (.twig, .mustache, etc) if it exists.
$patternNameStripped = explode('.' . $patternExtension, $patternName);

// If the pattern name parsed had an extension, re-assign our Pattern Name to that.
if (count($patternNameStripped) > 1){
$patternName = $patternNameStripped[0];
}

//Finally, re-assign $lineage to the default PL pattern key.
$lineage = $patternType . "-" . $patternName;
}

if (PatternData::getOption($lineage)) {

$patternLineages[] = array("lineagePattern" => $lineage,
"lineagePath" => "../../patterns/".$patternStoreData["pathDash"]."/".$patternStoreData["pathDash"].$suffixRendered.".html");

} else {

if (strpos($lineage, '/') === false) {
if (strpos($lineage, '/') === false && !$hidden) {
$fileName = $patternStoreData["pathName"].".".$patternExtension;
Console::writeWarning("you may have a typo in ".$fileName.". `".$lineage."` is not a valid pattern...");
}
Expand Down