Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: wrapping up implementation of ordering -- finally got top level…
… patternTypes reordered + non-nested patterns working! Addresses #138
  • Loading branch information
bolt-bot committed Oct 30, 2017
commit d813f4605f1bdaafa230b5b29f39e2e70411d9e8
43 changes: 33 additions & 10 deletions src/PatternLab/PatternData/Exporters/NavItemsExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,21 @@ public function __construct($options = array()) {

$this->store = PatternData::get();
$this->styleGuideExcludes = Config::getOption("styleGuideExcludes");

}


// Sort navigation level based on the `order` key (if it exists)
private function sortNavByOrder($a, $b) {
if (!isset($a['order'])){
return 0;
} else if (!isset($b['order'])){
return 0;
} else if ($a['order'] == $b['order']){
return 0;
}
return ($a['order'] < $b['order']) ? -1 : 1;
}


public function run() {

Expand All @@ -46,7 +59,7 @@ public function run() {
foreach ($this->store as $patternStoreKey => $patternStoreData) {

if ($patternStoreData["category"] == "patternType") {

$bi = (count($navItems["patternTypes"]) == 0) ? 0 : $bi + 1;

// add a new patternType to the nav
Expand Down Expand Up @@ -98,11 +111,8 @@ public function run() {
} else {
$navItems["patternTypes"][$bi]["patternTypeItems"][$ni]["patternSubtypeItems"][] = $patternInfo;
}

}

}

}

// review each subtype. add a view all link or remove the subtype as necessary
Expand Down Expand Up @@ -157,13 +167,26 @@ public function run() {
"patternPartial" => "viewall-".$patternTypeDash."-all");

}
}


// Sort the navItems by order property before returning final navigation (@TODO: look into possibly moving the sortNavByOrder function to a more global (ie. reusable) place)
foreach ($navItems as $navItem) {
// Sort top level patternTypes (ex. 01-atoms)
usort($navItems['patternTypes'], array( $this, 'sortNavByOrder' ) );

foreach ($navItem as $patternTypeKey => $patternTypeValue) {
// Then sort patternTypeItems and/or patternItems depending on what exists (ex. Homepage or Buttons)
usort($navItems['patternTypes'][$patternTypeKey]['patternTypeItems'], array( $this, 'sortNavByOrder' ) );
usort($navItems['patternTypes'][$patternTypeKey]['patternItems'], array( $this, 'sortNavByOrder' ) );

// Finallly, finish sorting out the nested patternSubtypeItems (Primary Button, etc)
for($i = 0, $c = count($navItems['patternTypes'][$patternTypeKey]['patternTypeItems']); $i < $c; $i++){
usort($navItems['patternTypes'][$patternTypeKey]['patternTypeItems'][$i]['patternSubtypeItems'], array( $this, 'sortNavByOrder' ) );
}
}
}

$navItems = PatternData::sortPatternData($navItems);


return $navItems;

}

}
36 changes: 28 additions & 8 deletions src/PatternLab/PatternData/Rules/DocumentationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function __construct($options) {
}

public function run($depth, $ext, $path, $pathName, $name) {

// load default vars
$patternType = PatternData::getPatternType();
$patternTypeDash = PatternData::getPatternTypeDash();
Expand All @@ -57,23 +56,42 @@ public function run($depth, $ext, $path, $pathName, $name) {
unset($yaml["title"]);
}

// figure out if this is a pattern subtype
// figure out if this is a top level pattern type or pattern subtype
$patternSubtypeDoc = false;
if ($depth == 1) {
// go through all of the directories to see if this one matches our doc
$patternTypeDoc = false;
if ($depth == 0) {
foreach (glob($patternSourceDir.DIRECTORY_SEPARATOR.$patternType,GLOB_ONLYDIR) as $dir) {
$dir = str_replace($patternSourceDir.DIRECTORY_SEPARATOR,"",$dir);
if ($dir == $doc) {
$patternTypeDoc = true;
break;
}
}
} else if ($depth == 1){
// go through all of the directories to see if this one matches our doc
foreach (glob($patternSourceDir.DIRECTORY_SEPARATOR.$patternType.DIRECTORY_SEPARATOR."*",GLOB_ONLYDIR) as $dir) {
$dir = str_replace($patternSourceDir.DIRECTORY_SEPARATOR.$patternType.DIRECTORY_SEPARATOR,"",$dir);
if ($dir == $doc) {
$patternSubtypeDoc = true;
break;
}
}

}

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

$category = "pattern"; // By default, make the pattern type a "pattern"
$patternStoreKey = $docPartial;

// Update if patternType or subtype
if ($patternTypeDoc) {
$category = "patternType";
$patternStoreKey = $patternTypeDash."-pltype";

// organisms-pltype
} else if ($patternSubtypeDoc){
$category = "patternSubtype";
$patternStoreKey = $docPartial."-plsubtype";
}

$patternStoreData = array("category" => $category,
"desc" => trim($markdown),
"descExists" => true,
Expand All @@ -100,6 +118,8 @@ public function run($depth, $ext, $path, $pathName, $name) {
}
}



// if the pattern data store already exists make sure this data overwrites it
$patternStoreData = (PatternData::checkOption($patternStoreKey)) ? array_replace_recursive(PatternData::getOption($patternStoreKey),$patternStoreData) : $patternStoreData;
PatternData::setOption($patternStoreKey, $patternStoreData);
Expand Down