Наследование: extends Jade\Engine\Keywords
Пример #1
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);
 }
Пример #2
0
 public function testEngineOptions()
 {
     $jade = new Jade(array('terse' => false, 'indentChar' => '@'));
     $compiler = new Compiler($jade);
     $jade->setCustomOption('foo', 'bar');
     $this->assertFalse($compiler->getOption('terse'));
     $this->assertSame('@', $compiler->getOption('indentChar'));
     $this->assertSame('bar', $compiler->getOption('foo'));
 }
Пример #3
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);
 }
Пример #4
0
 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);
 }
Пример #5
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;
 }
 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);
 }
Пример #7
0
 /**
  * Get an option from the jade engine if set or from the options array else.
  *
  * @param string $option
  *
  * @throws \InvalidArgumentException
  *
  * @return mixed
  */
 public function getOption($option)
 {
     if (is_null($this->jade)) {
         if (!isset($this->options[$option])) {
             throw new \InvalidArgumentException("{$option} is not a valid option name.", 28);
         }
         return $this->options[$option];
     }
     return $this->jade->getOption($option);
 }
Пример #8
0
 /**
  * Remove the keywords.
  *
  * @return self   $this
  */
 public function unsetMinify()
 {
     $this->pug->removeKeyword('assets');
     $this->pug->removeKeyword('concat');
     $this->pug->removeKeyword('concat-to');
     $this->pug->removeKeyword('minify');
     $this->pug->removeKeyword('minify-to');
     $this->minify = null;
     return $this;
 }
Пример #9
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));
 }
Пример #10
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'));
}
Пример #11
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');
 }
Пример #12
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);
 }
Пример #13
0
 /**
  * @{inheritDoc}
  */
 public function partial($view, array $data = [])
 {
     return $this->jade->render("{$this->path}/{$view}", $data);
 }
Пример #14
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);
 }
Пример #15
0
 /**
  * test the Pug alias
  */
 public function testPugAlias()
 {
     $jade = new Jade();
     $pug = new Pug();
     $this->assertSame($jade->getOption('stream'), 'jade.stream');
     $this->assertSame($pug->getOption('stream'), 'pug.stream');
     $this->assertSame($pug->render('p Hello'), '<p>Hello</p>');
     $this->assertSame($pug->getExtension(), '.pug');
     $this->assertTrue(in_array('.pug', $pug->getExtensions()));
     $jade = new Jade(array('extension' => '.foo'));
     $this->assertSame($jade->getExtension(), '.foo');
     $this->assertFalse(in_array('.pug', $jade->getExtensions()));
     $this->assertTrue(in_array('.foo', $jade->getExtensions()));
     $jade->setOption('extension', array('.jade', '.pug'));
     $this->assertSame($jade->getExtension(), '.jade');
     $this->assertFalse(in_array('.foo', $jade->getExtensions()));
     $this->assertTrue(in_array('.jade', $jade->getExtensions()));
     $this->assertTrue(in_array('.pug', $jade->getExtensions()));
     $jade->setOption('extension', array());
     $this->assertSame($jade->getExtension(), '');
     $this->assertFalse(in_array('', $jade->getExtensions()));
     $this->assertFalse(in_array('.foo', $jade->getExtensions()));
     $this->assertFalse(in_array('.jade', $jade->getExtensions()));
     $this->assertFalse(in_array('.pug', $jade->getExtensions()));
     $jade->setOption('extension', '.pug');
     $this->assertSame($jade->getExtension(), '.pug');
     $this->assertFalse(in_array('', $jade->getExtensions()));
     $this->assertFalse(in_array('.foo', $jade->getExtensions()));
     $this->assertFalse(in_array('.jade', $jade->getExtensions()));
     $this->assertTrue(in_array('.pug', $jade->getExtensions()));
 }
Пример #16
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.');
 }
Пример #17
0
<?php

require __DIR__ . '/../../vendor/autoload.php';
use Jade\Jade;
$jade = new Jade();
echo $jade->render(__DIR__ . '/' . basename(__FILE__, '.php') . '.jade');
Пример #18
0
 /**
  * Compile the given Jade template contents.
  *
  * @param  string $value
  * @return string
  */
 public function compileString($value)
 {
     return $this->jade->compile($value);
 }
Пример #19
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');
    }
Пример #20
0
Файл: index.php Проект: vsuh/ss
<?php

require_once 'vendor/autoload.php';
require_once 'pub/lib/function.php';
use Jade\Jade;
$jade = new Jade();
$tpl_dir = __DIR__ . '\\pub\\tpls';
$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;