render() public method

This is the essence of the Jade-renderer and is the shortest and easiest way to get Jade running in your project Notice that if your file couldn't found, you need to pass _relative_ paths. The paths will be relative from the compiler:paths option or from get_include_path(), if no paths have been defined
public render ( string $file, array $args = null ) : string
$file string the relative path to the file to render
$args array an array of variables to pass to the Jade-file
return string The renderered markup
コード例 #1
0
ファイル: IssueTest.php プロジェクト: marihachi/tale-jade
 public function testIssue48()
 {
     $this->assertEquals('<h2>Hello</h2>', $this->renderer->render('issue-48/1'));
     $this->assertEquals(' <button>Submit</button>', $this->renderer->render('issue-48/views/view.ctp'));
     $this->assertEquals('<div id="clip_1"></div>', $this->renderer->render('issue-48/escaping', ['clipId' => 1]));
 }
コード例 #2
0
 public function testIfElseRendering()
 {
     $this->assertEquals('<p>1 This should be printed</p><p>4 This should be printed</p>', $this->_renderer->render('if-else', ['condition' => true, 'negativeCondition' => false]));
 }
コード例 #3
0
ファイル: EscapingTest.php プロジェクト: B7th/tale-jade
 public function testUnescapedInterpolationRendering()
 {
     $this->assertEquals('<p>In this random text i will insert an <a href="#">\' some random text &</a>, awesome, isn\'t it?</p>', $this->_renderer->render('unescaped-interpolation', ['expression' => '<a href="#">\' some random text &</a>']));
 }
コード例 #4
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]]]));
 }
コード例 #5
0
                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]);
コード例 #6
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'));
 }
コード例 #7
0
 public function testStandAloneCompilation()
 {
     $this->assertEquals('<p class="a b c d e f">Test!</p>', $this->renderer->render('basic', ['classes' => ['e', 'f']]));
 }
コード例 #8
0
ファイル: index.php プロジェクト: GodLesZ/tale-jade
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)]);
コード例 #9
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']]));
 }
コード例 #10
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'));
 }
コード例 #11
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'));
 }
コード例 #12
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']]);
}
コード例 #13
0
 public function testIdAndClassForwarding()
 {
     $this->assertEquals('<button class="btn btn-default" id="someId">My Button Label</button>', $this->_renderer->render('id-and-class-forwarding'));
 }
コード例 #14
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'));
 }
コード例 #15
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'));
 }