Skip to content

Commit

Permalink
Latte bridge: compatibility with Latte master
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed May 5, 2016
1 parent 9bb9cec commit 55210af
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/Bridges/ApplicationLatte/UIMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static function install(Latte\Compiler $compiler)
public function initialize()
{
$this->getCompiler()->addMethod('getParentName', '
return !$this->getReferrerTemplate() && $this->params["_control"] instanceof Nette\Application\UI\Presenter
return !$this->getReferringTemplate() && $this->params["_control"] instanceof Nette\Application\UI\Presenter
? $this->params["_control"]->findLayoutTemplateFile() : NULL;
');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Bridges/ApplicationLatte/UIRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static function initialize(Latte\Template $template, $blockQueue)
$params = $template->getParameters();
if (!$template->getParentName() && !empty($params['_control']->snippetMode)) {
$tmp = $template;
while (in_array($tmp->getReferenceType(), ['extends', 'include', NULL], TRUE) && ($tmp = $tmp->getReferrerTemplate()));
while (in_array($tmp->getReferenceType(), ['extends', 'include', NULL], TRUE) && ($tmp = $tmp->getReferringTemplate()));
if (!$tmp) {
self::renderSnippets($params['_control'], $blockQueue, $params);
return TRUE;
Expand Down
10 changes: 7 additions & 3 deletions tests/Bridges.Latte/expected/UIMacros.dynamicsnippets.alt.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
class Template%a% extends Latte\Template
{
public $blocks = [
'_outer1' => ['blockOuter1', 'html'],
'_outer2' => ['blockOuter2', 'html'],
'_outer1' => 'blockOuter1',
'_outer2' => 'blockOuter2',
];

public $blockTypes = [
'_outer1' => 'html',
'_outer2' => 'html',
];


Expand All @@ -17,7 +22,6 @@ class Template%a% extends Latte\Template
$template = $this->params["template"];

// main template
if ($this->tryRenderParent(get_defined_vars())) return;
?><div id="<?php echo $_control->getSnippetId('outer1') ?>"><?php call_user_func(reset($this->blockQueue['_outer1']), $this->params) ?></div>

<div id="<?php echo $_control->getSnippetId('outer2') ?>"><?php call_user_func(reset($this->blockQueue['_outer2']), $this->params) ?></div><?php
Expand Down
11 changes: 6 additions & 5 deletions tests/Bridges.Latte/expected/UIMacros.dynamicsnippets.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
class Template%a% extends Latte\Template
{
public $blocks = [
'_outer' => ['blockOuter', 'html'],
'_outer' => 'blockOuter',
];

public $blockTypes = [
'_outer' => 'html',
];


Expand All @@ -16,7 +20,6 @@ class Template%a% extends Latte\Template
$template = $this->params["template"];

// main template
if ($this->tryRenderParent(get_defined_vars())) return;
?><div id="<?php echo $_control->getSnippetId('outer') ?>"><?php call_user_func(reset($this->blockQueue['_outer']), $this->params) ?></div><?php

}
Expand All @@ -40,9 +43,7 @@ class Template%a% extends Latte\Template

#<?php echo LFilters::escapeHtmlText($id) ?>

<?php $this->local->dynSnippets[$this->local->dynSnippetId] = ob_get_flush() ?>
</div>
<?php
<?php $this->local->dynSnippets[$this->local->dynSnippetId] = ob_get_flush() ?></div><?php
$iterations++;
}
?> <?php
Expand Down
16 changes: 10 additions & 6 deletions tests/Bridges.Latte/expected/UIMacros.snippet.alt.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@
class Template%a% extends Latte\Template
{
public $blocks = [
'_outer' => ['blockOuter', 'html'],
'_inner' => ['blockInner', 'html'],
'_gallery' => ['blockGallery', 'html'],
'_outer' => 'blockOuter',
'_inner' => 'blockInner',
'_gallery' => 'blockGallery',
];

public $blockTypes = [
'_outer' => 'html',
'_inner' => 'html',
'_gallery' => 'html',
];


Expand All @@ -19,9 +25,7 @@ class Template%a% extends Latte\Template

// main template
?> <div class="test"<?php echo ' id="' . $_control->getSnippetId('outer') . '"' ?>>
<?php
if ($this->tryRenderParent(get_defined_vars())) return;
call_user_func(reset($this->blockQueue['_outer']), $this->params) ?>
<?php call_user_func(reset($this->blockQueue['_outer']), $this->params) ?>
</div>

<div class="test"<?php echo ' id="' . $_control->getSnippetId('inner') . '"' ?>>
Expand Down
19 changes: 13 additions & 6 deletions tests/Bridges.Latte/expected/UIMacros.snippet.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@
class Template%a% extends Latte\Template
{
public $blocks = [
'_' => ['block_%h%', 'html'],
'_outer' => ['blockOuter', 'html'],
'_inner' => ['blockInner', 'html'],
'_title' => ['blockTitle', 'html'],
'_title2' => ['blockTitle2', 'html'],
'_' => 'block_b14a7',
'_outer' => 'blockOuter',
'_inner' => 'blockInner',
'_title' => 'blockTitle',
'_title2' => 'blockTitle2',
];

public $blockTypes = [
'_' => 'html',
'_outer' => 'html',
'_inner' => 'html',
'_title' => 'html',
'_title2' => 'html',
];


Expand All @@ -20,7 +28,6 @@ class Template%a% extends Latte\Template
$template = $this->params["template"];

// main template
if ($this->tryRenderParent(get_defined_vars())) return;
?><div id="<?php echo $_control->getSnippetId('') ?>"><?php call_user_func(reset($this->blockQueue['_']), $this->params) ?></div>


Expand Down
42 changes: 27 additions & 15 deletions tests/Bridges.Latte/expected/UIMacros.snippet4.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@
class Template%a% extends Latte\Template
{
public $blocks = [
'_snippet' => ['blockSnippet', 'html'],
'block1' => ['blockBlock1', 'html'],
'_outer' => ['blockOuter', 'html'],
'block2' => ['blockBlock2', 'html'],
'block1' => 'blockBlock1',
'_snippet' => 'blockSnippet',
'_outer' => 'blockOuter',
'block2' => 'blockBlock2',
];

public $blockTypes = [
'block1' => 'html',
'_snippet' => 'html',
'_outer' => 'html',
'block2' => 'html',
];


function render()
{
%A%
// main template
if ($this->tryRenderParent(get_defined_vars())) return;
call_user_func(reset($this->blockQueue['_snippet']), $this->params);
call_user_func(reset($this->blockQueue['block1']), get_defined_vars());
?>


Expand All @@ -25,21 +31,23 @@ class Template%a% extends Latte\Template
}


function blockSnippet($_args)
function blockBlock1($_args)
{
extract($_args);
$_control->redrawControl('snippet', FALSE);

?><div<?php echo ' id="' . $_control->getSnippetId('snippet') . '"' ?>>
<?php call_user_func(reset($this->blockQueue['_snippet']), $this->params) ?>
</div>
<?php

}


function blockBlock1($_args)
function blockSnippet($_args)
{
extract($_args);
?><div<?php echo ' id="' . $_control->getSnippetId('snippet') . '"' ?>>
static
</div>
$_control->redrawControl('snippet', FALSE);

?> static
<?php
}

Expand All @@ -51,6 +59,9 @@ class Template%a% extends Latte\Template

?>
begin
<?php
call_user_func(reset($this->blockQueue['block2']), get_defined_vars());
?>
end
<?php
if (isset($this->local->dynSnippets)) return $this->local->dynSnippets;
Expand All @@ -62,9 +73,10 @@ end
{
extract($_args);
?><div<?php echo ' id="' . ($this->local->dynSnippetId = $_control->getSnippetId("inner-$id")) . '"' ?>>
dynamic
</div>
<?php ob_start() ?> dynamic
<?php $this->local->dynSnippets[$this->local->dynSnippetId] = ob_get_flush() ?></div>
<?php

}

}

0 comments on commit 55210af

Please sign in to comment.