Skip to content

Commit 5339dad

Browse files
authored
Merge pull request #26 from phug-php/propagate-mixins
Propagate mixins to the layout
2 parents 987f6f1 + 377731e commit 5339dad

File tree

6 files changed

+35
-0
lines changed

6 files changed

+35
-0
lines changed

src/Phug/Compiler/NodeCompiler/ImportNodeCompiler.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Phug\Formatter\Element\CodeElement;
99
use Phug\Formatter\Element\ExpressionElement;
1010
use Phug\Formatter\Element\MarkupElement;
11+
use Phug\Formatter\Element\MixinElement;
1112
use Phug\Formatter\Element\TextElement;
1213
use Phug\Formatter\ElementInterface;
1314
use Phug\Parser\Node\FilterNode;
@@ -125,6 +126,16 @@ public function compileNode(NodeInterface $node, ElementInterface $parent = null
125126
}
126127

127128
if ($isIncludeImport) {
129+
$parentLayout = $compiler->getLayout();
130+
if ($parentLayout) {
131+
$parentDocument = $parentLayout->getDocument();
132+
foreach ($element->getChildren() as $child) {
133+
if ($child instanceof MixinElement) {
134+
$parentDocument->appendChild(clone $child);
135+
}
136+
}
137+
}
138+
128139
return $element;
129140
}
130141

tests/Phug/Compiler/NodeCompiler/ImportNodeCompilerTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,17 @@ public function testIncludeRawText()
249249
);
250250
}
251251

252+
/**
253+
* @covers ::<public>
254+
*/
255+
public function testNestedIncludedMixins()
256+
{
257+
$this->assertRenderFile(
258+
file_get_contents(__DIR__.'/../../../templates/issue26/error-test.html'),
259+
__DIR__.'/../../../templates/issue26/error-test.pug'
260+
);
261+
}
262+
252263
/**
253264
* @covers \Phug\Compiler::compileIntoElement
254265
* @expectedException \Phug\CompilerException
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!DOCTYPE html><html><body><h1>i am mixin</h1></body></html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extends ./layout.pug
2+
include ./test-mixin.pug
3+
4+
block body
5+
+test-mixin()

tests/templates/issue26/layout.pug

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
doctype html
2+
3+
html
4+
body
5+
block body
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mixin test-mixin()
2+
h1 i am mixin

0 commit comments

Comments
 (0)