render() public method

Compile HTML code from a Pug input or a Pug file.
public render ( $input, $filename = null, array $vars = [] ) : string
$vars array
return string
 public function testJsExpression()
 {
     $jade = new Jade(array('singleQuote' => false, 'expressionLanguage' => 'js'));
     $actual = trim($jade->render("- a = 2\n- b = 4\n- c = b * a\np=a * b\np=c"));
     $this->assertSame('<p>8</p><p>8</p>', $actual);
     $actual = trim($jade->render("- a = 2\n- b = 4\np=a + b"));
     $this->assertSame('<p>6</p>', $actual);
     $actual = trim($jade->render("- a = '2'\n- b = 4\np=a + b"));
     $this->assertSame('<p>24</p>', $actual);
     $compiler = new ExpressionCompilerTester(array('expressionLanguage' => 'js'));
     $actual = trim($compiler->callPhpizeExpression('addDollarIfNeeded', 'array(1)'));
     $this->assertSame('array(1)', $actual);
     $actual = trim($compiler->callPhpizeExpression('addDollarIfNeeded', 'a'));
     $this->assertSame('$a', $actual);
 }
示例#2
0
 /**
  * @param string $test_method
  * @param array $scope
  * @return string
  */
 protected function render($test_method, $scope = array())
 {
     $content = $this->jade->render($this->jadeFile($test_method), $scope, array('includes' => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR));
     $results_dir = dirname(__FILE__) . '/results/';
     if (!file_exists($results_dir)) {
         mkdir($results_dir);
     }
     file_put_contents($results_dir . $test_method . ".php", $content);
     ob_start();
     clearstatcache();
     extract($scope);
     eval("?>" . $content);
     $rendered = ob_get_contents();
     ob_end_clean();
     return $rendered;
 }
示例#3
0
 public function testPipeless()
 {
     $jade = new Jade(array('prettyprint' => false));
     $actual = $jade->render("div\n  span.\n            Some indented text\n            on many lines\n            but the words\n            must not\n            be\n            sticked.\n        ");
     $expected = '<div><span>Some indented text on many lines but the words must not be sticked.</span></div>';
     $actual = preg_replace('/\\s+/', ' ', $actual);
     $this->assertSame($expected, $actual);
 }
示例#4
0
 public function testResetSharedVariables()
 {
     $jade = new Jade();
     $jade->share('answear', 42);
     $jade->share(array('foo' => 'Hello', 'bar' => 'world'));
     $jade->resetSharedVariables();
     $error = null;
     try {
         $jade->render("p\n  =foo\n=' '\n=bar\n  | !");
     } catch (\Exception $e) {
         $error = $e->getMessage();
     }
     $this->assertSame('Undefined variable: foo', $error);
 }
示例#5
0
 protected function getHtmlFromTemplate($template, array $vars = array())
 {
     $jade = new Jade(array('singleQuote' => false, 'prettyprint' => false, 'restrictedScope' => true));
     return trim($jade->render($this->getPerformanceTemplate($template), $vars));
 }
示例#6
0
function get_php_code($file, $vars = array())
{
    $jade = new Jade(array('singleQuote' => false, 'prettyprint' => true));
    return $jade->render($file, $vars);
}
示例#7
0
 /**
  * @expectedException EmulateBugException
  */
 public function testExtendsWithFilterException()
 {
     $jade = new Jade();
     $jade->filter('throw-exception', function () {
         throw new EmulateBugException("Bad filter", 1);
     });
     $jade->render(__DIR__ . '/../templates/auxiliary/extends-exception-filter.jade');
 }
示例#8
0
 public function testClassAttribute()
 {
     $jade = new Jade(array('singleQuote' => false, 'classAttribute' => 'className'));
     $actual = trim($jade->render('.foo.bar Hello'));
     $expected = '<div className="foo bar">Hello</div>';
     $this->assertSame($expected, $actual);
 }
示例#9
0
    /**
     * @group php-filter-prettyprint
     */
    public function testPhpFilterWithPrettyprint()
    {
        $jade = new Jade(array('prettyprint' => true));
        $actual = trim($jade->render('
h1
    :php
        | BAR-
        echo 6 * 7
        | -BAR
'));
        $expected = '/^<h1>\\n    BAR-42\\s+-BAR\\s*\\n<\\/h1>$/';
        $this->assertRegExp($expected, $actual, 'Block filter');
        $actual = trim($jade->render('
h1
    span BAR-
    :php
        echo 6 * 7
    span -BAR
'));
        $expected = '/^<h1>\\s+<span>BAR-<\\/span>\\s+42\\s+<span>-BAR<\\/span><\\/h1>$/';
        $this->assertRegExp($expected, $actual, 'Block filter and span');
        $actual = trim($jade->render('
h1
    | BAR-
    :php echo 6 * 7
    | -BAR
'));
        $expected = '/^<h1>\\s+BAR-\\s+42\\s+-BAR\\s*<\\/h1>$/';
        $this->assertRegExp($expected, $actual, 'One-line filter');
        $actual = $jade->render('h1 BAR-#[:php echo 6 * 7]-BAR');
        $expected = '/^<h1>\\s+BAR-\\s+42\\s+-BAR\\s*<\\/h1>$/';
        $this->assertRegExp($expected, $actual, 'In-line filter');
    }
示例#10
0
<?php

require __DIR__ . '/../../vendor/autoload.php';
use Jade\Jade;
$jade = new Jade();
echo $jade->render(__DIR__ . '/' . basename(__FILE__, '.php') . '.jade');
示例#11
0
 /**
  * @expectedException \ErrorException
  * @expectedExceptionCode 5
  */
 public function testMissingDirectory()
 {
     $jade = new Jade(array('singleQuote' => false, 'cache' => 'does/not/exists'));
     $jade->render(__DIR__ . '/../templates/attrs.jade');
 }
示例#12
0
 public function testKeyWordArguments()
 {
     $jade = new Jade(array('singleQuote' => false, 'prettyprint' => false));
     $foo = function ($args, $block, $keyWord) {
         return $keyWord;
     };
     $jade->setKeyword('foo', $foo);
     $actual = trim($jade->render("foo\n"));
     $expected = 'foo';
     $this->assertSame($expected, $actual);
     $jade->setKeyword('bar', $foo);
     $actual = trim($jade->render("bar\n"));
     $expected = 'bar';
     $this->assertSame($expected, $actual);
     $jade->setKeyword('minify', function ($args, $block) {
         $names = array();
         foreach ($block->nodes as $index => $tag) {
             if ($tag->name === 'link') {
                 $href = $tag->getAttribute('href');
                 $names[] = substr($href['value'], 1, -5);
                 unset($block->nodes[$index]);
             }
         }
         return '<link href="' . implode('-', $names) . '.min.css">';
     });
     $actual = trim($jade->render("minify\n" . "  link(href='foo.css')\n" . "  link(href='bar.css')\n"));
     $expected = '<link href="foo-bar.min.css">';
     $this->assertSame($expected, $actual);
     $jade->setKeyword('concat-to', function ($args, $block) {
         $names = array();
         foreach ($block->nodes as $index => $tag) {
             if ($tag->name === 'link') {
                 unset($block->nodes[$index]);
             }
         }
         return '<link href="' . $args . '">';
     });
     $actual = trim($jade->render("concat-to app.css\n" . "  link(href='foo.css')\n" . "  link(href='bar.css')\n"));
     $expected = '<link href="app.css">';
     $this->assertSame($expected, $actual);
 }
示例#13
0
 /**
  * @{inheritDoc}
  */
 public function partial($view, array $data = [])
 {
     return $this->jade->render("{$this->path}/{$view}", $data);
 }
示例#14
0
文件: index.php 项目: vsuh/ss
$jext = '.jade';
echo "<br><br><br><br>";
//  var_dump($_POST);
$depList = getDepartmentList();
$mode = $_GET['mode'] ? $_GET['mode'] : 'bd';
$currDep = $_POST['rep_dept'] ? $_POST['rep_dept'] : "000000000";
$tpl = getTemplate($mode);
if ($_POST['go']) {
    switch ($mode) {
        case 'bd':
            $content = get_bd_content($currDep);
            break;
        case 'mv':
            $content = get_mv_content($currDep, $_POST);
            break;
        case 'ls':
            $content = get_list_employee($currDep);
            break;
        case 'vc':
            $content = get_vacations($currDep);
            break;
        case 'fr':
            $content = get_fired_list($currDep, $_POST);
            break;
    }
}
//  echo 'content';
//  var_dump($content);
//  var_dump($tpl);
$jade->render($tpl, ['currDepCode' => $currDep, 'currDep' => $currDep == "000000000" ? "" : $depList[$currDep], 'depList' => $depList, 'mode' => $mode, 'title' => 'Списки сотрудников сотрудников', 'content' => is_array($content) ? $content : array(), 'arrMonth' => get_month_array(), 'PeriodBeg' => $_POST['rep-period-from'] ? $_POST['rep-period-from'] : date('01-m-Y'), 'PeriodEnd' => $_POST['rep-period-to'] ? $_POST['rep-period-to'] : date('t-m-Y'), 'go' => $_POST['go'], 'reason' => $_POST['rep-purp']]);