stream() public method

Create a stream wrapper to allow the possibility to add $scope variables.
public stream ( $input ) : string
return string
Example #1
0
 private function cacheSystem($keepBaseName)
 {
     $cacheDirectory = sys_get_temp_dir() . '/pug-test';
     $this->emptyDirectory($cacheDirectory);
     if (!is_dir($cacheDirectory)) {
         mkdir($cacheDirectory, 0777, true);
     }
     $file = tempnam(sys_get_temp_dir(), 'jade-test-');
     $jade = new Jade(array('singleQuote' => false, 'keepBaseName' => $keepBaseName, 'cache' => $cacheDirectory));
     copy(__DIR__ . '/../templates/attrs.jade', $file);
     $name = basename($file);
     $stream = $jade->cache($file);
     $phpFiles = array_values(array_map(function ($file) use($cacheDirectory) {
         return $cacheDirectory . DIRECTORY_SEPARATOR . $file;
     }, array_filter(scandir($cacheDirectory), function ($file) {
         return substr($file, -4) === '.php';
     })));
     $start = 'jade.stream://data;';
     $this->assertTrue(strpos($stream, $start) === 0, 'Fresh content should be a stream.');
     $this->assertSame(1, count($phpFiles), 'The cached file should now exist.');
     $cachedFile = realpath($phpFiles[0]);
     $this->assertFalse(!$cachedFile, 'The cached file should now exist.');
     $this->assertSame($stream, $jade->stream($jade->compile($file)), 'Should return the stream of attrs.jade.');
     $this->assertStringEqualsFile($cachedFile, substr($stream, strlen($start)), 'The cached file should contains the same contents.');
     touch($file, time() - 3600);
     $path = $jade->cache($file);
     $this->assertSame(realpath($path), $cachedFile, 'The cached file should be used instead if untouched.');
     copy(__DIR__ . '/../templates/mixins.jade', $file);
     touch($file, time() + 3600);
     $stream = $jade->cache($file);
     $this->assertSame($stream, $jade->stream($jade->compile(__DIR__ . '/../templates/mixins.jade')), 'The cached file should be the stream of mixins.jade.');
     unlink($file);
 }