Skip to content

Commit 964db90

Browse files
committed
Merge branch 'dev'
2 parents 79bae51 + 2b8a581 commit 964db90

File tree

5 files changed

+83
-21
lines changed

5 files changed

+83
-21
lines changed

src/PatternLab/Config.php

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ class Config {
3737
*/
3838
protected static function cleanDir($dir) {
3939

40-
$dir = trim($dir);
41-
$dir = ($dir[0] == DIRECTORY_SEPARATOR) ? ltrim($dir, DIRECTORY_SEPARATOR) : $dir;
42-
$dir = ($dir[strlen($dir)-1] == DIRECTORY_SEPARATOR) ? rtrim($dir, DIRECTORY_SEPARATOR) : $dir;
40+
if (isset($dir[0])) {
41+
$dir = trim($dir);
42+
$dir = ($dir[0] == DIRECTORY_SEPARATOR) ? ltrim($dir, DIRECTORY_SEPARATOR) : $dir;
43+
$dir = ($dir[strlen($dir)-1] == DIRECTORY_SEPARATOR) ? rtrim($dir, DIRECTORY_SEPARATOR) : $dir;
44+
}
4345

4446
return $dir;
4547

@@ -74,6 +76,33 @@ public static function getOptions() {
7476
return self::$options;
7577
}
7678

79+
/**
80+
* Review the given styleguideKitPath to handle pre-2.1.0 backwards compatibility
81+
* @param {String} styleguideKitPath from config.yml
82+
*
83+
* @return {String} the final, post-2.1.0-style styleguideKitPath
84+
*/
85+
protected static function getStyleguideKitPath($styleguideKitPath = "") {
86+
87+
$styleguideKitPathFinal = "";
88+
if (isset($styleguideKitPath[0]) && ($styleguideKitPath[0] == DIRECTORY_SEPARATOR)) {
89+
if (strpos($styleguideKitPath, DIRECTORY_SEPARATOR."vendor".DIRECTORY_SEPARATOR === 0)) {
90+
$styleguideKitPathFinal = $styleguideKitPath; // mistaken set-up, pass to final for clean-up
91+
} else if (strpos($styleguideKitPath, self::$options["baseDir"]) === 0) {
92+
$styleguideKitPathFinal = str_replace(self::$options["baseDir"], "", $styleguideKitPath); // just need to peel off the base
93+
} else if (strpos($styleguideKitPath, DIRECTORY_SEPARATOR."vendor") !== false) {
94+
$parts = explode(DIRECTORY_SEPARATOR."vendor".DIRECTORY_SEPARATOR, $styleguideKitPath); // set on another machine's config.yml? try to be smart about it
95+
$styleguideKitPathFinal = "vendor".DIRECTORY_SEPARATOR.$parts[1];
96+
Console::writeInfo("Please double-check the styleguideKitPath option in <path>./config/config.yml</path>. It should be a path relative to the root of your Pattern Lab project...");
97+
}
98+
} else {
99+
$styleguideKitPathFinal = $styleguideKitPath; // fingers crossed everything is fine
100+
}
101+
102+
return $styleguideKitPathFinal;
103+
104+
}
105+
77106
/**
78107
* Adds the config options to a var to be accessed from the rest of the system
79108
* If it's an old config or no config exists this will update and generate it.
@@ -172,17 +201,39 @@ public static function init($baseDir = "", $verbose = true) {
172201
}
173202

174203
// set-up the various dirs
175-
self::$options["configDir"] = self::$userConfigDir;
176-
self::$options["coreDir"] = is_dir(self::$options["baseDir"]."_core") ? self::$options["baseDir"]."_core" : self::$options["baseDir"]."core";
177-
self::$options["exportDir"] = isset(self::$options["exportDir"]) ? self::$options["baseDir"].self::cleanDir(self::$options["exportDir"]) : self::$options["baseDir"]."exports";
178-
self::$options["publicDir"] = isset(self::$options["publicDir"]) ? self::$options["baseDir"].self::cleanDir(self::$options["publicDir"]) : self::$options["baseDir"]."public";
179-
self::$options["scriptsDir"] = isset(self::$options["scriptsDir"]) ? self::$options["baseDir"].self::cleanDir(self::$options["scriptsDir"]) : self::$options["baseDir"]."scripts";
180-
self::$options["sourceDir"] = isset(self::$options["sourceDir"]) ? self::$options["baseDir"].self::cleanDir(self::$options["sourceDir"]) : self::$options["baseDir"]."source";
181-
self::$options["componentDir"] = self::$options["publicDir"]."/patternlab-components";
182-
self::$options["dataDir"] = self::$options["sourceDir"]."/_data";
183-
self::$options["patternExportDir"] = self::$options["exportDir"]."/patterns";
184-
self::$options["patternPublicDir"] = self::$options["publicDir"]."/patterns";
185-
self::$options["patternSourceDir"] = self::$options["sourceDir"]."/_patterns";
204+
self::$options["configDir"] = self::$userConfigDir;
205+
self::$options["coreDir"] = is_dir(self::$options["baseDir"]."_core") ? self::$options["baseDir"]."_core" : self::$options["baseDir"]."core";
206+
self::$options["exportDir"] = isset(self::$options["exportDir"]) ? self::$options["baseDir"].self::cleanDir(self::$options["exportDir"]) : self::$options["baseDir"]."exports";
207+
self::$options["publicDir"] = isset(self::$options["publicDir"]) ? self::$options["baseDir"].self::cleanDir(self::$options["publicDir"]) : self::$options["baseDir"]."public";
208+
self::$options["scriptsDir"] = isset(self::$options["scriptsDir"]) ? self::$options["baseDir"].self::cleanDir(self::$options["scriptsDir"]) : self::$options["baseDir"]."scripts";
209+
self::$options["sourceDir"] = isset(self::$options["sourceDir"]) ? self::$options["baseDir"].self::cleanDir(self::$options["sourceDir"]) : self::$options["baseDir"]."source";
210+
self::$options["componentDir"] = self::$options["publicDir"]."/patternlab-components";
211+
self::$options["dataDir"] = self::$options["sourceDir"]."/_data";
212+
self::$options["patternExportDir"] = self::$options["exportDir"]."/patterns";
213+
self::$options["patternPublicDir"] = self::$options["publicDir"]."/patterns";
214+
self::$options["patternSourceDir"] = self::$options["sourceDir"]."/_patterns";
215+
216+
// handle a pre-2.1.0 styleguideKitPath before saving it
217+
if (isset(self::$options["styleguideKitPath"])) {
218+
self::$options["styleguideKitPath"] = self::$options["baseDir"].self::cleanDir(self::getStyleguideKitPath(self::$options["styleguideKitPath"]));
219+
}
220+
221+
// double-check a few directories are real
222+
// refactor this at some point. it's verbose
223+
if (!isset(self::$options["sourceDir"])) {
224+
Console::writeError("please make sure sourceDir is set in <path>./config/config.yml</path> by adding 'sourceDir=some/path'. sorry, stopping pattern lab... :(");
225+
} else if (!is_dir(self::$options["sourceDir"])) {
226+
Console::writeError("hrm... i can't seem to find the directory with your source files. are you sure they're at <path>".Console::getHumanReadablePath(self::$options["sourceDir"])."</path>? you can fix this in <path>./config/config.yml</path> by editing sourceDir. sorry, stopping pattern lab... :(");
227+
}
228+
if (!isset(self::$options["publicDir"])) {
229+
Console::writeError("please make sure publicDir is set in <path>./config/config.yml</path> by adding 'publicDir=some/path'. sorry, stopping pattern lab... :(");
230+
} else if (!is_dir(self::$options["publicDir"])) {
231+
Console::writeError("hrm... i can't seem to find the directory where you want to write your styleguide. are you sure it's at <path>".Console::getHumanReadablePath(self::$options["sourceDir"])."</path>? you can fix this in <path>./config/config.yml</path> by editing publicDir. sorry, stopping pattern lab... :(");
232+
}
233+
if (isset(self::$options["styleguideKitPath"]) && !is_dir(self::$options["styleguideKitPath"])) {
234+
Console::writeError("hrm... i can't seem to find the directory where your styleguide files are located. are you sure it's at <path>".Console::getHumanReadablePath(self::$options["styleguideKitPath"])."</path>? you can fix this in <path>./config/config.yml</path> by editing styleguideKitPath. sorry, stopping pattern lab... :(");
235+
}
236+
186237

187238
// make sure styleguideExcludes is set to an array even if it's empty
188239
if (is_string(self::$options["styleGuideExcludes"])) {

src/PatternLab/Console.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,16 @@ public static function writeInfo($line,$doubleSpace = false,$doubleBreak = false
477477
self::writeLine($lineFinal,$doubleSpace,$doubleBreak);
478478
}
479479

480+
/**
481+
* Alias for writeInfo because I keep wanting to use it
482+
* @param {String} the content to be written out
483+
* @param {Boolean} if there should be two spaces added to the beginning of the line
484+
* @param {Boolean} if there should be two breaks added to the end of the line
485+
*/
486+
public static function log($line,$doubleSpace = false,$doubleBreak = false) {
487+
self::writeInfo($line,$doubleSpace = false,$doubleBreak = false);
488+
}
489+
480490
/**
481491
* Write out a line to the console
482492
* @param {String} the content to be written out

src/PatternLab/Console/Commands/ServerCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function run() {
4949
$host = $port ? $host.":".$port : $host.":8080";
5050

5151
// start-up the server with the router
52-
Console::writeInfo("server started on ".$host.". use ctrl+c to exit...");
52+
Console::writeInfo("server started on http://".$host." - use ctrl+c to exit...");
5353
passthru("cd ".$publicDir." && ".$_SERVER["_"]." -S ".$host." ".$coreDir."/server/router.php");
5454

5555
}

src/PatternLab/InstallerUtil.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,12 +610,11 @@ protected static function packagesInstall($installerInfo) {
610610
// address other specific needs based on type
611611
if ($type == "patternlab-patternengine") {
612612
self::scanForPatternEngineRule($pathBase);
613-
} else if ($type == "patternlab-starterkit") {
614-
Config::updateConfigOption("starterKit",$name);
615-
Config::updateConfigOption("starterKitPath",$pathBase);
616613
} else if (($type == "patternlab-styleguidekit") && (strpos($name,"-assets-") === false)) {
614+
$dir = str_replace(Config::getOption("baseDir"), "", $pathBase);
615+
$dir = ($dir[strlen($dir)-1] == DIRECTORY_SEPARATOR) ? rtrim($dir, DIRECTORY_SEPARATOR) : $dir;
617616
Config::updateConfigOption("styleguideKit",$name);
618-
Config::updateConfigOption("styleguideKitPath",$pathBase);
617+
Config::updateConfigOption("styleguideKitPath",$dir);
619618
}
620619

621620
}

src/PatternLab/Template.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ public static function init() {
4848

4949
// load pattern-lab's resources
5050
$partialPath = $styleguideKitPath."/views/partials";
51-
self::$htmlHead = file_get_contents($partialPath."/general-header.".$patternExtension);
52-
self::$htmlFoot = file_get_contents($partialPath."/general-footer.".$patternExtension);
51+
$generalHeaderPath = $partialPath."/general-header.".$patternExtension;
52+
$generalFooterPath = $partialPath."/general-footer.".$patternExtension;
53+
self::$htmlHead = (file_exists($generalHeaderPath)) ? file_get_contents($generalHeaderPath) : "";
54+
self::$htmlFoot = (file_exists($generalFooterPath)) ? file_get_contents($generalFooterPath) : "";
5355

5456
// gather the user-defined header and footer information
5557
$patternHeadPath = $sourceDir."/_meta/_00-head.".$patternExtension;

0 commit comments

Comments
 (0)