Skip to content

Commit 09c63a6

Browse files
committed
expanding config options and more dir separators
1 parent 585924c commit 09c63a6

File tree

7 files changed

+56
-51
lines changed

7 files changed

+56
-51
lines changed

src/PatternLab/Annotations.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public static function clear() {
4040
public static function gather() {
4141

4242
// set-up default var
43-
$sourceDir = Config::getOption("sourceDir");
43+
$annotationsDir = Config::getOption("annotationsDir");
44+
4445
// set-up the dispatcher
4546
$dispatcherInstance = Dispatcher::getInstance();
4647

@@ -51,14 +52,14 @@ public static function gather() {
5152
self::$store["comments"] = array();
5253

5354
// iterate over all of the files in the annotations dir
54-
if (!is_dir($sourceDir."/_annotations")) {
55-
Console::writeWarning("<path>_annotations/</path><warning> doesn't exist so you won't have annotations...");
56-
mkdir($sourceDir."/_annotations");
55+
if (!is_dir($annotationsDir)) {
56+
Console::writeWarning("<path>".Console::getHumanReadablePath($annotationsDir)."</path><warning> doesn't exist so you won't have annotations...");
57+
mkdir($annotationsDir);
5758
}
5859

5960
// find the markdown-based annotations
6061
$finder = new Finder();
61-
$finder->files()->name("*.md")->in($sourceDir."/_annotations");
62+
$finder->files()->name("*.md")->in($annotationsDir);
6263
$finder->sortByName();
6364

6465
foreach ($finder as $name => $file) {
@@ -89,13 +90,14 @@ public static function gather() {
8990
}
9091

9192
// read in the old style annotations.js, modify the data and generate JSON array to merge
92-
if (file_exists($sourceDir."/_annotations/annotations.js")) {
93-
$text = file_get_contents($sourceDir."/_annotations/annotations.js");
93+
$oldStyleAnnotationsPath = $annotationsDir.DIRECTORY_SEPARATOR."annotations.js";
94+
if (file_exists($oldStyleAnnotationsPath)) {
95+
$text = file_get_contents($oldStyleAnnotationsPath);
9496
$text = str_replace("var comments = ","",$text);
9597
$text = rtrim($text,";");
9698
$data = json_decode($text,true);
9799
if ($jsonErrorMessage = JSON::hasError()) {
98-
JSON::lastErrorMsg("_annotations/annotations.js",$jsonErrorMessage,$data);
100+
JSON::lastErrorMsg(Console::getHumanReadablePath($oldStyleAnnotationsPath),$jsonErrorMessage,$data);
99101
}
100102
}
101103

src/PatternLab/Config.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -201,18 +201,20 @@ public static function init($baseDir = "", $verbose = true) {
201201
}
202202

203203
// set-up the various dirs
204-
self::$options["configDir"] = self::$userConfigDir;
205-
self::$options["configPath"] = self::$userConfigPath;
206-
self::$options["coreDir"] = is_dir(self::$options["baseDir"]."_core") ? self::$options["baseDir"]."_core" : self::$options["baseDir"]."core";
207-
self::$options["exportDir"] = isset(self::$options["exportDir"]) ? self::$options["baseDir"].self::cleanDir(self::$options["exportDir"]) : self::$options["baseDir"]."exports";
208-
self::$options["publicDir"] = isset(self::$options["publicDir"]) ? self::$options["baseDir"].self::cleanDir(self::$options["publicDir"]) : self::$options["baseDir"]."public";
209-
self::$options["scriptsDir"] = isset(self::$options["scriptsDir"]) ? self::$options["baseDir"].self::cleanDir(self::$options["scriptsDir"]) : self::$options["baseDir"]."scripts";
210-
self::$options["sourceDir"] = isset(self::$options["sourceDir"]) ? self::$options["baseDir"].self::cleanDir(self::$options["sourceDir"]) : self::$options["baseDir"]."source";
211-
self::$options["componentDir"] = self::$options["publicDir"]."/patternlab-components";
212-
self::$options["dataDir"] = self::$options["sourceDir"]."/_data";
213-
self::$options["patternExportDir"] = self::$options["exportDir"]."/patterns";
214-
self::$options["patternPublicDir"] = self::$options["publicDir"]."/patterns";
215-
self::$options["patternSourceDir"] = self::$options["sourceDir"]."/_patterns";
204+
self::$options["configDir"] = self::$userConfigDir;
205+
self::$options["configPath"] = self::$userConfigPath;
206+
self::$options["coreDir"] = is_dir(self::$options["baseDir"]."_core") ? self::$options["baseDir"]."_core" : self::$options["baseDir"]."core";
207+
self::$options["exportDir"] = isset(self::$options["exportDir"]) ? self::$options["baseDir"].self::cleanDir(self::$options["exportDir"]) : self::$options["baseDir"]."exports";
208+
self::$options["publicDir"] = isset(self::$options["publicDir"]) ? self::$options["baseDir"].self::cleanDir(self::$options["publicDir"]) : self::$options["baseDir"]."public";
209+
self::$options["scriptsDir"] = isset(self::$options["scriptsDir"]) ? self::$options["baseDir"].self::cleanDir(self::$options["scriptsDir"]) : self::$options["baseDir"]."scripts";
210+
self::$options["sourceDir"] = isset(self::$options["sourceDir"]) ? self::$options["baseDir"].self::cleanDir(self::$options["sourceDir"]) : self::$options["baseDir"]."source";
211+
self::$options["componentDir"] = isset(self::$options["componentDir"]) ? self::$options["publicDir"].DIRECTORY_SEPARATOR.self::cleanDir(self::$options["componentDir"]) : self::$options["publicDir"].DIRECTORY_SEPARATOR."patternlab-components";
212+
self::$options["dataDir"] = isset(self::$options["dataDir"]) ? self::$options["sourceDir"].DIRECTORY_SEPARATOR.self::cleanDir(self::$options["dataDir"]) : self::$options["sourceDir"].DIRECTORY_SEPARATOR."_data";
213+
self::$options["patternExportDir"] = isset(self::$options["patternExportDir"]) ? self::$options["exportDir"].DIRECTORY_SEPARATOR.self::cleanDir(self::$options["patternExportDir"]) : self::$options["exportDir"].DIRECTORY_SEPARATOR."patterns";
214+
self::$options["patternPublicDir"] = isset(self::$options["patternPublicDir"]) ? self::$options["publicDir"].DIRECTORY_SEPARATOR.self::cleanDir(self::$options["patternPublicDir"]) : self::$options["publicDir"].DIRECTORY_SEPARATOR."patterns";
215+
self::$options["patternSourceDir"] = isset(self::$options["patternSourceDir"]) ? self::$options["sourceDir"].DIRECTORY_SEPARATOR.self::cleanDir(self::$options["patternSourceDir"]) : self::$options["sourceDir"].DIRECTORY_SEPARATOR."_patterns";
216+
self::$options["metaDir"] = isset(self::$options["metaDir"]) ? self::$options["sourceDir"].DIRECTORY_SEPARATOR.self::cleanDir(self::$options["metaDir"]) : self::$options["sourceDir"].DIRECTORY_SEPARATOR."_meta/";
217+
self::$options["annotationsDir"] = isset(self::$options["annotationsDir"]) ? self::$options["sourceDir"].DIRECTORY_SEPARATOR.self::cleanDir(self::$options["annotationsDir"]) : self::$options["sourceDir"].DIRECTORY_SEPARATOR."_annotations/";
216218

217219
// handle a pre-2.1.0 styleguideKitPath before saving it
218220
if (isset(self::$options["styleguideKitPath"])) {

src/PatternLab/FileUtil.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,23 +210,23 @@ public static function cleanPublic() {
210210
// scan source/ & public/ to figure out what directories might need to be cleaned up
211211
$publicDir = Config::getOption("publicDir");
212212
$sourceDir = Config::getOption("sourceDir");
213-
$publicDirs = glob($publicDir."/*",GLOB_ONLYDIR);
214-
$sourceDirs = glob($sourceDir."/*",GLOB_ONLYDIR);
213+
$publicDirs = glob($publicDir.DIRECTORY_SEPARATOR."*",GLOB_ONLYDIR);
214+
$sourceDirs = glob($sourceDir.DIRECTORY_SEPARATOR."*",GLOB_ONLYDIR);
215215

216216
// make sure some directories aren't deleted
217217
$ignoreDirs = array("styleguide","patternlab-components");
218218
foreach ($ignoreDirs as $ignoreDir) {
219-
$key = array_search($publicDir."/".$ignoreDir,$publicDirs);
219+
$key = array_search($publicDir.DIRECTORY_SEPARATOR.$ignoreDir,$publicDirs);
220220
if ($key !== false){
221221
unset($publicDirs[$key]);
222222
}
223223
}
224224

225225
// compare source dirs against public. remove those dirs w/ an underscore in source/ from the public/ list
226226
foreach ($sourceDirs as $dir) {
227-
$cleanDir = str_replace($sourceDir."/","",$dir);
227+
$cleanDir = str_replace($sourceDir.DIRECTORY_SEPARATOR,"",$dir);
228228
if ($cleanDir[0] == "_") {
229-
$key = array_search($publicDir."/".str_replace("_","",$cleanDir),$publicDirs);
229+
$key = array_search($publicDir.DIRECTORY_SEPARATOR.str_replace("_","",$cleanDir),$publicDirs);
230230
if ($key !== false){
231231
unset($publicDirs[$key]);
232232
}

src/PatternLab/PatternData/Helpers/RawPatternHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function run() {
4747
$srcPath = (isset($patternStoreData["pseudo"])) ? PatternData::getPatternOption($patternStoreData["original"],"pathName") : $patternStoreData["pathName"];
4848

4949
// load the raw data so it can be modified/rendered
50-
$path = $patternSourceDir."/".$srcPath.".".$patternExtension;
50+
$path = $patternSourceDir.DIRECTORY_SEPARATOR.$srcPath.".".$patternExtension;
5151
if (file_exists($path)) {
5252
PatternData::setPatternOption($patternStoreKey,"patternRaw",file_get_contents($path));
5353
} else {

src/PatternLab/PatternData/Rules/DocumentationRule.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function run($depth, $ext, $path, $pathName, $name) {
5454
$patternSourceDir = Config::getOption("patternSourceDir");
5555

5656
// parse data
57-
$text = file_get_contents($patternSourceDir."/".$pathName);
57+
$text = file_get_contents($patternSourceDir.DIRECTORY_SEPARATOR.$pathName);
5858
list($yaml,$markdown) = Documentation::parse($text);
5959

6060
// grab the title and unset it from the yaml so it doesn't get duped in the meta
@@ -67,8 +67,8 @@ public function run($depth, $ext, $path, $pathName, $name) {
6767
$patternSubtypeDoc = false;
6868
if ($depth == 1) {
6969
// go through all of the directories to see if this one matches our doc
70-
foreach (glob($patternSourceDir."/".$patternType."/*",GLOB_ONLYDIR) as $dir) {
71-
$dir = str_replace($patternSourceDir."/".$patternType."/","",$dir);
70+
foreach (glob($patternSourceDir.DIRECTORY_SEPARATOR.$patternType.DIRECTORY_SEPARATOR."*",GLOB_ONLYDIR) as $dir) {
71+
$dir = str_replace($patternSourceDir.DIRECTORY_SEPARATOR.$patternType.DIRECTORY_SEPARATOR,"",$dir);
7272
if ($dir == $doc) {
7373
$patternSubtypeDoc = true;
7474
break;

src/PatternLab/Template.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static function init() {
4242

4343
// set-up config vars
4444
$patternExtension = Config::getOption("patternExtension");
45-
$sourceDir = Config::getOption("sourceDir");
45+
$metaDir = Config::getOption("metaDir");
4646
$styleguideKit = Config::getOption("styleguideKit");
4747
$styleguideKitPath = Config::getOption("styleguideKitPath");
4848

@@ -51,15 +51,15 @@ public static function init() {
5151
}
5252

5353
// load pattern-lab's resources
54-
$partialPath = $styleguideKitPath."/views/partials";
55-
$generalHeaderPath = $partialPath."/general-header.".$patternExtension;
56-
$generalFooterPath = $partialPath."/general-footer.".$patternExtension;
57-
self::$htmlHead = (file_exists($generalHeaderPath)) ? file_get_contents($generalHeaderPath) : "";
58-
self::$htmlFoot = (file_exists($generalFooterPath)) ? file_get_contents($generalFooterPath) : "";
54+
$partialPath = $styleguideKitPath.DIRECTORY_SEPARATOR."views".DIRECTORY_SEPARATOR."partials";
55+
$generalHeaderPath = $partialPath.DIRECTORY_SEPARATOR."general-header.".$patternExtension;
56+
$generalFooterPath = $partialPath.DIRECTORY_SEPARATOR."general-footer.".$patternExtension;
57+
self::$htmlHead = (file_exists($generalHeaderPath)) ? file_get_contents($generalHeaderPath) : "";
58+
self::$htmlFoot = (file_exists($generalFooterPath)) ? file_get_contents($generalFooterPath) : "";
5959

6060
// gather the user-defined header and footer information
61-
$patternHeadPath = $sourceDir."/_meta/_00-head.".$patternExtension;
62-
$patternFootPath = $sourceDir."/_meta/_01-foot.".$patternExtension;
61+
$patternHeadPath = $metaDir.DIRECTORY_SEPARATOR."_00-head.".$patternExtension;
62+
$patternFootPath = $metaDir.DIRECTORY_SEPARATOR."_01-foot.".$patternExtension;
6363
self::$patternHead = (file_exists($patternHeadPath)) ? file_get_contents($patternHeadPath) : "";
6464
self::$patternFoot = (file_exists($patternFootPath)) ? file_get_contents($patternFootPath) : "";
6565

@@ -68,8 +68,8 @@ public static function init() {
6868
$filesystemLoaderClass = $patternEngineBasePath."\Loaders\FilesystemLoader";
6969

7070
$options = array();
71-
$options["templatePath"] = $styleguideKitPath."/views";
72-
$options["partialsPath"] = $styleguideKitPath."/views/partials";
71+
$options["templatePath"] = $styleguideKitPath.DIRECTORY_SEPARATOR."views";
72+
$options["partialsPath"] = $options["templatePath"].DIRECTORY_SEPARATOR."partials";
7373

7474
self::$filesystemLoader = new $filesystemLoaderClass($options);
7575

src/PatternLab/Watcher.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function watch($options = array()) {
6565
// DEPRECATED
6666
/*if ($reload) {
6767
$path = str_replace("lib".DIRECTORY_SEPARATOR."PatternLab","autoReloadServer.php",__DIR__);
68-
$fp = popen("php ".$path." -s", "r");
68+
$fp = popen("php ".$path." -s", "r");
6969
Console::writeLine("starting page auto-reload...");
7070
}*/
7171

@@ -82,11 +82,12 @@ public function watch($options = array()) {
8282
Console::writeLine("watching your site for changes...");
8383

8484
// default vars
85-
$publicDir = Config::getOption("publicDir");
86-
$sourceDir = Config::getOption("sourceDir");
87-
$ignoreExts = Config::getOption("ie");
88-
$ignoreDirs = Config::getOption("id");
89-
$patternExt = Config::getOption("patternExtension");
85+
$publicDir = Config::getOption("publicDir");
86+
$sourceDir = Config::getOption("sourceDir");
87+
$patternSourceDir = Config::getOption("patternSourceDir");
88+
$ignoreExts = Config::getOption("ie");
89+
$ignoreDirs = Config::getOption("id");
90+
$patternExt = Config::getOption("patternExtension");
9091

9192
// run forever
9293
while (true) {
@@ -95,15 +96,15 @@ public function watch($options = array()) {
9596
$cp = clone $o->patterns;
9697

9798
// iterate over the patterns & related data and regenerate the entire site if they've changed
98-
$patternObjects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($sourceDir."/_patterns/"), \RecursiveIteratorIterator::SELF_FIRST);
99+
$patternObjects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($patternSourceDir), \RecursiveIteratorIterator::SELF_FIRST);
99100

100101
// make sure dots are skipped
101102
$patternObjects->setFlags(\FilesystemIterator::SKIP_DOTS);
102103

103104
foreach($patternObjects as $name => $object) {
104105

105106
// clean-up the file name and make sure it's not one of the pattern lab files or to be ignored
106-
$fileName = str_replace($sourceDir."/_patterns".DIRECTORY_SEPARATOR,"",$name);
107+
$fileName = str_replace($patternSourceDir.DIRECTORY_SEPARATOR,"",$name);
107108
$fileNameClean = str_replace(DIRECTORY_SEPARATOR."_",DIRECTORY_SEPARATOR,$fileName);
108109

109110
if ($object->isFile() && (($object->getExtension() == $patternExt) || ($object->getExtension() == "json") || ($object->getExtension() == "md"))) {
@@ -168,10 +169,10 @@ public function watch($options = array()) {
168169
}
169170

170171
// iterate over annotations, data, meta and any other _ dirs
171-
$watchDirs = glob($sourceDir."/_*",GLOB_ONLYDIR);
172+
$watchDirs = glob($sourceDir.DIRECTORY_SEPARATOR."_*",GLOB_ONLYDIR);
172173
foreach ($watchDirs as $watchDir) {
173174

174-
if (str_replace($sourceDir."/","",$watchDir) != "_patterns") {
175+
if ($watchDir != $patternSourceDir) {
175176

176177
// iterate over the data files and regenerate the entire site if they've changed
177178
$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($watchDir), \RecursiveIteratorIterator::SELF_FIRST);
@@ -181,7 +182,7 @@ public function watch($options = array()) {
181182

182183
foreach($objects as $name => $object) {
183184

184-
$fileName = str_replace($sourceDir."/","",$name);
185+
$fileName = str_replace($sourceDir.DIRECTORY_SEPARATOR,"",$name);
185186
$mt = $object->getMTime();
186187

187188
if (!isset($o->$fileName)) {
@@ -205,7 +206,7 @@ public function watch($options = array()) {
205206
// iterate over all of the other files in the source directory and move them if their modified time has changed
206207
if ($moveStatic) {
207208

208-
$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($sourceDir."/"), \RecursiveIteratorIterator::SELF_FIRST);
209+
$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($sourceDir.DIRECTORY_SEPARATOR), \RecursiveIteratorIterator::SELF_FIRST);
209210

210211
// make sure dots are skipped
211212
$objects->setFlags(\FilesystemIterator::SKIP_DOTS);

0 commit comments

Comments
 (0)