create() public method

return \Phrozn\Site\View\Factory
public create ( )
Beispiel #1
0
 protected function buildQueue()
 {
     $projectDir = $this->getProjectDir();
     $outputDir = $this->getOutputDir();
     $item = new \SplFileObject($this->getSingleFile());
     if ($item->isFile()) {
         try {
             $factory = new View\Factory($item->getRealPath());
             $view = $factory->create();
             $view->setSiteConfig($this->getSiteConfig())->setOutputDir($outputDir);
             $this->addView($view);
         } catch (\Exception $e) {
             $this->getOutputter()->stderr(str_replace($projectDir, '', $item->getRealPath()) . ': ' . $e->getMessage());
         }
     }
     return $this;
 }
Beispiel #2
0
 /**
  * Create list of views to be created
  *
  * @return \Phrozn\Site
  */
 protected function buildQueue()
 {
     // guess the base path with Phrozn project
     $projectDir = $this->getProjectDir();
     $outputDir = $this->getOutputDir();
     $config = $this->getSiteConfig();
     // configure skip files options
     $skipToken = '-!SKIP!-';
     $folders = array('entries', 'styles', 'scripts');
     foreach ($folders as $folder) {
         $dir = new \RecursiveDirectoryIterator($projectDir . '/' . $folder);
         $it = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::SELF_FIRST);
         foreach ($it as $item) {
             $baseName = $item->getBaseName();
             if (isset($config['skip'])) {
                 $baseName = preg_replace($config['skip'], array_fill(0, count($config['skip']), $skipToken), $baseName);
                 if (strpos($baseName, $skipToken) !== false) {
                     continue;
                 }
             }
             if ($item->isFile()) {
                 try {
                     $factory = new View\Factory($item->getRealPath());
                     $factory->setInputRootDir($projectDir);
                     $view = $factory->create();
                     $view->setSiteConfig($this->getSiteConfig())->setOutputDir($outputDir);
                     $this->views[] = $view;
                 } catch (\Exception $e) {
                     $this->getOutputter()->stderr(str_replace($projectDir, '', $item->getRealPath()) . ': ' . $e->getMessage());
                 }
             }
         }
     }
     return $this;
 }
Beispiel #3
0
 /**
  * Two step view is used. View to wrap is provided with content variable.
  *
  * @param string $content View text to wrap into layout
  * @param array $vars List of variables passed to processors
  *
  * @return string
  */
 protected function applyLayout($content, $vars)
 {
     $layoutName = $this->getParam('page.layout', ViewFactory::DEFAULT_LAYOUT_SCRIPT);
     $inputFile = $this->getInputFile();
     $pos = strpos($inputFile, '/entries');
     // make sure that input path is normalized to root entries directory
     if (false !== $pos) {
         $inputFile = substr($inputFile, 0, $pos + 8) . '/entry';
     }
     $layoutPath = realpath(dirname($inputFile) . '/../layouts/' . $layoutName);
     $factory = new ViewFactory($layoutPath);
     $layout = $factory->create();
     // essentially layout is Site\View as well
     $layout->hasLayout(false);
     // no nested layouts
     return $layout->render(array('content' => $content, 'entry' => $vars['page']));
 }