public function run($depth, $ext, $path, $pathName, $name) { // load default vars $dirSep = PatternData::getDirSep(); // set-up the names $patternType = $name; // 00-atoms $patternTypeDash = $this->getPatternName($name, false); // atoms $patternTypeClean = str_replace("-", " ", $patternTypeDash); // atoms (dashes replaced with spaces) $patternTypePath = $pathName; // 00-atoms/02-blocks $patternTypePathDash = str_replace($dirSep, "-", $patternTypePath); // 00-atoms-02-blocks (file path) // create a key for the data store $patternStoreKey = $patternTypeDash . "-pltype"; // add a new patternType to the nav $patternData = array("category" => "patternType", "name" => $patternType, "nameDash" => $patternTypeDash, "nameClean" => $patternTypeClean, "depth" => $depth, "ext" => $ext, "path" => $path, "pathName" => $patternTypePath, "pathDash" => $patternTypePathDash, "isDir" => $this->isDirProp, "isFile" => $this->isFileProp); PatternData::setOption($patternStoreKey, $patternData); // starting a new set of pattern types. it might not have any pattern subtypes PatternData::setPatternType($patternType); PatternData::setPatternTypeClean($patternTypeClean); PatternData::setPatternTypeDash($patternTypeDash); }
public function run($depth, $ext, $path, $pathName, $name) { // load default vars $patternType = PatternData::getPatternType(); $patternTypeDash = PatternData::getPatternTypeDash(); $patternTypeClean = PatternData::getPatternTypeClean(); $dirSep = PatternData::getDirSep(); // set-up the names $patternSubtype = $name; // 02-blocks $patternSubtypeDash = $this->getPatternName($name, false); // blocks $patternSubtypeClean = str_replace("-", " ", $patternSubtypeDash); // blocks (dashes replaced with spaces) $patternSubtypePath = $pathName; // 00-atoms/02-blocks $patternSubtypePathDash = str_replace($dirSep, "-", $patternSubtypePath); // 00-atoms-02-blocks (file path) // create a key for the data store $patternStoreKey = $patternTypeDash . "-" . $patternSubtypeDash . "-plsubtype"; // collect the data $patternStoreData = array("category" => "patternSubtype", "name" => $patternSubtype, "nameDash" => $patternSubtypeDash, "nameClean" => $patternSubtypeClean, "type" => $patternType, "typeDash" => $patternTypeDash, "breadcrumb" => $patternTypeClean, "depth" => $depth, "ext" => $ext, "path" => $path, "pathName" => $patternSubtypePath, "pathDash" => $patternSubtypePathDash, "isDir" => $this->isDirProp, "isFile" => $this->isFileProp); // if the pattern data store already exists make sure it is merged and overwrites this data $patternStoreData = PatternData::checkOption($patternStoreKey) ? array_replace_recursive(PatternData::getOption($patternStoreKey), $patternStoreData) : $patternStoreData; PatternData::setOption($patternStoreKey, $patternStoreData); // starting a new set of pattern types. it might not have any pattern subtypes PatternData::setPatternSubtype($patternSubtype); PatternData::setPatternSubtypeClean($patternSubtypeClean); PatternData::setPatternSubtypeDash($patternSubtypeDash); PatternData::setPatternSubtypeSet(true); }
public function run($depth, $ext, $path, $pathName, $name) { // load default vars $patternSubtype = PatternData::getPatternSubtype(); $patternSubtypeClean = PatternData::getPatternSubtypeClean(); $patternSubtypeDash = PatternData::getPatternSubtypeDash(); $patternType = PatternData::getPatternType(); $patternTypeClean = PatternData::getPatternTypeClean(); $patternTypeDash = PatternData::getPatternTypeDash(); $dirSep = PatternData::getDirSep(); $frontMeta = PatternData::getFrontMeta(); // should this pattern get rendered? $hidden = $name[0] == "_"; $noviewall = $name[0] == "-"; // set-up the names $patternFull = in_array($name[0], $frontMeta) ? substr($name, 1) : $name; // 00-colors.mustache $pattern = str_replace("." . $this->extProp, "", $patternFull); // 00-colors $patternState = ""; // check for pattern state if (strpos($pattern, "@") !== false) { $patternBits = explode("@", $pattern, 2); $pattern = $patternBits[0]; $patternState = $patternBits[1]; } // finish setting up vars $patternDash = $this->getPatternName($pattern, false); // colors $patternClean = str_replace("-", " ", $patternDash); // colors (dashes replaced with spaces) $patternPartial = $patternTypeDash . "-" . $patternDash; // atoms-colors $patternPath = str_replace("." . $this->extProp, "", $pathName); // 00-atoms/01-global/00-colors $patternPathDash = str_replace($dirSep, "-", $patternPath); // 00-atoms-01-global-00-colors (file path) // create a key for the data store $patternStoreKey = $patternPartial; // collect the data $patternStoreData = array("category" => "pattern", "name" => $pattern, "partial" => $patternPartial, "nameDash" => $patternDash, "nameClean" => $patternClean, "type" => $patternType, "typeDash" => $patternTypeDash, "breadcrumb" => $patternTypeClean, "state" => $patternState, "hidden" => $hidden, "noviewall" => $noviewall, "depth" => $depth, "ext" => $ext, "path" => $path, "pathName" => $patternPath, "pathDash" => $patternPathDash, "isDir" => $this->isDirProp, "isFile" => $this->isFileProp, "partialViewDescAdditions" => array(), "partialViewExampleAdditions" => array(), "extraHolder" => array(), "extraOutput" => array()); // add any subtype info if necessary if ($depth == 2) { $patternStoreData["subtype"] = $patternSubtype; $patternStoreData["subtypeDash"] = $patternSubtypeDash; $patternStoreData["breadcrumb"] = $patternTypeClean . " > " . $patternSubtypeClean; } // if the pattern data store already exists make sure it is merged and overwrites this data $patternStoreData = PatternData::checkOption($patternStoreKey) ? array_replace_recursive(PatternData::getOption($patternStoreKey), $patternStoreData) : $patternStoreData; PatternData::setOption($patternStoreKey, $patternStoreData); }
public function run($depth, $ext, $path, $pathName, $name) { // load default vars $patternType = PatternData::getPatternType(); $patternTypeDash = PatternData::getPatternTypeDash(); $dirSep = PatternData::getDirSep(); // make sure the pattern isn't hidden $hidden = $name[0] == "_"; // set-up the names, $name == 00-colors.md $doc = str_replace("." . $this->extProp, "", $name); // 00-colors $docDash = $this->getPatternName(str_replace("_", "", $doc), false); // colors $docPartial = $patternTypeDash . "-" . $docDash; // if the pattern isn't hidden do stuff if (!$hidden) { // default vars $patternSourceDir = Config::getOption("patternSourceDir"); // parse data $text = file_get_contents($patternSourceDir . "/" . $pathName); list($yaml, $markdown) = Documentation::parse($text); // grab the title and unset it from the yaml so it doesn't get duped in the meta if (isset($yaml["title"])) { $title = $yaml["title"]; unset($yaml["title"]); } // figure out if this is a pattern subtype $patternSubtypeDoc = false; if ($depth == 1) { // go through all of the directories to see if this one matches our doc foreach (glob($patternSourceDir . "/" . $patternType . "/*", GLOB_ONLYDIR) as $dir) { $dir = str_replace($patternSourceDir . "/" . $patternType . "/", "", $dir); if ($dir == $doc) { $patternSubtypeDoc = true; break; } } } $category = $patternSubtypeDoc ? "patternSubtype" : "pattern"; $patternStoreKey = $patternSubtypeDoc ? $docPartial . "-plsubtype" : $docPartial; $patternStoreData = array("category" => $category, "nameClean" => $title, "desc" => $markdown, "descExists" => true, "meta" => $yaml, "full" => $doc); // if the pattern data store already exists make sure this data overwrites it $patternStoreData = PatternData::checkOption($patternStoreKey) ? array_replace_recursive(PatternData::getOption($patternStoreKey), $patternStoreData) : $patternStoreData; PatternData::setOption($patternStoreKey, $patternStoreData); } }
public function run($depth, $ext, $path, $pathName, $name) { // load default vars $patternTypeDash = PatternData::getPatternTypeDash(); // set-up the names, $name == foo.listitems.json $pattern = str_replace(".listitems." . $ext, "", $name); // foo $patternDash = $this->getPatternName($pattern, false); // foo $patternPartial = $patternTypeDash . "-" . $patternDash; // atoms-foo $patternStoreData = array("category" => "pattern"); $data = Data::getListItems("_patterns/" . $pathName, $ext); $patternStoreData["listItems"] = $data; // create a key for the data store $patternStoreKey = $patternPartial; // if the pattern data store already exists make sure it is merged and overwrites this data $patternStoreData = PatternData::checkOption($patternStoreKey) ? array_replace_recursive(PatternData::getOption($patternStoreKey), $patternStoreData) : $patternStoreData; PatternData::setOption($patternStoreKey, $patternStoreData); }
public function run($depth, $ext, $path, $pathName, $name) { // load default vars $patternTypeDash = PatternData::getPatternTypeDash(); // should this pattern get rendered? $hidden = $name[0] == "_"; // set-up the names, $name == foo.json $pattern = str_replace("." . $ext, "", $name); // foo $patternDash = $this->getPatternName($pattern, false); // foo $patternPartial = $patternTypeDash . "-" . $patternDash; // atoms-foo if (!$hidden) { $patternStoreData = array("category" => "pattern"); $file = file_get_contents(Config::getOption("patternSourceDir") . "/" . $pathName); if ($ext == "json") { $data = json_decode($file, true); if ($jsonErrorMessage = JSON::hasError()) { JSON::lastErrorMsg($name, $jsonErrorMessage, $data); } } else { try { $data = YAML::parse($file); } catch (ParseException $e) { printf("unable to parse " . $pathNameClean . ": %s..\n", $e->getMessage()); } // single line of text won't throw a YAML error. returns as string if (gettype($data) == "string") { $data = array(); } } $patternStoreData["data"] = $data; // create a key for the data store $patternStoreKey = $patternPartial; // if the pattern data store already exists make sure it is merged and overwrites this data $patternStoreData = PatternData::checkOption($patternStoreKey) ? array_replace_recursive(PatternData::getOption($patternStoreKey), $patternStoreData) : $patternStoreData; PatternData::setOption($patternStoreKey, $patternStoreData); } }
public function run($depth, $ext, $path, $pathName, $name) { // load default vars $patternSubtype = PatternData::getPatternSubtype(); $patternSubtypeClean = PatternData::getPatternSubtypeClean(); $patternSubtypeDash = PatternData::getPatternSubtypeDash(); $patternType = PatternData::getPatternType(); $patternTypeClean = PatternData::getPatternTypeClean(); $patternTypeDash = PatternData::getPatternTypeDash(); $dirSep = PatternData::getDirSep(); $frontMeta = PatternData::getFrontMeta(); // should this pattern get rendered? $hidden = $name[0] == "_"; $noviewall = $name[0] == "-"; // set-up the names $patternFull = in_array($name[0], $frontMeta) ? substr($name, 1) : $name; // 00-colors~foo.mustache $patternState = ""; // check for pattern state if (strpos($patternFull, "@") !== false) { $patternBits = explode("@", $patternFull, 2); $patternState = str_replace("." . $ext, "", $patternBits[1]); $patternFull = preg_replace("/@(.*?)\\./", ".", $patternFull); } // finish setting up vars $patternBits = explode("~", $patternFull); $patternBase = $patternBits[0] . "." . Config::getOption("patternExtension"); // 00-homepage.mustache $patternBaseDash = $this->getPatternName($patternBits[0], false); // homepage $patternBaseOrig = $patternTypeDash . "-" . $patternBaseDash; // pages-homepage $patternBaseData = $patternBits[0] . "." . $ext; // 00-homepage.json $stripJSON = str_replace("." . $ext, "", $patternBits[1]); $patternBitClean = preg_replace("/@(.*?)/", "", $patternBits[0]); $pattern = $patternBitClean . "-" . $stripJSON; // 00-homepage-00-emergency $patternInt = $patternBitClean . "-" . $this->getPatternName($stripJSON, false); // 00-homepage-emergency $patternDash = $this->getPatternName($patternInt, false); // homepage-emergency $patternClean = str_replace("-", " ", $patternDash); // homepage emergency $patternPartial = $patternTypeDash . "-" . $patternDash; // pages-homepage-emergency $patternPath = str_replace("." . $ext, "", str_replace("~", "-", $pathName)); // 00-atoms/01-global/00-colors $patternPathDash = str_replace($dirSep, "-", $patternPath); // 00-atoms-01-global-00-colors (file path) // check the original pattern path. if it doesn't exist make a guess $patternPathOrig = PatternData::getPatternOption($patternBaseOrig, "pathName"); // 04-pages/00-homepage $patternPathOrigDash = PatternData::getPatternOption($patternBaseOrig, "pathDash"); // 04-pages-00-homepage if (!$patternPathOrig) { $patternPathOrigBits = explode("~", $pathName); $patternPathOrig = $patternPathOrigBits[0]; // 04-pages/00-homepage $patternPathOrigDash = str_replace($dirSep, "-", $patternPathOrig); // 04-pages-00-homepage } // create a key for the data store $patternStoreKey = $patternPartial; // collect the data $patternStoreData = array("category" => "pattern", "name" => $pattern, "partial" => $patternPartial, "nameDash" => $patternDash, "nameClean" => $patternClean, "type" => $patternType, "typeDash" => $patternTypeDash, "breadcrumb" => array("patternType" => $patternTypeClean), "state" => $patternState, "hidden" => $hidden, "noviewall" => $noviewall, "depth" => $depth, "ext" => $ext, "path" => $path, "pathName" => $patternPath, "pathDash" => $patternPathDash, "isDir" => $this->isDirProp, "isFile" => $this->isFileProp, "pseudo" => true, "original" => $patternBaseOrig, "pathOrig" => $patternPathOrig, "pathOrigDash" => $patternPathOrigDash); // add any subtype info if necessary if ($depth > 1) { $patternStoreData["subtype"] = $patternSubtype; $patternStoreData["subtypeDash"] = $patternSubtypeDash; $patternStoreData["breadcrumb"] = array("patternType" => $patternTypeClean, "patternSubtype" => $patternSubtypeClean); } $patternDataBase = array(); if (file_exists(Config::getOption("patternSourceDir") . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $patternBaseData)) { $data = file_get_contents(Config::getOption("patternSourceDir") . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $patternBaseData); if ($ext == "json") { $patternDataBase = json_decode($data, true); if ($jsonErrorMessage = JSON::hasError()) { JSON::lastErrorMsg($patternBaseJSON, $jsonErrorMessage, $data); } } else { try { $patternDataBase = YAML::parse($data); } catch (ParseException $e) { printf("unable to parse " . $pathNameClean . ": %s..\n", $e->getMessage()); } // single line of text won't throw a YAML error. returns as string if (gettype($patternDataBase) == "string") { $patternDataBase = array(); } } } // get the data for the pseudo-pattern $data = file_get_contents(Config::getOption("patternSourceDir") . DIRECTORY_SEPARATOR . $pathName); if ($ext == "json") { $patternData = json_decode($data, true); if ($jsonErrorMessage = JSON::hasError()) { JSON::lastErrorMsg($name, $jsonErrorMessage, $data); } } else { try { $patternData = YAML::parse($data); } catch (ParseException $e) { printf("unable to parse " . $pathNameClean . ": %s..\n", $e->getMessage()); } // single line of text won't throw a YAML error. returns as string if (gettype($patternData) == "string") { $patternData = array(); } } // make sure the pattern data is an array before merging the data $patternStoreData["data"] = is_array($patternData) ? array_replace_recursive($patternDataBase, $patternData) : $patternDataBase; // if the pattern data store already exists make sure it is merged and overwrites this data $patternStoreData = PatternData::checkOption($patternStoreKey) ? array_replace_recursive(PatternData::getOption($patternStoreKey), $patternStoreData) : $patternStoreData; PatternData::setOption($patternStoreKey, $patternStoreData); }
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(); /* rtl support start */ foreach (array_keys($store) as $patternStoreKey) { if ($store[$patternStoreKey]['isFile']) { $store[$patternStoreKey]['patternTextDirection'] = 'ltr'; $store[$patternStoreKey . '-rtl'] = $store[$patternStoreKey]; $store[$patternStoreKey . '-rtl']['name'] .= '-rtl'; $store[$patternStoreKey . '-rtl']['pathDash'] .= '-rtl'; $store[$patternStoreKey . '-rtl']['patternTextDirection'] = 'rtl'; $store[$patternStoreKey . '-rtl']['nameDash'] .= '-rtl'; $store[$patternStoreKey . '-rtl']['nameClean'] .= ' (RTL)'; $store[$patternStoreKey . '-rtl']['partial'] .= '-rtl'; } } foreach ($store as $patternStoreKey => $patternStoreData) { PatternData::setOption($patternStoreKey, $patternStoreData); } /* rtl support end */ // 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) { if ($patternStoreData["category"] == "pattern" && !$patternStoreData["hidden"]) { $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)))) : ""; /* add text-direction */ $data['patternTextDirection'] = $store[$patternStoreKey]['patternTextDirection']; /* add text-direction end */ 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); } } } }