/**
  * 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);
                 }
             }
         }
     }
 }
Exemplo n.º 3
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");
 }