Пример #1
0
 public static function run()
 {
     // send out an event
     $event = new ConsoleEvent($options = array());
     Dispatcher::getInstance()->dispatch("console.loadCommandsStart", $event);
     // loadCommands
     self::loadCommands();
     // send out an event
     Dispatcher::getInstance()->dispatch("console.loadCommandsEnd", $event);
     // get what was passed on the command line
     self::$options = getopt(self::$optionsShort, self::$optionsLong);
     // test and run the given command
     $commandFound = false;
     $commandSent = self::getCommand();
     foreach (self::$commandInstances as $command) {
         if ($command->test($commandSent)) {
             $command->run();
             $commandFound = true;
         }
     }
     // no command was found so just draw the help by default
     if (!$commandFound) {
         self::writeHelp();
     }
 }
 /**
  * Set-up a default var
  */
 public function __construct()
 {
     // dispatch event and build the appropriate processes
     $event = new ProcessSpawnerEvent();
     $dispatcherInstance = Dispatcher::getInstance();
     $dispatcherInstance->dispatch('processSpawner.getPluginProcesses', $event);
     $this->pluginProcesses = $event->getPluginProcesses();
 }
 public function testGenerate()
 {
     Console::init();
     Config::init(__DIR__ . "/../../../../../..");
     Dispatcher::init();
     $generator = new Generator();
     $generator->generate(['foo' => 'baz']);
     echo '';
 }
Пример #4
0
 /**
  * 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");
 }
Пример #5
0
 /**
  * Common init sequence
  */
 protected static function init()
 {
     // start the timer
     Timer::start();
     // initialize the console to print out any issues
     Console::init();
     // initialize the config for the pluginDir
     $baseDir = __DIR__ . "/../../../../../";
     Config::init($baseDir, false);
     Dispatcher::init();
 }
 /**
  * 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");
 }
 /**
  * Common init sequence
  */
 protected static function init()
 {
     // start the timer
     Timer::start();
     // initialize the console to print out any issues
     Console::init();
     // initialize the config for the pluginDir
     $baseDir = __DIR__ . "/../../../../../";
     Config::init($baseDir, false);
     // make sure the source dir is set-up
     $sourceDir = Config::getOption("sourceDir");
     if (!is_dir($sourceDir)) {
         FileUtil::makeDir($sourceDir);
     }
     // make sure the public dir is set-up
     $publicDir = Config::getOption("publicDir");
     if (!is_dir($publicDir)) {
         FileUtil::makeDir($publicDir);
     }
     Dispatcher::init();
 }
Пример #8
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
             if (!$ignored && $object->isFile() && !file_exists($publicDir . "/" . $fileName)) {
                 FileUtil::moveStaticFile($fileName);
             }
         }
     }
     // note the end of the operation
     $dispatcherInstance->dispatch("generator.moveStaticEnd");
 }
Пример #9
0
 /**
  * Gather all of the information related to the patterns
  */
 public static function gather($options = array())
 {
     // set default vars
     $exportClean = isset($options["exportClean"]) ? $options["exportClean"] : false;
     $exportFiles = isset($options["exportClean"]) ? $options["exportFiles"] : false;
     $dispatcherInstance = Dispatcher::getInstance();
     // cleaning the var for use below, i know this is stupid
     $options = array();
     // dispatch that the data gather has started
     $event = new PatternDataEvent($options);
     $dispatcherInstance->dispatch("patternData.gatherStart", $event);
     // load up the rules for parsing patterns and the directories
     self::loadRules($options);
     // dispatch that the rules are loaded
     $event = new PatternDataEvent($options);
     $dispatcherInstance->dispatch("patternData.rulesLoaded", $event);
     // iterate over the patterns & related data and regenerate the entire site if they've changed
     // seems a little silly to use symfony finder here. not really giving me any power
     $patternObjects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(Config::getOption("patternSourceDir")), \RecursiveIteratorIterator::SELF_FIRST);
     $patternObjects->setFlags(\FilesystemIterator::SKIP_DOTS);
     // sort the returned objects
     $patternObjects = iterator_to_array($patternObjects);
     ksort($patternObjects);
     $patternSourceDir = Config::getOption("patternSourceDir");
     foreach ($patternObjects as $name => $object) {
         $ext = $object->getExtension();
         $isDir = $object->isDir();
         $isFile = $object->isFile();
         $path = str_replace($patternSourceDir . "/", "", $object->getPath());
         $pathName = str_replace($patternSourceDir . "/", "", $object->getPathname());
         $name = $object->getFilename();
         $depth = substr_count($pathName, DIRECTORY_SEPARATOR);
         // iterate over the rules and see if the current file matches one, if so run the rule
         foreach (self::$rules as $rule) {
             if ($rule->test($depth, $ext, $isDir, $isFile, $name)) {
                 $rule->run($depth, $ext, $path, $pathName, $name);
             }
         }
     }
     // dispatch that the data is loaded
     $event = new PatternDataEvent($options);
     $dispatcherInstance->dispatch("patternData.dataLoaded", $event);
     // make sure all of the appropriate pattern data is pumped into $this->d for rendering patterns
     $dataLinkExporter = new DataLinkExporter();
     $dataLinkExporter->run();
     // make sure all of the appropriate pattern data is pumped into $this->d for rendering patterns
     $dataMergeExporter = new DataMergeExporter();
     $dataMergeExporter->run();
     // dispatch that the raw pattern helper is about to start
     $event = new PatternDataEvent($options);
     $dispatcherInstance->dispatch("patternData.rawPatternHelperStart", $event);
     // add the lineage info to PatternData::$store
     $rawPatternHelper = new RawPatternHelper();
     $rawPatternHelper->run();
     // dispatch that the raw pattern helper is ended
     $event = new PatternDataEvent($options);
     $dispatcherInstance->dispatch("patternData.rawPatternHelperEnd", $event);
     // dispatch that the lineage helper is about to start
     $event = new PatternDataEvent($options);
     $dispatcherInstance->dispatch("patternData.lineageHelperStart", $event);
     // add the lineage info to PatternData::$store
     $lineageHelper = new LineageHelper();
     $lineageHelper->run();
     // dispatch that the lineage helper is ended
     $event = new PatternDataEvent($options);
     $dispatcherInstance->dispatch("patternData.lineageHelperEnd", $event);
     // dispatch that the pattern state helper is about to start
     $event = new PatternDataEvent($options);
     $dispatcherInstance->dispatch("patternData.patternStateHelperStart", $event);
     // using the lineage info update the pattern states on PatternData::$store
     $patternStateHelper = new PatternStateHelper();
     $patternStateHelper->run();
     // dispatch that the pattern state helper is ended
     $event = new PatternDataEvent($options);
     $dispatcherInstance->dispatch("patternData.patternStateHelperEnd", $event);
     // set-up code pattern paths
     $ppdExporter = new PatternPathSrcExporter();
     $patternPathSrc = $ppdExporter->run();
     $options = array();
     $options["patternPaths"] = $patternPathSrc;
     // dispatch that the code helper is about to start
     $event = new PatternDataEvent($options);
     $dispatcherInstance->dispatch("patternData.codeHelperStart", $event);
     // render out all of the patterns and store the generated info in PatternData::$store
     $options["exportFiles"] = $exportFiles;
     $options["exportClean"] = $exportClean;
     $patternCodeHelper = new PatternCodeHelper($options);
     $patternCodeHelper->run();
     // dispatch that the pattern code helper is ended
     $event = new PatternDataEvent($options);
     $dispatcherInstance->dispatch("patternData.patternCodeHelperEnd", $event);
     // dispatch that the gather has ended
     $event = new PatternDataEvent($options);
     $dispatcherInstance->dispatch("patternData.gatherEnd", $event);
 }
Пример #10
0
 /**
  * Generate the listItems array
  * @param  {String}       the filename for the pattern to be parsed
  * @param  {String}       the extension so that a flag switch can be used to parse data
  *
  * @return {Array}        the final set of list items
  */
 public static function getListItems($filepath, $ext = "json")
 {
     // set-up the dispatcher
     $dispatcherInstance = Dispatcher::getInstance();
     // dispatch that the data gather has started
     $dispatcherInstance->dispatch("data.getListItemsStart");
     // default vars
     $sourceDir = Config::getOption("sourceDir");
     $listItems = array();
     $listItemsData = array();
     // add list item data, makes 'listItems' a reserved word
     if (file_exists($sourceDir . "/" . $filepath)) {
         $file = file_get_contents($sourceDir . "/" . $filepath);
         if ($ext == "json") {
             $listItemsData = json_decode($file, true);
             if ($jsonErrorMessage = JSON::hasError()) {
                 JSON::lastErrorMsg($filepath, $jsonErrorMessage, $listItems);
             }
         } else {
             try {
                 $listItemsData = 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($listItemsData) == "string") {
                 $listItemsData = array();
             }
         }
         $numbers = array("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve");
         $i = 0;
         $k = 1;
         $c = count($listItemsData) + 1;
         while ($k < $c) {
             shuffle($listItemsData);
             $itemsArray = array();
             while ($i < $k) {
                 $itemsArray[] = $listItemsData[$i];
                 $i++;
             }
             $listItems[$numbers[$k - 1]] = $itemsArray;
             $i = 0;
             $k++;
         }
     }
     $dispatcherInstance->dispatch("data.getListItemsEnd");
     return $listItems;
 }
Пример #11
0
 /**
  * Watch the source/ directory for any changes to existing files. Will run forever if given the chance.
  * @param  {Boolean}       decide if the reload server should be turned on
  * @param  {Boolean}       decide if static files like CSS and JS should be moved
  */
 public function watch($options = array())
 {
     // double-checks options was properly set
     if (empty($options)) {
         Console::writeError("need to pass options to generate...");
     }
     // set default attributes
     $moveStatic = isset($options["moveStatic"]) ? $options["moveStatic"] : true;
     $noCacheBuster = isset($options["noCacheBuster"]) ? $options["noCacheBuster"] : false;
     // make sure a copy of the given options are saved for using when running generate
     $this->options = $options;
     // set-up the Dispatcher
     $dispatcherInstance = Dispatcher::getInstance();
     $dispatcherInstance->dispatch("watcher.start");
     if ($noCacheBuster) {
         Config::setOption("cacheBuster", 0);
     }
     $c = false;
     // track that one loop through the pattern file listing has completed
     $o = new \stdClass();
     // create an object to hold the properties
     $cp = new \stdClass();
     // create an object to hold a clone of $o
     $o->patterns = new \stdClass();
     Console::writeLine("watching your site for changes...");
     // default vars
     $publicDir = Config::getOption("publicDir");
     $sourceDir = Config::getOption("sourceDir");
     $patternSourceDir = Config::getOption("patternSourceDir");
     $ignoreExts = Config::getOption("ie");
     $ignoreDirs = Config::getOption("id");
     $patternExt = Config::getOption("patternExtension");
     // build the file extensions based on the rules
     $fileExtensions = array();
     $patternRules = PatternData::getRules();
     foreach ($patternRules as $patternRule) {
         $extensions = $patternRule->getProp("extProp");
         if (strpos($extensions, "&&") !== false) {
             $extensions = explode("&&", $extensions);
         } else {
             if (strpos($extensions, "||") !== false) {
                 $extensions = explode("||", $extensions);
             } else {
                 $extensions = array($extensions);
             }
         }
         foreach ($extensions as $extension) {
             if (!in_array($extension, $fileExtensions)) {
                 $fileExtensions[] = $extension;
             }
         }
     }
     // run forever
     while (true) {
         // clone the patterns so they can be checked in case something gets deleted
         $cp = clone $o->patterns;
         // iterate over the patterns & related data and regenerate the entire site if they've changed
         $patternObjects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($patternSourceDir), \RecursiveIteratorIterator::SELF_FIRST);
         // make sure dots are skipped
         $patternObjects->setFlags(\FilesystemIterator::SKIP_DOTS);
         foreach ($patternObjects 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($patternSourceDir . DIRECTORY_SEPARATOR, "", $name);
             $fileNameClean = str_replace(DIRECTORY_SEPARATOR . "_", DIRECTORY_SEPARATOR, $fileName);
             if ($object->isFile() && in_array($object->getExtension(), $fileExtensions)) {
                 // make sure this isn't a hidden pattern
                 $patternParts = explode(DIRECTORY_SEPARATOR, $fileName);
                 $pattern = isset($patternParts[2]) ? $patternParts[2] : $patternParts[1];
                 // make sure the pattern still exists in source just in case it's been deleted during the iteration
                 if (file_exists($name)) {
                     $mt = $object->getMTime();
                     if (isset($o->patterns->{$fileName}) && $o->patterns->{$fileName} != $mt) {
                         $o->patterns->{$fileName} = $mt;
                         $this->updateSite($fileName, "changed");
                     } else {
                         if (!isset($o->patterns->{$fileName}) && $c) {
                             $o->patterns->{$fileName} = $mt;
                             $this->updateSite($fileName, "added");
                             if ($object->getExtension() == $patternExt) {
                                 $patternSrcPath = str_replace("." . $patternExt, "", $fileName);
                                 $patternDestPath = str_replace("/", "-", $patternSrcPath);
                                 $render = $pattern[0] != "_" ? true : false;
                                 $this->patternPaths[$patternParts[0]][$pattern] = array("patternSrcPath" => $patternSrcPath, "patternDestPath" => $patternDestPath, "render" => $render);
                             }
                         } else {
                             if (!isset($o->patterns->{$fileName})) {
                                 $o->patterns->{$fileName} = $mt;
                             }
                         }
                     }
                     if ($c && isset($o->patterns->{$fileName})) {
                         unset($cp->{$fileName});
                     }
                 } else {
                     // the file was removed during the iteration so remove references to the item
                     unset($o->patterns->{$fileName});
                     unset($cp->{$fileName});
                     unset($this->patternPaths[$patternParts[0]][$pattern]);
                     $this->updateSite($fileName, "removed");
                 }
             }
         }
         // make sure old entries are deleted
         // will throw "pattern not found" errors if an entire directory is removed at once but that shouldn't be a big deal
         if ($c) {
             foreach ($cp as $fileName => $mt) {
                 unset($o->patterns->{$fileName});
                 $patternParts = explode(DIRECTORY_SEPARATOR, $fileName);
                 $pattern = isset($patternParts[2]) ? $patternParts[2] : $patternParts[1];
                 unset($this->patternPaths[$patternParts[0]][$pattern]);
                 $this->updateSite($fileName, "removed");
             }
         }
         // iterate over annotations, data, meta and any other _ dirs
         $watchDirs = glob($sourceDir . DIRECTORY_SEPARATOR . "_*", GLOB_ONLYDIR);
         foreach ($watchDirs as $watchDir) {
             if ($watchDir != $patternSourceDir) {
                 // iterate over the data files and regenerate the entire site if they've changed
                 $objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($watchDir), \RecursiveIteratorIterator::SELF_FIRST);
                 // make sure dots are skipped
                 $objects->setFlags(\FilesystemIterator::SKIP_DOTS);
                 foreach ($objects as $name => $object) {
                     $fileName = str_replace($sourceDir . DIRECTORY_SEPARATOR, "", $name);
                     $mt = $object->getMTime();
                     if (!isset($o->{$fileName})) {
                         $o->{$fileName} = $mt;
                         if ($c) {
                             $this->updateSite($fileName, "added");
                         }
                     } else {
                         if ($o->{$fileName} != $mt) {
                             $o->{$fileName} = $mt;
                             if ($c) {
                                 $this->updateSite($fileName, "changed");
                             }
                         }
                     }
                 }
             }
         }
         // iterate over all of the other files in the source directory and move them if their modified time has changed
         if ($moveStatic) {
             $objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($sourceDir . DIRECTORY_SEPARATOR), \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(), $ignoreExts) && !in_array($object->getFilename(), $ignoreDirs)) {
                     // catch directories that have the ignored dir in their path
                     $ignoreDir = FileUtil::ignoreDir($fileName);
                     // check to see if it's a new directory
                     if (!$ignoreDir && $object->isDir() && !isset($o->{$fileName}) && !is_dir($publicDir . "/" . $fileName)) {
                         mkdir($publicDir . "/" . $fileName);
                         $o->{$fileName} = "dir created";
                         // placeholder
                         Console::writeLine($fileName . "/ directory was created...");
                     }
                     // check to see if it's a new file or a file that has changed
                     if (file_exists($name)) {
                         $mt = $object->getMTime();
                         if (!$ignoreDir && $object->isFile() && !isset($o->{$fileName}) && !file_exists($publicDir . "/" . $fileName)) {
                             $o->{$fileName} = $mt;
                             FileUtil::moveStaticFile($fileName, "added");
                             if ($object->getExtension() == "css") {
                                 $this->updateSite($fileName, "changed", 0);
                                 // make sure the site is updated for MQ reasons
                             }
                         } else {
                             if (!$ignoreDir && $object->isFile() && isset($o->{$fileName}) && $o->{$fileName} != $mt) {
                                 $o->{$fileName} = $mt;
                                 FileUtil::moveStaticFile($fileName, "changed");
                                 if ($object->getExtension() == "css") {
                                     $this->updateSite($fileName, "changed", 0);
                                     // make sure the site is updated for MQ reasons
                                 }
                             } else {
                                 if (!isset($o->fileName)) {
                                     $o->{$fileName} = $mt;
                                 }
                             }
                         }
                     } else {
                         unset($o->{$fileName});
                     }
                 }
             }
         }
         $c = true;
         // taking out the garbage. basically killing mustache after each run.
         if (gc_enabled()) {
             gc_collect_cycles();
         }
         // pause for .05 seconds to give the CPU a rest
         usleep(50000);
     }
 }
Пример #12
0
 /**
  * Delete patterns and user-created directories and files in public/
  */
 public static function cleanPublic()
 {
     // set-up the dispatcher
     $dispatcherInstance = Dispatcher::getInstance();
     // dispatch that the data gather has started
     $dispatcherInstance->dispatch("fileUtil.cleanPublicStart");
     // default var
     $patternPublicDir = Config::getOption("patternPublicDir");
     // make sure patterns exists before trying to clean it
     if (is_dir($patternPublicDir)) {
         // symfony finder doesn't support child first and I don't want to do array crap
         $objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($patternPublicDir), \RecursiveIteratorIterator::CHILD_FIRST);
         // make sure dots are skipped
         $objects->setFlags(\FilesystemIterator::SKIP_DOTS);
         // for each file figure out what to do with it
         foreach ($objects as $name => $object) {
             if ($object->isDir()) {
                 // if this is a directory remove it
                 rmdir($name);
             } else {
                 if ($object->isFile() && $object->getFilename() != "README") {
                     // if this is a file remove it
                     unlink($name);
                 }
             }
         }
     }
     // scan source/ & public/ to figure out what directories might need to be cleaned up
     $publicDir = Config::getOption("publicDir");
     $sourceDir = Config::getOption("sourceDir");
     $publicDirs = glob($publicDir . DIRECTORY_SEPARATOR . "*", GLOB_ONLYDIR);
     $sourceDirs = glob($sourceDir . DIRECTORY_SEPARATOR . "*", GLOB_ONLYDIR);
     // make sure some directories aren't deleted
     $ignoreDirs = array("styleguide", "patternlab-components");
     foreach ($ignoreDirs as $ignoreDir) {
         $key = array_search($publicDir . DIRECTORY_SEPARATOR . $ignoreDir, $publicDirs);
         if ($key !== false) {
             unset($publicDirs[$key]);
         }
     }
     // compare source dirs against public. remove those dirs w/ an underscore in source/ from the public/ list
     foreach ($sourceDirs as $dir) {
         $cleanDir = str_replace($sourceDir . DIRECTORY_SEPARATOR, "", $dir);
         if ($cleanDir[0] == "_") {
             $key = array_search($publicDir . DIRECTORY_SEPARATOR . str_replace("_", "", $cleanDir), $publicDirs);
             if ($key !== false) {
                 unset($publicDirs[$key]);
             }
         }
     }
     // for the remaining dirs in public delete them and their files
     foreach ($publicDirs as $dir) {
         // symfony finder doesn't support child first and I don't want to do array crap
         $objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir), \RecursiveIteratorIterator::CHILD_FIRST);
         // make sure dots are skipped
         $objects->setFlags(\FilesystemIterator::SKIP_DOTS);
         foreach ($objects as $name => $object) {
             if ($object->isDir()) {
                 rmdir($name);
             } else {
                 if ($object->isFile()) {
                     unlink($name);
                 }
             }
         }
         rmdir($dir);
     }
     $dispatcherInstance->dispatch("fileUtil.cleanPublicEnd");
 }
Пример #13
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") {
             // 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"])) {
                 // 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");
 }