Skip to content

Commit

Permalink
SnippetBridge: added setSnippetMode; added snippet test (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
matej21 authored and dg committed Jul 31, 2016
1 parent 82330d4 commit d47e06c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"nette/forms": "~2.4",
"nette/robot-loader": "~2.4",
"nette/security": "~2.4",
"latte/latte": "~2.4",
"latte/latte": "^2.4.1",
"tracy/tracy": "^2.4"
},
"conflict": {
Expand Down
6 changes: 6 additions & 0 deletions src/Bridges/ApplicationLatte/SnippetBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public function isSnippetMode()
}


public function setSnippetMode($snippetMode)
{
$this->control->snippetMode = $snippetMode;
}


public function needsRedraw($name)
{
return $this->control->isControlInvalid($name);
Expand Down
49 changes: 49 additions & 0 deletions tests/Bridges.Latte/UIMacros.renderSnippets4.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/**
* Test: UIMacros, renderSnippets and template rendered from another template
*/

use Nette\Bridges\ApplicationLatte\UIMacros;
use Nette\Bridges\ApplicationLatte\SnippetBridge;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';



class TestPresenter extends Nette\Application\UI\Presenter
{

public function render()
{
$latte = new Latte\Engine;
$latte->setLoader(new Latte\Loaders\StringLoader);
UIMacros::install($latte->getCompiler());
$latte->addProvider('uiControl', $this);
$latte->addProvider('snippetBridge', new SnippetBridge($this));
$latte->render('{snippet foo}{php $presenter->renderFoo()}{/snippet}', ['presenter' => $this]);
}

public function renderFoo()
{
$latte = new Latte\Engine;
$latte->setLoader(new Latte\Loaders\StringLoader);
UIMacros::install($latte->getCompiler());
$latte->addProvider('uiControl', $this);
$latte->addProvider('snippetBridge', new SnippetBridge($this));
$latte->render('Hello');
}
}


$presenter = new TestPresenter;
$presenter->snippetMode = TRUE;
$presenter->redrawControl('foo');
$presenter->render();
Assert::same([
'snippets' => [
'snippet--foo' => 'Hello',
],
], (array) $presenter->payload);

0 comments on commit d47e06c

Please sign in to comment.