コード例 #1
0
ファイル: PrettyTest.php プロジェクト: TeaMeow/Avane
    public function testSingle()
    {
        $phtml = <<<'PHTML'
<div class="container">
  <div class="row">
    <div class="col-md-6 col-sm-3">
      <p>
        Some content
      </p>
    </div>
    <div class="col-md-6 col-sm-3">
      <p>
        Some content
      </p>
    </div>
    <div class="col-md-6 col-sm-3">
      <p>
        Some content
      </p>
    </div>
  </div>
</div>
PHTML;
        $this->assertEquals(str_replace("\r", '', $phtml), $this->renderer->compileFile('single'));
    }
コード例 #2
0
    public function testIssue18()
    {
        $jade = <<<JADE
- if (\$something):
    p Do something
- endif;



- if (\$something && \$somethingElse) {
    p Do some random stuff
- }



-
    if (\$something && \$somethingElse) {
        echo "No jade handling here";
    }

    \$array = ["a","b"
        "c", "d",
            "e", "f",
        "g",
    "h"];

p and it goes on normally...
JADE;
        $this->assertEquals('<?php if ($something):?><p>Do something</p><?php endif;?><?php if ($something && $somethingElse) {?><p>Do some random stuff</p><?php }?><?php if ($something && $somethingElse) {echo "No jade handling here"; } $array = ["a","b""c", "d","e", "f", "g", "h"];?><p>and it goes on normally...</p>', $this->_renderer->compile($jade));
    }
コード例 #3
0
ファイル: PrettyTest.php プロジェクト: talesoft/tale-jade
    public function testForcedInlineTags()
    {
        $phtml = <<<'PHTML'
<?php $content = "This is some Content.\n\n    This comment contains own whitespace to preserve."?>
<some-container>
  <pre><?=htmlentities(isset($content) ? $content : '', \ENT_QUOTES, 'UTF-8')?></pre>
  <pre>Some <strong>interpolated content</strong></pre>
  <div>
    <?=htmlentities(isset($content) ? $content : '', \ENT_QUOTES, 'UTF-8')?>
  </div>
  <div>
    Some 
    <strong>
      interpolated content
    </strong>
  </div>
  <code><?=htmlentities(isset($content) ? $content : '', \ENT_QUOTES, 'UTF-8')?></code>
  <code>Some <strong>interpolated content</strong></code>
</some-container>
PHTML;
        $this->assertEquals(str_replace("\r", '', $phtml), $this->renderer->compileFile('forced-inline'));
    }
コード例 #4
0
 public function testTagInterpolation()
 {
     $this->assertEquals('<?php $tagName = \'abcdefghi\'?><<?=htmlentities(isset($tagName) ? $tagName : \'\', \\ENT_QUOTES, \'UTF-8\')?> class="some-class">Some Content</<?=htmlentities(isset($tagName) ? $tagName : \'\', \\ENT_QUOTES, \'UTF-8\')?>>', $this->renderer->compile("\$tagName='abcdefghi'\n#{\$tagName}.some-class Some Content"));
     $this->assertEquals('<?php $tagName = \'def\'?><abc<?=htmlentities(isset($tagName) ? $tagName : \'\', \\ENT_QUOTES, \'UTF-8\')?>ghi class="some-class">Some Content</abc<?=htmlentities(isset($tagName) ? $tagName : \'\', \\ENT_QUOTES, \'UTF-8\')?>ghi>', $this->renderer->compile("\$tagName='def'\nabc#{\$tagName}ghi.some-class Some Content"));
     $this->assertEquals('<?php $t1 = \'abc\'?><?php $t2 = \'def\'?><abc<?=htmlentities(isset($t1) ? $t1 : \'\', \\ENT_QUOTES, \'UTF-8\')?>ghi-<?=htmlentities(isset($t2) ? $t2 : \'\', \\ENT_QUOTES, \'UTF-8\')?> class="some-class">Some Content</abc<?=htmlentities(isset($t1) ? $t1 : \'\', \\ENT_QUOTES, \'UTF-8\')?>ghi-<?=htmlentities(isset($t2) ? $t2 : \'\', \\ENT_QUOTES, \'UTF-8\')?>>', $this->renderer->compile("\$t1='abc'\n\$t2='def'\nabc#{\$t1}ghi-#{\$t2}.some-class Some Content"));
 }
コード例 #5
0
ファイル: VariableTest.php プロジェクト: TeaMeow/Avane
 public function testAssignment()
 {
     $this->assertEquals('<p>Hello World!</p>nowrap212<div style="width: 100%; height: 50%"></div>', $this->renderer->render('assignment', ['existing' => ['style' => ['width' => '100%'], 'class' => 'test']]));
 }
コード例 #6
0
ファイル: IssueTest.php プロジェクト: TeaMeow/Avane
 public function testIssue105()
 {
     $this->assertEquals('<script id="stylmock" data-items="globals" data-project="wdg_inv_2016_olya" data-save_path="c:\\\\Apache24\\\\htdocs\\\\romero\\\\wdg\\\\wdg_html\\\\wp-content\\\\themes\\\\invite2016\\\\styles.css"></script>', $this->renderer->compile("script#stylmock(data-items='globals' data-project='wdg_inv_2016_olya' data-save_path='c:\\\\Apache24\\\\htdocs\\\\romero\\\\wdg\\\\wdg_html\\\\wp-content\\\\themes\\\\invite2016\\\\styles.css')"));
 }
コード例 #7
0
ファイル: MixinTest.php プロジェクト: B7th/tale-jade
 public function testVariadic()
 {
     $this->assertEquals('<h1>Test 1</h1><item name="Item 1" id="51"></item><item name="Item 2" id="52"></item><item name="Item 4" id="54"></item><h1>Test 2</h1><item name="Item 5" id="55"></item><item name="Item 6" id="56"></item><item name="Item 7" id="57"></item>', $this->_renderer->render('variadic', ['items' => [['name' => 'Item 1', 'id' => 51], ['name' => 'Item 2', 'id' => 52], ['name' => 'Item 3', 'id' => 53], ['name' => 'Item 4', 'id' => 54], ['name' => 'Item 5', 'id' => 55], ['name' => 'Item 6', 'id' => 56], ['name' => 'Item 7', 'id' => 57], ['name' => 'Item 8', 'id' => 58]]]));
 }
コード例 #8
0
ファイル: DoctypeTest.php プロジェクト: TeaMeow/Avane
 public function testXhtmlDoctype()
 {
     $this->assertEquals('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><!-- these should (self)-close --><hr /><img /><link /><area /><!-- These should repeat --><a disabled="disabled" selected="selected" checked="checked">Some link</a><!-- this should self-close --><some-element></some-element><!-- this shouldn\'t self-close --><some-element>Some Content</some-element>', $this->renderer->render('xhtml'));
 }
コード例 #9
0
ファイル: index.php プロジェクト: GodLesZ/tale-jade
ini_set('display_startup_errors', 1);
ini_set('error_reporting', E_ALL | E_NOTICE);
use Tale\Jade\Compiler;
use Tale\Jade\Renderer;
$minify = isset($_GET['minify']) ? true : false;
$handleErrors = isset($_GET['withErrorHandler']) ? true : false;
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest') {
    $compiler = new Compiler(['pretty' => !$minify, 'handleErrors' => $handleErrors, 'allowImports' => false]);
    $jade = isset($_POST['jade']) ? $_POST['jade'] : '';
    header('Content-Type: text/plain; encoding=utf-8');
    try {
        echo json_encode($compiler->compile(str_replace("\t", '    ', $jade)));
    } catch (Exception $e) {
        echo json_encode($e->getMessage());
    }
    exit;
}
$renderer = new Renderer(['compiler' => ['pretty' => true], 'adapter' => 'file', 'adapterOptions' => ['lifeTime' => 0]]);
$example = isset($_GET['example']) ? $_GET['example'] : 'welcome';
$exampleJade = '';
$example = preg_replace('/[^a-z0-9\\-]+/i', '', $example);
if (file_exists(__DIR__ . '/examples/' . $example . '.jade')) {
    $exampleJade = file_get_contents(__DIR__ . '/examples/' . $example . '.jade');
}
$action = isset($_GET['page']) ? preg_replace('/^[a-z0-9\\-]+$/i', '', $_GET['example']) : 'index';
$exampleJade = json_encode($exampleJade);
$url = $_SERVER['PHP_SELF'];
header('Content-Type: text/html; encoding=utf-8');
mb_internal_encoding('UTF-8');
ob_start('mb_output_handler');
echo $renderer->render('views/index', ['action' => $action, 'example' => $example, 'exampleJade' => $exampleJade, 'url' => $url, 'minify' => json_encode($minify), 'handleErrors' => json_encode($handleErrors)]);
コード例 #10
0
 public function testIdAndClassForwarding()
 {
     $this->assertEquals('<button class="btn btn-default" id="someId">My Button Label</button>', $this->_renderer->render('id-and-class-forwarding'));
 }
コード例 #11
0
ファイル: MixinTest.php プロジェクト: TeaMeow/Avane
 public function testDuplicateInInclude()
 {
     $this->renderer->getCompiler()->setOption('replace_mixins', true);
     $this->assertEquals('<p>Testing</p>', $this->renderer->render('duplicate-in-include'));
 }
コード例 #12
0
 /**
  * @dataProvider lexerOptionProvider
  */
 public function testRendererForwardsOptionsToLexer($option, $value)
 {
     $renderer = new Renderer(['lexerOptions' => [$option => $value]]);
     $this->assertEquals($value, $renderer->getCompiler()->getParser()->getLexer()->getOption($option));
 }
コード例 #13
0
 public function testIeConditionals()
 {
     $this->assertEquals('<!--[if IE8]><script src="ie8.js"></script> <![endif]-->', $this->renderer->compile("<!--[if IE8]>\nscript(src='ie8.js')\n<![endif]-->"));
 }
コード例 #14
0
ファイル: MixinTest.php プロジェクト: talesoft/tale-jade
 public function testCallNameInterpolation()
 {
     $this->assertEquals('<b-element>Some Content</b-element><c-element>Some other content</c-element>', $this->renderer->render('interpolation'));
 }
コード例 #15
0
ファイル: AttributeTest.php プロジェクト: talesoft/tale-jade
 public function testSpaceSeparated()
 {
     $this->assertEquals('<meta name="viewport" content="some viewport content"><a href="google.de" target="_blank" title="Some link title"></a>', $this->renderer->render('space-separated'));
 }
コード例 #16
0
 public function testStandAloneCompilation()
 {
     $this->assertEquals('<p class="a b c d e f">Test!</p>', $this->renderer->render('basic', ['classes' => ['e', 'f']]));
 }
コード例 #17
0
ファイル: InterpolationTest.php プロジェクト: B7th/tale-jade
 public function testMailToLink()
 {
     $this->assertEquals('<div class="copyright">Copyright (c) 2016 <a href="mailto:tk@talesoft.io">tk@talesoft.io</a> Berlin</div>', $this->_renderer->compile('.copyright Copyright (c) 2016 #[a(href=\'mailto:tk@talesoft.io\') tk@talesoft.io] Berlin'));
 }
コード例 #18
0
                echo json_encode(['success' => false, 'message' => "\n" . get_class($e) . "\n\n" . $e->getMessage()]);
                exit;
            }
            echo json_encode(['success' => true, 'output' => (string) $result]);
            exit;
        default:
            echo json_encode(['success' => false, 'message' => 'Invalid mode selected']);
    }
}
$view = isset($_GET['view']) ? $_GET['view'] : 'index';
$example = isset($_GET['example']) ? $_GET['example'] : 'index';
$id = isset($_GET['id']) ? $_GET['id'] : null;
if (!file_exists(VIEW_PATH . "/{$view}.jade")) {
    $view = 'index';
}
$jade = '';
if ($id && preg_match('/^[a-z0-9]+$/i', $id)) {
    $path = SAVE_PATH . '/' . implode('/', str_split($id)) . '.jade';
    if (file_exists($path)) {
        $jade = file_get_contents($path);
    } else {
        $id = null;
    }
} else {
    if ($example && preg_match('/^[a-z0-9\\-]+$/i', $example) && $example !== 'empty' && file_exists(EXAMPLE_PATH . "/{$example}.jade")) {
        $jade = file_get_contents(EXAMPLE_PATH . "/{$example}.jade");
        $id = null;
    }
}
$renderer = new Renderer(['paths' => [__DIR__ . '/views'], 'pretty' => false, 'adapterOptions' => ['lifeTime' => 3600 * 24]]);
echo $renderer->render('index', ['jade' => $jade, 'example' => $example, 'id' => $id]);
コード例 #19
0
ファイル: index.php プロジェクト: GodLesZ/tale-jade-bootstrap
<?php

namespace MyWebsite;

use Tale\Jade\Renderer;
use Exception;
include 'vendor/autoload.php';
$config = ['cache' => false, 'pretty' => true, 'url' => 'http://localhost'];
if (file_exists(__DIR__ . '/config.php')) {
    $config = array_replace_recursive($config, include __DIR__ . '/config.php');
}
$renderer = new Renderer(['compiler' => ['pretty' => $config['pretty'], 'paths' => [__DIR__ . '/views/']], 'adapter' => 'file', 'adapterOptions' => ['path' => __DIR__ . '/cache', 'lifeTime' => $config['cache'] ? 3600 : 0]]);
$page = isset($_GET['page']) ? preg_replace('/[^a-z0-9\\-_]/i', '', $_GET['page']) : 'index';
$action = isset($_GET['action']) ? preg_replace('/[^a-z0-9\\-_]/i', '', $_GET['action']) : 'index';
try {
    echo $renderer->render('pages/' . $page, ['page' => $page, 'action' => $action, 'url' => $config['url']]);
} catch (Exception $e) {
    echo $renderer->render('pages/404', ['page' => $page, 'action' => $action, 'url' => $config['url']]);
}
コード例 #20
0
ファイル: EscapingTest.php プロジェクト: B7th/tale-jade
 public function testCarriageReturnEscaping()
 {
     $this->assertEquals("<input value=\"Line 1\rLine 2\">", $this->_renderer->compile('input(value="Line 1\\rLine 2")'));
 }
コード例 #21
0
 public function testFor()
 {
     $this->assertEquals('<p>1 Character at 0 is a</p><p>1 Character at 1 is b</p><p>1 Character at 2 is c</p><p>1 Character at 3 is d</p><p>1 Character at 4 is e</p><p>1 Character at 5 is f</p><p>1 Character at 6 is g</p><p>1 Character at 7 is h</p><p>1 Character at 8 is i</p><p>1 Character at 9 is j</p><p>1 Character at 10 is k</p><p>1 Character at 11 is l</p><p>1 Character at 12 is m</p><p>1 Character at 13 is n</p><p>1 Character at 14 is o</p><p>1 Character at 15 is p</p><p>1 Character at 16 is q</p><p>1 Character at 17 is r</p><p>1 Character at 18 is s</p><p>1 Character at 19 is t</p><p>1 Character at 20 is u</p><p>1 Character at 21 is v</p><p>1 Character at 22 is w</p><p>1 Character at 23 is x</p><p>1 Character at 24 is y</p><p>1 Character at 25 is z</p>', $this->_renderer->render('for'));
 }
コード例 #22
0
ファイル: IssueTest.php プロジェクト: marihachi/tale-jade
 public function testIssue66()
 {
     $this->assertEquals('<div class="blogentry" itemscope itemtype="http://schema.org/BlogPosting"></div>', $this->renderer->compile('.blogentry(itemscope itemtype="http://schema.org/BlogPosting")'));
 }
コード例 #23
0
ファイル: IssueTest.php プロジェクト: B7th/tale-jade
 public function testIssue57()
 {
     $this->assertEquals('<pre><code><?=htmlentities(\'<?php\', \\ENT_QUOTES, \'UTF-8\')?> <?=htmlentities(\'$foo = \'hey\';\', \\ENT_QUOTES, \'UTF-8\')?></code></pre>', $this->_renderer->compile("pre: code!.\n\t<?php\n\t\$foo = 'hey';"));
 }
コード例 #24
0
 public function testInvalidJadeInterpolation()
 {
     $this->setExpectedException(Compiler\Exception::class);
     $this->_renderer->compile('#[p Some content');
 }
コード例 #25
0
 public function testIssue55()
 {
     $this->assertEquals('<div class="col s6 right-align"><strong>Sign In</strong> / <?=$view->Html->link(\'Sign Up\', [\'action\' => \'add\'])?></div>', $this->_renderer->compile('.col.s6.right-align #[strong Sign In] / !{$view->Html->link(\'Sign Up\', [\'action\' => \'add\'])}'));
 }