/** * Reload the page. * * This is a convenient way to simply reload the page in your browser * without having to run 'holograph build' because this class does that for * you. * * E.g. in a browser, go to * http://localhost/styleguide/docs/index.php/index.html and it will * serve up the index.html file after regenerating the styleguide build. * * Current downside is you can't provide an alternate config filename; it * always assumes holograph.yml * * @param mixed $requestUri * @return void */ public static function reload($requestUri) { $configFile = 'holograph.yml'; $config = Yaml::parse($configFile); $logger = new Logger\Memory(); $builder = new Builder($config, $logger); $builder->execute(); //$destination = $builder->getConfig('destination'); $destination = '.'; $fileio = new FileOps(); $contents = $fileio->readFile($destination . '/' . self::transformRequestUri($requestUri)); return $contents; }
/** * testExecuteSimple * * @return void */ public function testExecuteSimple() { mkdir("test-source"); file_put_contents("test-source/test.css", ".main { color: red}"); file_put_contents("test-source/test.md", "# Hi there"); $config = array('source' => 'test-source', 'destination' => 'test-destination', 'build' => 'test-build/css', 'main_stylesheet' => 'test-build/css/screen.css'); $builder = new Builder($config, $this->logger); $result = $builder->execute(); $this->assertTrue(file_exists("test-destination/static/css/doc.css")); $this->assertTrue(file_exists("test-build/css/screen.css")); $this->assertTrue(file_exists("test-destination/test.html")); $this->assertEquals(0, $result); }
/** * Execute * * @return void */ public function execute() { if ($this->_args->verbose) { $this->logger->setVerbose(true); } $action = $this->_args->action ? $this->_args->action : "help"; if ($this->_args->help || $this->_args->h || $action == 'help') { $this->displayHelp(); return self::STATUS_SUCCESS; } if ($this->_args->version || $action == 'version') { print Version::renderVersion(); return self::STATUS_SUCCESS; } $this->logger->info("Current path: " . getcwd()); $configFileOverride = false; if ($this->_args->conf) { $this->_configFilename = $this->_args->conf; // If a specified file fails, we want to bail since there are // destructive commands run (rm -rf) on paths that the user may not // have intended with a custom config file $configFileOverride = true; } switch ($action) { case 'init': $this->logger->notice("Initializing environment for Holograph"); $this->writeConfig(); break; case 'config': $this->showConfig(); break; case 'build': $config = $this->readConfigFile($this->_configFilename, $configFileOverride); if ($this->_args->compat) { $config['compatMode'] = $this->_args->compat; } $builder = new Builder($config, $this->logger); try { $builder->execute(); } catch (\Exception $exception) { $this->_halt($exception->getMessage()); } break; case 'live': $config = $this->readConfigFile($this->_configFilename, $configFileOverride); $autoloadPath = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR; if (!file_exists($autoloadPath . 'vendor/autoload.php')) { $autoloadPath = dirname(dirname(dirname(dirname($autoloadPath)))); } $indexContents = "<?php\n"; $indexContents .= sprintf("/* Holograph Live\nGenerated %s\n*/\n", date("Y-m-d H:i:s")); $indexContents .= sprintf("require_once '%s/vendor/autoload.php';\n", $autoloadPath); $indexContents .= "\$contents = \\Holograph\\Live::reload(\$_SERVER['REQUEST_URI']);\n"; $indexContents .= "print \$contents;\n"; $fileio = new FileOps(); $fileio->writeFile($config['destination'] . DIRECTORY_SEPARATOR . "index.php", $indexContents); $serverCmd = 'php -S localhost:8000 -t ' . $config['destination']; $this->logger->info($serverCmd); passthru($serverCmd); break; default: $this->logger->warning("Unrecognized action '{$action}'"); $this->_status = self::STATUS_ERROR; break; } return $this->_status; }