/** * Gather data from annotations.js and *.md files found in source/_annotations * * @return {Array} populates Annotations::$store */ public static function gather() { // set-up default var $annotationsDir = Config::getOption("annotationsDir"); // set-up the dispatcher $dispatcherInstance = Dispatcher::getInstance(); // dispatch that the data gather has started $dispatcherInstance->dispatch("annotations.gatherStart"); // set-up the comments store self::$store["comments"] = array(); // create the annotations dir if it doesn't exist if (!is_dir($annotationsDir)) { mkdir($annotationsDir); } // find the markdown-based annotations $finder = new Finder(); $finder->files()->name("*.md")->in($annotationsDir); $finder->sortByName(); foreach ($finder as $name => $file) { $data = array(); $data[0] = array(); $text = file_get_contents($file->getPathname()); $matches = strpos($text, PHP_EOL . "~*~" . PHP_EOL) !== false ? explode(PHP_EOL . "~*~" . PHP_EOL, $text) : array($text); foreach ($matches as $match) { list($yaml, $markdown) = Documentation::parse($match); if (isset($yaml["el"]) || isset($yaml["selector"])) { $data[0]["el"] = isset($yaml["el"]) ? $yaml["el"] : $yaml["selector"]; } else { $data[0]["el"] = "#someimpossibleselector"; } $data[0]["title"] = isset($yaml["title"]) ? $yaml["title"] : ""; $data[0]["comment"] = $markdown; self::$store["comments"] = array_merge(self::$store["comments"], $data); } } // read in the old style annotations.js, modify the data and generate JSON array to merge $data = array(); $oldStyleAnnotationsPath = $annotationsDir . DIRECTORY_SEPARATOR . "annotations.js"; if (file_exists($oldStyleAnnotationsPath)) { $text = trim(file_get_contents($oldStyleAnnotationsPath)); $text = str_replace("var comments = ", "", $text); if ($text[strlen($text) - 1] == ";") { $text = rtrim($text, ";"); } $data = json_decode($text, true); if ($jsonErrorMessage = JSON::hasError()) { JSON::lastErrorMsg(Console::getHumanReadablePath($oldStyleAnnotationsPath), $jsonErrorMessage, $data); } } // merge in any data from the old file if the json decode was successful if (is_array($data) && isset($data["comments"])) { self::$store["comments"] = array_merge(self::$store["comments"], $data["comments"]); } $dispatcherInstance->dispatch("annotations.gatherEnd"); }
/** * Gather data from annotations.js and *.md files found in source/_annotations * * @return {Array} populates Annotations::$store */ public static function gather() { // set-up default var $sourceDir = Config::getOption("sourceDir"); // set-up the dispatcher $dispatcherInstance = Dispatcher::getInstance(); // dispatch that the data gather has started $dispatcherInstance->dispatch("annotations.gatherStart"); // set-up the comments store self::$store["comments"] = array(); // iterate over all of the files in the annotations dir if (!is_dir($sourceDir . "/_annotations")) { Console::writeWarning("<path>_annotations/</path><warning> doesn't exist so you won't have annotations..."); mkdir($sourceDir . "/_annotations"); } // find the markdown-based annotations $finder = new Finder(); $finder->files()->name("*.md")->in($sourceDir . "/_annotations"); $finder->sortByName(); foreach ($finder as $name => $file) { $data = array(); $data[0] = array(); $text = file_get_contents($file->getPathname()); $matches = strpos($text, PHP_EOL . "~*~" . PHP_EOL) !== false ? explode(PHP_EOL . "~*~" . PHP_EOL, $text) : array($text); foreach ($matches as $match) { list($yaml, $markdown) = Documentation::parse($match); if (isset($yaml["el"]) || isset($yaml["selector"])) { $data[0]["el"] = isset($yaml["el"]) ? $yaml["el"] : $yaml["selector"]; } else { $data[0]["el"] = "#someimpossibleselector"; } $data[0]["title"] = isset($yaml["title"]) ? $yaml["title"] : ""; $data[0]["comment"] = $markdown; self::$store["comments"] = array_merge(self::$store["comments"], $data); } } // read in the old style annotations.js, modify the data and generate JSON array to merge if (file_exists($sourceDir . "/_annotations/annotations.js")) { $text = file_get_contents($sourceDir . "/_annotations/annotations.js"); $text = str_replace("var comments = ", "", $text); $text = rtrim($text, ";"); $data = json_decode($text, true); if ($jsonErrorMessage = JSON::hasError()) { JSON::lastErrorMsg("_annotations/annotations.js", $jsonErrorMessage, $data); } } // merge in any data from the old file self::$store["comments"] = array_merge(self::$store["comments"], $data["comments"]); $dispatcherInstance->dispatch("annotations.gatherEnd"); }
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); } }