Skip to content

Commit

Permalink
Merge pull request #12 from victorwelling/embed-fix
Browse files Browse the repository at this point in the history
Undo regression in embedding templates
  • Loading branch information
Victor Welling committed Oct 3, 2018
2 parents 1ea7e63 + ad109a8 commit 8397b9a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/Twig/Node/DisplayEndNode.php
Expand Up @@ -39,6 +39,10 @@ public function __construct(ModuleNode $module)
*/
public function compile(Compiler $compiler)
{
if ($this->module->hasAttribute('is_embedded')) {
return;
}

$extension = Extension::class;
$templateName = $this->getTemplateName();
$view = View::class;
Expand Down
4 changes: 4 additions & 0 deletions src/Twig/Node/DisplayStartNode.php
Expand Up @@ -43,6 +43,10 @@ public function __construct(ModuleNode $module, FindPresentationModelInterface $
*/
public function compile(Compiler $compiler)
{
if ($this->module->hasAttribute('is_embedded')) {
return;
}

$presentationModel = $this->findPresentationModel->for($this->getTemplateName());

$compiler
Expand Down
7 changes: 7 additions & 0 deletions src/Twig/NodeVisitor/ModelNodeVisitor.php
Expand Up @@ -52,6 +52,13 @@ public function leaveNode(Node $node, Environment $environment): Node
return $node;
}

if ($node->hasAttribute('embedded_templates')) {
/** @var ModuleNode $embeddedTemplate */
foreach ($node->getAttribute('embedded_templates') as $embeddedTemplate) {
$embeddedTemplate->setAttribute('is_embedded', true);
}
}

$node->setNode('display_start', new DisplayStartNode($node, $this));
$node->setNode('display_end', new DisplayEndNode($node));

Expand Down
2 changes: 0 additions & 2 deletions tests/Integration/Embedding/EmbeddingTest.php
Expand Up @@ -66,8 +66,6 @@ public function testEmbeddedTemplatesShouldReceiveVariablesPassedAsArguments()
*/
public function testPresentersShouldOnlyBeCalledOnce()
{
$this->markTestSkipped('Presenters should only be called once: currently fails, fix pending.');

$this->pagePresenter
->expects($this->once())
->method('present');
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Embedding/Templates/page.twig
@@ -1,7 +1,7 @@
{% model 'Shoot\\Shoot\\Tests\\Integration\\Embedding\\Models\\Page' %}
{% extends 'base.twig' %}
{% block body %}
{% embed 'layout.twig' with { main_class: 'main--overriden'} only %}
{% embed 'layout.twig' with { main_class: 'main--overriden'} %}
{% block main %}
<h1>{{ title }}</h1>
<p>{{ content }}</p>
Expand Down

0 comments on commit 8397b9a

Please sign in to comment.