Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: consolidating Pattern Loader #153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 2 additions & 18 deletions src/PatternLab/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,6 @@ protected function generateStyleguide() {
// default var
$publicDir = Config::getOption("publicDir");

// load the pattern loader
$ppdExporter = new PatternPathSrcExporter();
$patternPathSrc = $ppdExporter->run();
$options = array();
$options["patternPaths"] = $patternPathSrc;
$patternEngineBasePath = PatternEngine::getInstance()->getBasePath();
$patternLoaderClass = $patternEngineBasePath."\Loaders\PatternLoader";
$patternLoader = new $patternLoaderClass($options);

// check directories i need
if (!is_dir($publicDir."/styleguide/")) {
mkdir($publicDir."/styleguide/");
Expand All @@ -326,6 +317,7 @@ protected function generateStyleguide() {
// add the pattern lab specific mark-up
$filesystemLoader = Template::getFilesystemLoader();
$stringLoader = Template::getStringLoader();
$patternLoader = Template::getPatternLoader();

$globalData = Data::get();
$globalData["patternLabHead"] = $stringLoader->render(array("string" => Template::getHTMLHead(), "data" => array("cacheBuster" => $partials["cacheBuster"])));
Expand Down Expand Up @@ -364,17 +356,9 @@ protected function generateViewAllPages() {
$patternFoot = Template::getPatternFoot();
$filesystemLoader = Template::getFilesystemLoader();
$stringLoader = Template::getStringLoader();
$patternLoader = Template::getPatternLoader();
$globalData = Data::get();

// load the pattern loader
$ppdExporter = new PatternPathSrcExporter();
$patternPathSrc = $ppdExporter->run();
$options = array();
$options["patternPaths"] = $patternPathSrc;
$patternEngineBasePath = PatternEngine::getInstance()->getBasePath();
$patternLoaderClass = $patternEngineBasePath."\Loaders\PatternLoader";
$patternLoader = new $patternLoaderClass($options);

// make sure view all is set
$globalData["viewall"] = true;

Expand Down
6 changes: 1 addition & 5 deletions src/PatternLab/PatternData/Helpers/PatternCodeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,11 @@ public function run() {
$patternHead = Template::getPatternHead();
$patternFoot = Template::getPatternFoot();
$stringLoader = Template::getStringLoader();
$patternLoader = Template::getPatternLoader();

// re-load the pattern data since we modified it
$store = PatternData::get();

// load the pattern loader
$patternEngineBasePath = PatternEngine::getInstance()->getBasePath();
$patternLoaderClass = $patternEngineBasePath."\Loaders\PatternLoader";
$patternLoader = new $patternLoaderClass($options);

// iterate to process each pattern
foreach ($store as $patternStoreKey => $patternStoreData) {

Expand Down
22 changes: 17 additions & 5 deletions src/PatternLab/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use \PatternLab\Config;
use \PatternLab\Console;
use \PatternLab\Timer;
use \PatternLab\PatternData\Exporters\PatternPathSrcExporter;

class Template {

Expand Down Expand Up @@ -70,15 +71,19 @@ public static function init() {
$options = array();
$options["templatePath"] = $styleguideKitPath.DIRECTORY_SEPARATOR."views";
$options["partialsPath"] = $options["templatePath"].DIRECTORY_SEPARATOR."partials";

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

// add the stringLoader
$stringLoaderClass = $patternEngineBasePath."\Loaders\StringLoader";
self::$stringLoader = new $stringLoaderClass();

// i can't remember why i chose to implement the pattern loader directly in classes
// i figure i had a good reason which is why it's not showing up here


// add the patternLoader
$ppdExporter = new PatternPathSrcExporter();
$patternPathSrc = $ppdExporter->run();
$options = array();
$options["patternPaths"] = $patternPathSrc;
$patternLoaderClass = $patternEngineBasePath."\Loaders\PatternLoader";
self::$patternLoader = new $patternLoaderClass($options);
}

/*
Expand Down Expand Up @@ -122,5 +127,12 @@ public static function getFilesystemLoader() {
public static function getStringLoader() {
return self::$stringLoader;
}

/*
* Get the PatternLoader
*/
public static function getPatternLoader() {
return self::$patternLoader;
}

}