Skip to content

Commit 314c1be

Browse files
committed
Merge branch 'dev'
2 parents 0596477 + 6b9c468 commit 314c1be

File tree

9 files changed

+240
-80
lines changed

9 files changed

+240
-80
lines changed

src/PatternLab/Builder.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ protected function generatePatterns($options = array()) {
222222
$patternSourceDir = Config::getOption("patternSourceDir");
223223
$patternExtension = Config::getOption("patternExtension");
224224

225-
226225
// make sure the export dir exists
227226
if ($exportFiles && !is_dir($exportDir)) {
228227
mkdir($exportDir);

src/PatternLab/Config.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Config {
2626
protected static $userConfigDirClean = "config";
2727
protected static $userConfigDirDash = "_config";
2828
protected static $userConfigPath = "";
29-
protected static $plConfigPath = "../../config/config.yml.default";
29+
protected static $plConfigPath = "config/config.yml.default";
3030
protected static $dirAdded = false;
3131

3232
/**
@@ -105,7 +105,7 @@ public static function init($baseDir = "", $verbose = true) {
105105
self::$userConfigDirDash = self::$options["baseDir"].self::$userConfigDirDash;
106106
self::$userConfigDir = (is_dir(self::$userConfigDirDash)) ? self::$userConfigDirDash : self::$userConfigDirClean;
107107
self::$userConfigPath = self::$userConfigDir.DIRECTORY_SEPARATOR.self::$userConfig;
108-
self::$plConfigPath = __DIR__.DIRECTORY_SEPARATOR.self::$plConfigPath;
108+
self::$plConfigPath = self::$options["baseDir"]."vendor/pattern-lab/core/".self::$plConfigPath;
109109
self::$dirAdded = true;
110110

111111
// just in case the config directory doesn't exist at all
@@ -315,7 +315,7 @@ public static function updateConfigOption($optionName,$optionValue) {
315315
if ($currentOptionValue != $newOptionValue) {
316316

317317
// prompt for input
318-
$prompt = "update the config option <desc>".$optionName."</desc> with the value <desc>".$newOptionValue."</desc>?";
318+
$prompt = "update the config option <desc>".$optionName." (".$currentOptionValue.")</desc> with the value <desc>".$newOptionValue."</desc>?";
319319
$options = "Y/n";
320320
$input = Console::promptInput($prompt,$options);
321321

src/PatternLab/Console/Commands/ServerCommand.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,21 @@ public function __construct() {
2929

3030
public function run() {
3131

32-
// set-up defaults
33-
$publicDir = Config::getOption("publicDir");
34-
$coreDir = Config::getOption("coreDir");
35-
36-
Console::writeInfo("server started on localhost:8080. use ctrl+c to exit...");
37-
passthru("cd ".$publicDir." && ".$_SERVER["_"]." -S localhost:8080 ".$coreDir."/server/router.php");
32+
if (version_compare(phpversion(), '5.4.0', '<')) {
33+
34+
Console::writeWarning("you must have PHP 5.4.0 or greater to use this feature. you are using PHP ".phpversion()."...");
35+
36+
} else {
37+
38+
// set-up defaults
39+
$publicDir = Config::getOption("publicDir");
40+
$coreDir = Config::getOption("coreDir");
41+
42+
// start-up the server with the router
43+
Console::writeInfo("server started on localhost:8080. use ctrl+c to exit...");
44+
passthru("cd ".$publicDir." && ".$_SERVER["_"]." -S localhost:8080 ".$coreDir."/server/router.php");
45+
46+
}
3847

3948
}
4049

src/PatternLab/Fetch.php

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ public function fetchStarterKit($starterkit = "") {
6262
$tempDirDist = $tempDirSK.DIRECTORY_SEPARATOR."dist";
6363
$tempComposerFile = $tempDirSK.DIRECTORY_SEPARATOR."composer.json";
6464

65-
$fs = new Filesystem();
66-
6765
// figure out the options for the GH path
6866
list($org,$repo,$tag) = $this->getPackageInfo($starterkit);
6967

@@ -103,40 +101,19 @@ public function fetchStarterKit($starterkit = "") {
103101
if (file_exists($tempComposerFile)) {
104102

105103
$tempComposerJSON = json_decode(file_get_contents($tempComposerFile), true);
104+
105+
// see if it has a patternlab section that might define the files to move
106106
if (isset($tempComposerJSON["extra"]) && isset($tempComposerJSON["extra"]["patternlab"])) {
107107
Console::writeInfo("installing the starterkit...");
108108
InstallerUtil::parseComposerExtraList($tempComposerJSON["extra"]["patternlab"], $starterkit, $tempDirDist);
109109
Console::writeInfo("installed the starterkit...");
110110
} else {
111-
Console::writeError("the starterkit's composer.json file didn't have a valid format. missing patternlab directives...");
111+
$this->mirrorDist($sourceDir, $tempDirDist);
112112
}
113113

114114
} else {
115115

116-
// see if the source directory is empty
117-
$emptyDir = true;
118-
if (is_dir($sourceDir)) {
119-
$objects = new \DirectoryIterator($sourceDir);
120-
foreach ($objects as $object) {
121-
if (!$object->isDot() && ($object->getFilename() != "README") && ($object->getFilename() != ".DS_Store")) {
122-
$emptyDir = false;
123-
}
124-
}
125-
}
126-
127-
// if source directory isn't empty ask if it's ok to nuke what's there
128-
if (!$emptyDir) {
129-
130-
$prompt = "a starterkit is already installed. merge or replace?";
131-
$options = "M/r";
132-
$input = Console::promptInput($prompt,$options);
133-
$options = ($input == "r") ? array("delete" => true, "override" => true) : array("delete" => false, "override" => false);
134-
135-
}
136-
137-
Console::writeInfo("installing the starterkit files...");
138-
$fs->mirror($tempDirDist, $sourceDir, null, $options);
139-
Console::writeInfo("starterkit files have been installed...");
116+
$this->mirrorDist($sourceDir, $tempDirDist);
140117

141118
}
142119

@@ -147,6 +124,8 @@ public function fetchStarterKit($starterkit = "") {
147124

148125
Console::writeInfo("the starterkit installation is complete...");
149126

127+
return true;
128+
150129
}
151130

152131
/**
@@ -175,4 +154,43 @@ protected function getPackageInfo($package) {
175154

176155
}
177156

157+
/**
158+
* Force mirror the dist/ folder to source/
159+
* @param {String} path to the source directory
160+
* @param {String} path to the temp dist directory
161+
*/
162+
protected function mirrorDist($sourceDir, $tempDirDist) {
163+
164+
// set default vars
165+
$fsOptions = array();
166+
$emptyDir = true;
167+
168+
// see if the source directory is empty
169+
if (is_dir($sourceDir)) {
170+
$objects = new \DirectoryIterator($sourceDir);
171+
foreach ($objects as $object) {
172+
if (!$object->isDot() && ($object->getFilename() != "README") && ($object->getFilename() != ".DS_Store")) {
173+
$emptyDir = false;
174+
}
175+
}
176+
}
177+
178+
// if source directory isn't empty ask if it's ok to nuke what's there
179+
if (!$emptyDir) {
180+
181+
$prompt = "a starterkit is already installed. merge the new files with it or replace it?";
182+
$options = "M/r";
183+
$input = Console::promptInput($prompt,$options);
184+
$fsOptions = ($input == "r") ? array("delete" => true, "override" => true) : array("delete" => false, "override" => false);
185+
186+
}
187+
188+
// mirror dist to source
189+
Console::writeInfo("installing the starterkit files...");
190+
$fs = new Filesystem();
191+
$fs->mirror($tempDirDist, $sourceDir, null, $options);
192+
Console::writeInfo("starterkit files have been installed...");
193+
194+
}
195+
178196
}

src/PatternLab/InstallerUtil.php

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,7 @@ public static function parseComposerExtraList($composerExtra, $name, $pathDist)
158158
// see if we need to modify the config
159159
if (isset($composerExtra["config"])) {
160160

161-
foreach ($composerExtra["config"] as $optionInfo) {
162-
163-
// get config info
164-
$option = key($optionInfo);
165-
$value = $optionInfo[$option];
161+
foreach ($composerExtra["config"] as $option => $value) {
166162

167163
// update the config option
168164
Config::updateConfigOption($option,$value);
@@ -416,7 +412,72 @@ public static function postPackageUpdate($event) {
416412
}
417413

418414
/**
419-
* Make sure certain things are set-up before running composer's install
415+
* Ask questions after the create package is done
416+
* @param {Object} a script event object from composer
417+
*/
418+
public static function postCreateProjectCmd($event) {
419+
420+
// see if there is an extra component
421+
$extra = $event->getComposer()->getPackage()->getExtra();
422+
423+
if (isset($extra["patternlab"])) {
424+
425+
self::init();
426+
Console::writeLine("");
427+
428+
// see if we have any starterkits to suggest
429+
if (isset($extra["patternlab"]["starterKitSuggestions"]) && is_array($extra["patternlab"]["starterKitSuggestions"])) {
430+
431+
$suggestions = $extra["patternlab"]["starterKitSuggestions"];
432+
433+
// suggest starterkits
434+
Console::writeInfo("suggested starterkits that work with this edition:", false, true);
435+
foreach ($suggestions as $i => $suggestion) {
436+
437+
// write each suggestion
438+
$num = $i + 1;
439+
Console::writeLine($num.": ".$suggestion, true);
440+
441+
}
442+
443+
// prompt for input on the suggestions
444+
Console::writeLine("");
445+
$prompt = "choose an option or hit return to skip:";
446+
$options = "(ex. 1)";
447+
$input = Console::promptInput($prompt,$options);
448+
$result = (int)$input - 1;
449+
450+
if (isset($suggestions[$result])) {
451+
452+
Console::writeLine("");
453+
$f = new Fetch();
454+
$result = $f->fetchStarterKit($suggestions[$result]);
455+
456+
if ($result) {
457+
458+
Console::writeLine("");
459+
$g = new Generator();
460+
$g->generate(array("foo" => "bar"));
461+
462+
Console::writeLine("");
463+
Console::writeInfo("type <desc>php core/console --server</desc> to start the built-in server and see Pattern Lab...", false, true);
464+
465+
}
466+
467+
} else {
468+
469+
Console::writeWarning("you will need to install a StarterKit before using Pattern Lab...");
470+
471+
}
472+
473+
}
474+
475+
}
476+
477+
}
478+
479+
/**
480+
* Make sure certain things are set-up before running the installation of a package
420481
* @param {Object} a script event object from composer
421482
*/
422483
public static function preInstallCmd($event) {
@@ -513,7 +574,7 @@ protected static function runTasks($event,$type) {
513574
self::scanForPatternEngineRule($pathBase);
514575
} else if ($type == "patternlab-starterkit") {
515576
Config::updateConfigOption("starterKit",$name);
516-
} else if ($type == "patternlab-styleguidekit") {
577+
} else if (($type == "patternlab-styleguidekit") && (strpos($name,"-assets-") === false)) {
517578
Config::updateConfigOption("styleguideKit",$name);
518579
}
519580

src/PatternLab/PatternData.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use \PatternLab\PatternData\Helpers\LineageHelper;
2424
use \PatternLab\PatternData\Helpers\PatternCodeHelper;
2525
use \PatternLab\PatternData\Helpers\PatternStateHelper;
26+
use \PatternLab\PatternData\Helpers\RawPatternHelper;
2627
use \PatternLab\Timer;
2728

2829
class PatternData {
@@ -153,14 +154,42 @@ public static function gather($options = array()) {
153154
$dataMergeExporter = new DataMergeExporter();
154155
$dataMergeExporter->run();
155156

157+
// dispatch that the raw pattern helper is about to start
158+
$event = new PatternDataEvent($options);
159+
$dispatcherInstance->dispatch("patternData.rawPatternHelperStart",$event);
160+
161+
// add the lineage info to PatternData::$store
162+
$rawPatternHelper = new RawPatternHelper();
163+
$rawPatternHelper->run();
164+
165+
// dispatch that the raw pattern helper is ended
166+
$event = new PatternDataEvent($options);
167+
$dispatcherInstance->dispatch("patternData.rawPatternHelperEnd",$event);
168+
169+
// dispatch that the lineage helper is about to start
170+
$event = new PatternDataEvent($options);
171+
$dispatcherInstance->dispatch("patternData.lineageHelperStart",$event);
172+
156173
// add the lineage info to PatternData::$store
157174
$lineageHelper = new LineageHelper();
158175
$lineageHelper->run();
159176

177+
// dispatch that the lineage helper is ended
178+
$event = new PatternDataEvent($options);
179+
$dispatcherInstance->dispatch("patternData.lineageHelperEnd",$event);
180+
181+
// dispatch that the pattern state helper is about to start
182+
$event = new PatternDataEvent($options);
183+
$dispatcherInstance->dispatch("patternData.patternStateHelperStart",$event);
184+
160185
// using the lineage info update the pattern states on PatternData::$store
161186
$patternStateHelper = new PatternStateHelper();
162187
$patternStateHelper->run();
163188

189+
// dispatch that the pattern state helper is ended
190+
$event = new PatternDataEvent($options);
191+
$dispatcherInstance->dispatch("patternData.patternStateHelperEnd",$event);
192+
164193
// set-up code pattern paths
165194
$ppdExporter = new PatternPathSrcExporter();
166195
$patternPathSrc = $ppdExporter->run();
@@ -177,6 +206,10 @@ public static function gather($options = array()) {
177206
$patternCodeHelper = new PatternCodeHelper($options);
178207
$patternCodeHelper->run();
179208

209+
// dispatch that the pattern code helper is ended
210+
$event = new PatternDataEvent($options);
211+
$dispatcherInstance->dispatch("patternData.patternCodeHelperEnd",$event);
212+
180213
// dispatch that the gather has ended
181214
$event = new PatternDataEvent($options);
182215
$dispatcherInstance->dispatch("patternData.gatherEnd",$event);

src/PatternLab/PatternData/Helpers/LineageHelper.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@
1919

2020
class LineageHelper extends \PatternLab\PatternData\Helper {
2121

22+
protected $lineageMatch;
23+
protected $lineageMatchKey;
24+
2225
public function __construct($options = array()) {
2326

2427
parent::__construct($options);
2528

29+
$this->lineageMatch = html_entity_decode(Config::getOption("lineageMatch"),ENT_QUOTES);
30+
$this->lineageMatchKey = Config::getOption("lineageMatchKey");
31+
2632
}
2733

2834
public function run() {
@@ -39,12 +45,8 @@ public function run() {
3945
if (($patternStoreData["category"] == "pattern") && (!isset($patternStoreData["pseudo"]))) {
4046

4147
$patternLineages = array();
42-
$fileName = $patternStoreData["pathName"].".".$patternExtension;
43-
$fileNameFull = $patternSourceDir."/".$fileName;
44-
45-
if (file_exists($fileNameFull)) {
46-
$foundLineages = $this->findLineages($fileNameFull);
47-
}
48+
$fileData = isset($patternStoreData["patternRaw"]) ? $patternStoreData["patternRaw"] : "";
49+
$foundLineages = $this->findLineages($fileData);
4850

4951
if (!empty($foundLineages)) {
5052

@@ -58,6 +60,7 @@ public function run() {
5860
} else {
5961

6062
if (strpos($lineage, '/') === false) {
63+
$fileName = $patternStoreData["pathName"].".".$patternExtension;
6164
Console::writeWarning("you may have a typo in ".$fileName.". {{> ".$lineage." }} is not a valid pattern...");
6265
}
6366

@@ -160,14 +163,13 @@ public function run() {
160163

161164
/**
162165
* Get the lineage for a given pattern by parsing it and matching mustache partials
163-
* @param {String} the filename for the pattern to be parsed
166+
* @param {String} the data from the raw pattern
164167
*
165168
* @return {Array} a list of patterns
166169
*/
167-
protected function findLineages($filename) {
168-
$data = file_get_contents($filename);
169-
if (preg_match_all('/{{>([ ]+)?([A-Za-z0-9-_]+)(?:\:[A-Za-z0-9-]+)?(?:(| )\(.*)?([ ]+)?}}/',$data,$matches)) {
170-
return array_unique($matches[2]);
170+
protected function findLineages($data) {
171+
if (preg_match_all("/".$this->lineageMatch."/",$data,$matches)) {
172+
return array_unique($matches[$this->lineageMatchKey]);
171173
}
172174
return array();
173175
}

0 commit comments

Comments
 (0)