Skip to content

Commit 89cb0ff

Browse files
committed
these rules don't depend on something being hidden
1 parent 820d5b6 commit 89cb0ff

File tree

3 files changed

+76
-95
lines changed

3 files changed

+76
-95
lines changed

src/PatternLab/PatternData/Rules/DocumentationRule.php

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -47,55 +47,50 @@ public function run($depth, $ext, $path, $pathName, $name) {
4747
$docDash = $this->getPatternName(str_replace("_","",$doc),false); // colors
4848
$docPartial = $patternTypeDash."-".$docDash;
4949

50-
// if the pattern isn't hidden do stuff
51-
if (!$hidden) {
52-
53-
// default vars
54-
$patternSourceDir = Config::getOption("patternSourceDir");
55-
56-
// parse data
57-
$text = file_get_contents($patternSourceDir.DIRECTORY_SEPARATOR.$pathName);
58-
list($yaml,$markdown) = Documentation::parse($text);
59-
60-
// grab the title and unset it from the yaml so it doesn't get duped in the meta
61-
if (isset($yaml["title"])) {
62-
$title = $yaml["title"];
63-
unset($yaml["title"]);
64-
}
65-
66-
// figure out if this is a pattern subtype
67-
$patternSubtypeDoc = false;
68-
if ($depth == 1) {
69-
// go through all of the directories to see if this one matches our doc
70-
foreach (glob($patternSourceDir.DIRECTORY_SEPARATOR.$patternType.DIRECTORY_SEPARATOR."*",GLOB_ONLYDIR) as $dir) {
71-
$dir = str_replace($patternSourceDir.DIRECTORY_SEPARATOR.$patternType.DIRECTORY_SEPARATOR,"",$dir);
72-
if ($dir == $doc) {
73-
$patternSubtypeDoc = true;
74-
break;
75-
}
50+
// default vars
51+
$patternSourceDir = Config::getOption("patternSourceDir");
52+
53+
// parse data
54+
$text = file_get_contents($patternSourceDir.DIRECTORY_SEPARATOR.$pathName);
55+
list($yaml,$markdown) = Documentation::parse($text);
56+
57+
// grab the title and unset it from the yaml so it doesn't get duped in the meta
58+
if (isset($yaml["title"])) {
59+
$title = $yaml["title"];
60+
unset($yaml["title"]);
61+
}
62+
63+
// figure out if this is a pattern subtype
64+
$patternSubtypeDoc = false;
65+
if ($depth == 1) {
66+
// go through all of the directories to see if this one matches our doc
67+
foreach (glob($patternSourceDir.DIRECTORY_SEPARATOR.$patternType.DIRECTORY_SEPARATOR."*",GLOB_ONLYDIR) as $dir) {
68+
$dir = str_replace($patternSourceDir.DIRECTORY_SEPARATOR.$patternType.DIRECTORY_SEPARATOR,"",$dir);
69+
if ($dir == $doc) {
70+
$patternSubtypeDoc = true;
71+
break;
7672
}
77-
7873
}
7974

80-
$category = ($patternSubtypeDoc) ? "patternSubtype" : "pattern";
81-
$patternStoreKey = ($patternSubtypeDoc) ? $docPartial."-plsubtype" : $docPartial;
82-
83-
$patternStoreData = array("category" => $category,
84-
"desc" => $markdown,
85-
"descExists" => true,
86-
"meta" => $yaml,
87-
"full" => $doc);
75+
}
76+
77+
$category = ($patternSubtypeDoc) ? "patternSubtype" : "pattern";
78+
$patternStoreKey = ($patternSubtypeDoc) ? $docPartial."-plsubtype" : $docPartial;
79+
80+
$patternStoreData = array("category" => $category,
81+
"desc" => $markdown,
82+
"descExists" => true,
83+
"meta" => $yaml,
84+
"full" => $doc);
8885

89-
if (isset($title)) {
90-
$patternStoreData["nameClean"] = $title;
91-
}
92-
93-
// if the pattern data store already exists make sure this data overwrites it
94-
$patternStoreData = (PatternData::checkOption($patternStoreKey)) ? array_replace_recursive(PatternData::getOption($patternStoreKey),$patternStoreData) : $patternStoreData;
95-
PatternData::setOption($patternStoreKey, $patternStoreData);
96-
86+
if (isset($title)) {
87+
$patternStoreData["nameClean"] = $title;
9788
}
9889

90+
// if the pattern data store already exists make sure this data overwrites it
91+
$patternStoreData = (PatternData::checkOption($patternStoreKey)) ? array_replace_recursive(PatternData::getOption($patternStoreKey),$patternStoreData) : $patternStoreData;
92+
PatternData::setOption($patternStoreKey, $patternStoreData);
93+
9994
}
10095

10196
}

src/PatternLab/PatternData/Rules/PatternInfoListItemsRule.php

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,22 @@ public function run($depth, $ext, $path, $pathName, $name) {
3939
// load default vars
4040
$patternTypeDash = PatternData::getPatternTypeDash();
4141

42-
// should this pattern get rendered?
43-
$hidden = ($name[0] == "_");
44-
4542
// set-up the names, $name == foo.listitems.json
4643
$pattern = str_replace(".listitems.".$ext,"",$name); // foo
4744
$patternDash = $this->getPatternName($pattern,false); // foo
4845
$patternPartial = $patternTypeDash."-".$patternDash; // atoms-foo
4946

50-
if (!$hidden) {
51-
52-
$patternStoreData = array("category" => "pattern");
53-
54-
$data = Data::getListItems("_patterns/".$pathName,$ext);
55-
$patternStoreData["listItems"] = $data;
56-
57-
// create a key for the data store
58-
$patternStoreKey = $patternPartial;
59-
60-
// if the pattern data store already exists make sure it is merged and overwrites this data
61-
$patternStoreData = (PatternData::checkOption($patternStoreKey)) ? array_replace_recursive(PatternData::getOption($patternStoreKey),$patternStoreData) : $patternStoreData;
62-
PatternData::setOption($patternStoreKey, $patternStoreData);
63-
64-
}
47+
$patternStoreData = array("category" => "pattern");
48+
49+
$data = Data::getListItems("_patterns/".$pathName,$ext);
50+
$patternStoreData["listItems"] = $data;
51+
52+
// create a key for the data store
53+
$patternStoreKey = $patternPartial;
54+
55+
// if the pattern data store already exists make sure it is merged and overwrites this data
56+
$patternStoreData = (PatternData::checkOption($patternStoreKey)) ? array_replace_recursive(PatternData::getOption($patternStoreKey),$patternStoreData) : $patternStoreData;
57+
PatternData::setOption($patternStoreKey, $patternStoreData);
6558

6659
}
6760

src/PatternLab/PatternData/Rules/PatternInfoRule.php

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,51 +39,44 @@ public function run($depth, $ext, $path, $pathName, $name) {
3939
// load default vars
4040
$patternTypeDash = PatternData::getPatternTypeDash();
4141

42-
// should this pattern get rendered?
43-
$hidden = ($name[0] == "_");
44-
4542
// set-up the names, $name == foo.json
4643
$pattern = str_replace(".".$ext,"",$name); // foo
4744
$patternDash = $this->getPatternName($pattern,false); // foo
4845
$patternPartial = $patternTypeDash."-".$patternDash; // atoms-foo
4946

50-
if (!$hidden) {
51-
52-
$patternStoreData = array("category" => "pattern");
53-
54-
$file = file_get_contents(Config::getOption("patternSourceDir")."/".$pathName);
55-
56-
if ($ext == "json") {
57-
$data = json_decode($file,true);
58-
if ($jsonErrorMessage = JSON::hasError()) {
59-
JSON::lastErrorMsg($name,$jsonErrorMessage,$data);
60-
}
61-
} else {
62-
63-
try {
64-
$data = YAML::parse($file);
65-
} catch (ParseException $e) {
66-
printf("unable to parse ".$pathNameClean.": %s..\n", $e->getMessage());
67-
}
68-
69-
// single line of text won't throw a YAML error. returns as string
70-
if (gettype($data) == "string") {
71-
$data = array();
72-
}
73-
47+
$patternStoreData = array("category" => "pattern");
48+
49+
$file = file_get_contents(Config::getOption("patternSourceDir")."/".$pathName);
50+
51+
if ($ext == "json") {
52+
$data = json_decode($file,true);
53+
if ($jsonErrorMessage = JSON::hasError()) {
54+
JSON::lastErrorMsg($name,$jsonErrorMessage,$data);
7455
}
56+
} else {
7557

76-
$patternStoreData["data"] = $data;
77-
78-
// create a key for the data store
79-
$patternStoreKey = $patternPartial;
58+
try {
59+
$data = YAML::parse($file);
60+
} catch (ParseException $e) {
61+
printf("unable to parse ".$pathNameClean.": %s..\n", $e->getMessage());
62+
}
8063

81-
// if the pattern data store already exists make sure it is merged and overwrites this data
82-
$patternStoreData = (PatternData::checkOption($patternStoreKey)) ? array_replace_recursive(PatternData::getOption($patternStoreKey),$patternStoreData) : $patternStoreData;
83-
PatternData::setOption($patternStoreKey, $patternStoreData);
64+
// single line of text won't throw a YAML error. returns as string
65+
if (gettype($data) == "string") {
66+
$data = array();
67+
}
8468

8569
}
8670

71+
$patternStoreData["data"] = $data;
72+
73+
// create a key for the data store
74+
$patternStoreKey = $patternPartial;
75+
76+
// if the pattern data store already exists make sure it is merged and overwrites this data
77+
$patternStoreData = (PatternData::checkOption($patternStoreKey)) ? array_replace_recursive(PatternData::getOption($patternStoreKey),$patternStoreData) : $patternStoreData;
78+
PatternData::setOption($patternStoreKey, $patternStoreData);
79+
8780
}
8881

8982
}

0 commit comments

Comments
 (0)