protected function cacheTemplates(Jade $pug)
 {
     $success = 0;
     $errors = 0;
     $directories = array();
     foreach ($pug->getOption('assetDirectory') as $assetDirectory) {
         $viewDirectory = $assetDirectory . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'views';
         if (!is_dir($viewDirectory)) {
             continue;
         }
         $directories[] = $viewDirectory;
         $data = $pug->cacheDirectory($viewDirectory);
         $success += $data[0];
         $errors += $data[1];
     }
     return array($directories, $success, $errors);
 }
Example #2
0
 /**
  * Test cacheDirectory method
  */
 public function testCacheDirectory()
 {
     $cacheDirectory = sys_get_temp_dir() . '/pug-test';
     $this->emptyDirectory($cacheDirectory);
     if (!is_dir($cacheDirectory)) {
         mkdir($cacheDirectory, 0777, true);
     }
     $templatesDirectory = __DIR__ . '/../templates';
     $jade = new Jade(array('basedir' => $templatesDirectory, 'cache' => $cacheDirectory));
     list($success, $errors) = $jade->cacheDirectory($templatesDirectory);
     $filesCount = count(array_filter(scandir($cacheDirectory), function ($file) {
         return $file !== '.' && $file !== '..';
     }));
     $expectedCount = count(array_filter(array_merge(scandir($templatesDirectory), scandir($templatesDirectory . '/auxiliary'), scandir($templatesDirectory . '/auxiliary/subdirectory/subsubdirectory')), function ($file) {
         return in_array(pathinfo($file, PATHINFO_EXTENSION), array('pug', 'jade'));
     }));
     $this->emptyDirectory($cacheDirectory);
     $templatesDirectory = __DIR__ . '/../templates/subdirectory/subsubdirectory';
     $jade = new Jade(array('basedir' => $templatesDirectory, 'cache' => $cacheDirectory));
     $this->emptyDirectory($cacheDirectory);
     rmdir($cacheDirectory);
     $this->assertSame($expectedCount, $success + $errors, 'Each .jade file in the directory to cache should generate a success or an error.');
     $this->assertSame($success, $filesCount, 'Each file successfully cached should be in the cache directory.');
 }