/**
  * Compare the search and ignore props against the name.
  * Can use && or || in the comparison
  * @param  {String}       the type of the pattern that should be used in the view all
  * @param  {String}       the subtype of the pattern that be used in the view all
  *
  * @return {Array}        the list of partials
  */
 public function run($type = "", $subtype = "")
 {
     // default vars
     $patternPartials = array();
     $styleGuideExcludes = Config::getOption("styleGuideExcludes");
     $store = PatternData::get();
     foreach ($store as $patternStoreKey => $patternStoreData) {
         $fileName = FileChangeList::getFileNameByPatternData($patternStoreData);
         if (!Config::getOption("update") || FileChangeList::hasChanged($fileName)) {
             if ($patternStoreData["category"] == "pattern" && !$patternStoreData["hidden"] && !$patternStoreData["noviewall"] && $patternStoreData["depth"] == 2 && !in_array($patternStoreData["type"], $styleGuideExcludes)) {
                 if ($patternStoreData["type"] == $type && empty($subtype) || empty($type) && empty($subtype) || $patternStoreData["type"] == $type && $patternStoreData["subtype"] == $subtype) {
                     $patternPartialData = array();
                     $patternPartialData["patternName"] = ucwords($patternStoreData["nameClean"]);
                     $patternPartialData["patternLink"] = $patternStoreData["pathDash"] . "/" . $patternStoreData["pathDash"] . ".html";
                     $patternPartialData["patternPartial"] = $patternStoreData["partial"];
                     $patternPartialData["patternPartialCode"] = $patternStoreData["code"];
                     $patternPartialData["patternLineageExists"] = isset($patternStoreData["lineages"]);
                     $patternPartialData["patternLineages"] = isset($patternStoreData["lineages"]) ? $patternStoreData["lineages"] : array();
                     $patternPartialData["patternLineageRExists"] = isset($patternStoreData["lineagesR"]);
                     $patternPartialData["patternLineagesR"] = isset($patternStoreData["lineagesR"]) ? $patternStoreData["lineagesR"] : array();
                     $patternPartialData["patternLineageEExists"] = isset($patternStoreData["lineages"]) || isset($patternStoreData["lineagesR"]);
                     $patternPartialData["patternDescExists"] = isset($patternStoreData["desc"]);
                     $patternPartialData["patternDesc"] = isset($patternStoreData["desc"]) ? $patternStoreData["desc"] : "";
                     $patternPartialData["patternDescAdditions"] = isset($patternStoreData["partialViewDescAdditions"]) ? $patternStoreData["partialViewDescAdditions"] : array();
                     $patternPartialData["patternExampleAdditions"] = isset($patternStoreData["partialViewExampleAdditions"]) ? $patternStoreData["partialViewExampleAdditions"] : array();
                     //$patternPartialData["patternCSSExists"]        = Config::$options["enableCSS"];
                     $patternPartialData["patternCSSExists"] = false;
                     $patternPartials[] = $patternPartialData;
                 }
             }
         }
     }
     return array("partials" => $patternPartials, "cacheBuster" => Data::getOption("cacheBuster"));
 }
 public function run()
 {
     // default vars
     $options = array();
     $options["patternPaths"] = $this->patternPaths;
     $patternExtension = Config::getOption("patternExtension");
     $patternSourceDir = Config::getOption("patternSourceDir");
     $htmlHead = Template::getHTMLHead();
     $htmlFoot = Template::getHTMLFoot();
     $patternHead = Template::getPatternHead();
     $patternFoot = Template::getPatternFoot();
     $stringLoader = Template::getStringLoader();
     // 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
     FileChangeList::touchParentPatterns($store);
     foreach ($store as $patternStoreKey => $patternStoreData) {
         if ($patternStoreData["category"] == "pattern" && !$patternStoreData["hidden"]) {
             $fileName = FileChangeList::getFileNameByPatternData($patternStoreData);
             if (!Config::getOption("update") || FileChangeList::hasChanged($fileName)) {
                 $data = Data::getPatternSpecificData($patternStoreKey);
                 // add the pattern data so it can be exported
                 $patternData = array();
                 //$patternFooterData["patternFooterData"]["cssEnabled"]      = (Config::$options["enableCSS"] && isset($this->patternCSS[$p])) ? "true" : "false";
                 $patternData["cssEnabled"] = false;
                 $patternData["lineage"] = isset($patternStoreData["lineages"]) ? $patternStoreData["lineages"] : array();
                 $patternData["lineageR"] = isset($patternStoreData["lineagesR"]) ? $patternStoreData["lineagesR"] : array();
                 $patternData["patternBreadcrumb"] = $patternStoreData["breadcrumb"];
                 $patternData["patternDesc"] = isset($patternStoreData["desc"]) ? $patternStoreData["desc"] : "";
                 $patternData["patternExtension"] = $patternExtension;
                 $patternData["patternName"] = $patternStoreData["nameClean"];
                 $patternData["patternPartial"] = $patternStoreData["partial"];
                 $patternData["patternState"] = $patternStoreData["state"];
                 // extra copy for the code view
                 $patternData["extraOutput"] = isset($patternStoreData["extraOutput"]) ? $patternStoreData["extraOutput"] : array();
                 // add the pattern lab specific mark-up
                 // set a default var
                 $exportClean = isset($options["exportClean"]) ? $options["exportClean"] : false;
                 $data["patternLabHead"] = !$this->exportFiles ? $stringLoader->render(array("string" => $htmlHead, "data" => array("cacheBuster" => $data["cacheBuster"]))) : "";
                 $data["patternLabFoot"] = !$this->exportFiles ? $stringLoader->render(array("string" => $htmlFoot, "data" => array("cacheBuster" => $data["cacheBuster"], "patternData" => json_encode($patternData)))) : "";
                 if (isset($patternStoreData["patternRaw"])) {
                     $header = !$this->exportClean ? $stringLoader->render(array("string" => $patternHead, "data" => $data)) : "";
                     $code = $patternLoader->render(array("pattern" => $patternStoreData["patternRaw"], "data" => $data));
                     $footer = !$this->exportClean ? $stringLoader->render(array("string" => $patternFoot, "data" => $data)) : "";
                     PatternData::setPatternOption($patternStoreKey, "header", $header);
                     PatternData::setPatternOption($patternStoreKey, "code", $code);
                     PatternData::setPatternOption($patternStoreKey, "footer", $footer);
                 }
             }
         }
     }
 }
 public function testIsUpdate()
 {
     Config::init(__DIR__ . "/../../../../../../", false);
     $sd = Config::getOption("patternSourceDir");
     $fileName = $sd . "/00-atoms/_unused/banner.twig";
     $patternStore = ['bla' => ['pathName' => "00-atoms/_unused/banner", 'ext' => 'twig']];
     FileChangeList::init(Config::getOption("publicDir") . DIRECTORY_SEPARATOR . "fileChangeList.csv");
     $this->assertTrue(touch($fileName, time() + 100));
     FileChangeList::write();
     touch($fileName, time());
     clearstatcache();
     FileChangeList::init(Config::getOption("publicDir") . DIRECTORY_SEPARATOR . "fileChangeList.csv");
     $condition = FileChangeList::hasChanged($fileName);
     $this->assertTrue($condition);
 }
Ejemplo n.º 4
0
 /**
  * Move static files from source/ to public/
  */
 protected function moveStatic()
 {
     // set-up the dispatcher
     $dispatcherInstance = Dispatcher::getInstance();
     // note the start of the operation
     $dispatcherInstance->dispatch("generator.moveStaticStart");
     // common values
     $publicDir = Config::getOption("publicDir");
     $sourceDir = Config::getOption("sourceDir");
     $ignoreExt = Config::getOption("ie");
     $ignoreDir = Config::getOption("id");
     // iterate over all of the other files in the source directory
     $objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($sourceDir), \RecursiveIteratorIterator::SELF_FIRST);
     // make sure dots are skipped
     $objects->setFlags(\FilesystemIterator::SKIP_DOTS);
     foreach ($objects as $name => $object) {
         // clean-up the file name and make sure it's not one of the pattern lab files or to be ignored
         $fileName = str_replace($sourceDir . DIRECTORY_SEPARATOR, "", $name);
         if ($fileName[0] != "_" && !in_array($object->getExtension(), $ignoreExt) && !in_array($object->getFilename(), $ignoreDir)) {
             // catch directories that have the ignored dir in their path
             $ignored = FileUtil::ignoreDir($fileName);
             // check to see if it's a new directory
             if (!$ignored && $object->isDir() && !is_dir($publicDir . "/" . $fileName)) {
                 mkdir($publicDir . "/" . $fileName);
             }
             // check to see if it's a new file or a file that has changed
             $sourceFileName = $sourceDir . DIRECTORY_SEPARATOR . $fileName;
             if (!$ignored && $object->isFile() && FileChangeList::hasChanged($sourceFileName)) {
                 FileUtil::moveStaticFile($fileName);
                 FileChangeList::update($sourceFileName);
             }
         }
     }
     // note the end of the operation
     $dispatcherInstance->dispatch("generator.moveStaticEnd");
 }
Ejemplo n.º 5
0
 /**
  * Generates the view all pages
  */
 protected function generateViewAllPages()
 {
     // set-up the dispatcher
     $dispatcherInstance = Dispatcher::getInstance();
     // note the beginning of the operation
     $dispatcherInstance->dispatch("builder.generateViewAllPagesStart");
     // default vars
     $patternPublicDir = Config::getOption("patternPublicDir");
     $htmlHead = Template::getHTMLHead();
     $htmlFoot = Template::getHTMLFoot();
     $patternHead = Template::getPatternHead();
     $patternFoot = Template::getPatternFoot();
     $filesystemLoader = Template::getFilesystemLoader();
     $stringLoader = Template::getStringLoader();
     // make sure the pattern dir exists
     if (!is_dir($patternPublicDir)) {
         mkdir($patternPublicDir);
     }
     // add view all to each list
     $store = PatternData::get();
     foreach ($store as $patternStoreKey => $patternStoreData) {
         if ($patternStoreData["category"] == "patternSubtype") {
             $fileName = FileChangeList::getFileNameByPatternData($patternStoreData);
             if (!Config::getOption("update") || FileChangeList::hasChanged($fileName)) {
                 // grab the partials into a data object for the style guide
                 $ppExporter = new PatternPartialsExporter();
                 $partials = $ppExporter->run($patternStoreData["type"], $patternStoreData["name"]);
                 if (!empty($partials["partials"])) {
                     // add the pattern data so it can be exported
                     $patternData = array();
                     $patternData["patternPartial"] = "viewall-" . $patternStoreData["typeDash"] . "-" . $patternStoreData["nameDash"];
                     // add the pattern lab specific mark-up
                     $partials["patternLabHead"] = $stringLoader->render(array("string" => $htmlHead, "data" => array("cacheBuster" => $partials["cacheBuster"])));
                     $partials["patternLabFoot"] = $stringLoader->render(array("string" => $htmlFoot, "data" => array("cacheBuster" => $partials["cacheBuster"], "patternData" => json_encode($patternData))));
                     // render the parts and join them
                     $header = $stringLoader->render(array("string" => $patternHead, "data" => $partials));
                     $code = $filesystemLoader->render(array("template" => "viewall", "data" => $partials));
                     $footer = $stringLoader->render(array("string" => $patternFoot, "data" => $partials));
                     $viewAllPage = $header . $code . $footer;
                     // if the pattern directory doesn't exist create it
                     $patternPath = $patternStoreData["pathDash"];
                     if (!is_dir($patternPublicDir . "/" . $patternPath)) {
                         mkdir($patternPublicDir . "/" . $patternPath);
                         file_put_contents($patternPublicDir . "/" . $patternPath . "/index.html", $viewAllPage);
                     } else {
                         file_put_contents($patternPublicDir . "/" . $patternPath . "/index.html", $viewAllPage);
                     }
                 }
             }
         } else {
             if ($patternStoreData["category"] == "patternType" && PatternData::hasPatternSubtype($patternStoreData["nameDash"])) {
                 $fileName = FileChangeList::getFileNameByPatternData($patternStoreData);
                 if (!Config::getOption("update") || FileChangeList::hasChanged($fileName)) {
                     // grab the partials into a data object for the style guide
                     $ppExporter = new PatternPartialsExporter();
                     $partials = $ppExporter->run($patternStoreData["name"]);
                     if (!empty($partials["partials"])) {
                         // add the pattern data so it can be exported
                         $patternData = array();
                         $patternData["patternPartial"] = "viewall-" . $patternStoreData["nameDash"] . "-all";
                         // add the pattern lab specific mark-up
                         $partials["patternLabHead"] = $stringLoader->render(array("string" => $htmlHead, "data" => array("cacheBuster" => $partials["cacheBuster"])));
                         $partials["patternLabFoot"] = $stringLoader->render(array("string" => $htmlFoot, "data" => array("cacheBuster" => $partials["cacheBuster"], "patternData" => json_encode($patternData))));
                         // render the parts and join them
                         $header = $stringLoader->render(array("string" => $patternHead, "data" => $partials));
                         $code = $filesystemLoader->render(array("template" => "viewall", "data" => $partials));
                         $footer = $stringLoader->render(array("string" => $patternFoot, "data" => $partials));
                         $viewAllPage = $header . $code . $footer;
                         // if the pattern directory doesn't exist create it
                         $patternPath = $patternStoreData["pathDash"];
                         if (!is_dir($patternPublicDir . "/" . $patternPath)) {
                             mkdir($patternPublicDir . "/" . $patternPath);
                             file_put_contents($patternPublicDir . "/" . $patternPath . "/index.html", $viewAllPage);
                         } else {
                             file_put_contents($patternPublicDir . "/" . $patternPath . "/index.html", $viewAllPage);
                         }
                     }
                 }
             }
         }
     }
     // note the end of the operation
     $dispatcherInstance->dispatch("builder.generateViewAllPagesEnd");
 }