compile() публичный Метод

Compile PHP code from a Pug input or a Pug file.
public compile ( string $input, string $filename = null ) : string
$input string input file (or input content if filenname is specified or no file found)
$filename string filename for the input code
Результат string
Пример #1
0
 protected function getPhp($template)
 {
     $jade = new Jade(array('singleQuote' => false, 'prettyprint' => false, 'restrictedScope' => true));
     return trim($jade->compile($template));
 }
Пример #2
0
function compile_php($file)
{
    $jade = new Jade(array('singleQuote' => false, 'prettyprint' => true));
    return $jade->compile(file_get_contents(TEMPLATES_DIRECTORY . DIRECTORY_SEPARATOR . $file . '.jade'));
}
Пример #3
0
 /**
  * Compile the given Jade template contents.
  *
  * @param  string $value
  * @return string
  */
 public function compileString($value)
 {
     return $this->jade->compile($value);
 }
Пример #4
0
    /**
     * phpSingleLine setting test
     */
    public function testPhpSingleLine()
    {
        $template = '
- $foo = "bar"
- $bar = 42
p(class=$foo)=$bar
';
        $jade = new Jade(array('phpSingleLine' => true));
        $compile = $jade->compile($template);
        $actual = substr_count($compile, "\n");
        $expected = substr_count($compile, '<?php') * 2 + 1;
        $this->assertSame($expected, $actual, 'PHP single line enabled');
        $this->assertGreaterThan(5, $actual, 'PHP single line enabled');
        $jade = new Jade(array('phpSingleLine' => false));
        $actual = substr_count(trim($jade->compile($template)), "\n");
        $this->assertLessThan(2, $actual, 'PHP single line disabled');
    }
Пример #5
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);
 }