Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * Execute preprocessor
  *
  * This will take all CSS files from the source dir, minify each one and 
  * then combine them into one file.
  *
  * @param array $options Options for execution
  * @return void
  */
 public function execute($options = array())
 {
     $cssFiles = FileOps::rglob("*.css", 0, $this->getSourceDir());
     if (empty($cssFiles)) {
         return false;
     }
     FileOps::ensurePathExists($this->getDestinationDir());
     // Just get the basename of the main style sheet, this will be written
     // to the destination dir
     $mainStylesheet = basename($options['main_stylesheet']);
     $mainStylesheet = $this->getDestinationDir() . DIRECTORY_SEPARATOR . $mainStylesheet;
     $buffer = array();
     foreach ($cssFiles as $file) {
         $content = file_get_contents($file);
         $newContent = \Minify_CSS_Compressor::process($content);
         $buffer[] = $newContent;
     }
     if ($buffer) {
         file_put_contents($mainStylesheet, implode("\n", $buffer));
     }
 }
Example #3
0
 /**
  * Get a list of files from source directory
  *
  * @param string $pattern File pattern to find
  * @return array
  */
 public function getSourceFilelist($pattern = "*.css")
 {
     $sourceDir = $this->_config['source'];
     $this->logger->notice("Reading source dir '{$sourceDir}' for '{$pattern}'...");
     $files = FileOps::rglob($pattern, 0, $sourceDir);
     sort($files);
     $this->logger->info(sprintf("Found %s files in source dir", count($files)));
     return $files;
 }
Example #4
0
 /**
  * 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;
 }