Exemple #1
0
 public function it_should_take_a_string_with_another_component_and_parse_it()
 {
     $testComponent = Raktiv::extend(['template' => '<p>Meet Little Bobby Raktiv</p>']);
     $this->beConstructedWith(['template' => '<p>Hello {{name}},</p><Test/>', 'data' => ['name' => 'Andrew']]);
     $this->addComponents(['Test' => $testComponent]);
     $this->render()->shouldBe("<p>Hello Andrew,</p><p>Meet Little Bobby Raktiv</p>");
 }
 public function it_should_parse_components_from_base_component_and_return_a_string()
 {
     $yowComponent = Raktiv::extend(['template' => 'Yow']);
     $raktiv = Raktiv::make();
     $raktiv->addComponent('Yow', $yowComponent);
     $talkComponent = Raktiv::extend(['template' => '<Yow />, wah gwaan']);
     $basicComponent = Raktiv::extend(['template' => '<h1><Talk /></h1>', 'components' => ['Talk' => $talkComponent]]);
     $this->addComponent('Basic', $basicComponent);
     $this->findComponent('Basic')->render()->shouldReturn('<h1>Yow, wah gwaan</h1>');
 }
Exemple #3
0
<?php

require "../vendor/autoload.php";
use PeelingPixels\Raktiv\Raktiv;
use Slim\App;
use Slim\Views\PhpRenderer;
$app = new App(['settings' => ['displayErrorDetails' => true]]);
$container = $app->getContainer();
$container['renderer'] = function () use($container) {
    $templatesDir = __DIR__ . '/app/templates/';
    return new PhpRenderer($templatesDir);
};
$app->get('/', function ($req, $res) {
    $templatesDir = __DIR__ . '/app/templates/';
    $data = ['fullName' => 'James Bond', 'hello' => ['name' => 'Jamie', 'library' => 'Ractive'], 'list' => ['shoppingList' => [['name' => 'Chips'], ['name' => 'Water'], ['name' => 'Milk']]], 'comments' => [['name' => 'Harry', 'text' => 'This is a test to make sure this works.']]];
    $comments = Raktiv::extend(['template' => file_get_contents($templatesDir . 'comments.html'), 'data' => ['comments' => $data['comments']]]);
    Raktiv::make()->addComponent('Comments', $comments);
    $list = Raktiv::extend(['template' => file_get_contents($templatesDir . 'list.html'), 'data' => $data['list']]);
    $hello = Raktiv::extend(['template' => file_get_contents($templatesDir . 'hello.html'), 'data' => $data['hello']]);
    $app = Raktiv::extend(['template' => file_get_contents($templatesDir . 'app.html'), 'components' => ['Hello' => $hello, 'List' => $list], 'data' => $data]);
    return $this->renderer->render($res, 'index.php', ['content' => $app->render(), 'json_data' => json_encode($data)]);
});
$app->run();