Skip to content

Commit

Permalink
Fixed a bug regarding the replace_mixins option (See #99)
Browse files Browse the repository at this point in the history
  • Loading branch information
TorbenKoehn committed Jun 4, 2016
1 parent 7921cd7 commit d8d7652
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,8 @@ protected function handleMixins(Node $node)
"Duplicate mixin name $mixinNode->name",
$mixinNode
);
else if (isset($this->mixins[$mixinNode->name]))
$this->mixins[$mixinNode->name]->parent->remove($this->mixins[$mixinNode->name]);

$this->mixins[$mixinNode->name] = $mixinNode;
}
Expand Down
22 changes: 22 additions & 0 deletions Test/MixinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tale\Test\Jade;

use Tale\Jade\Compiler\Exception;
use Tale\Jade\Renderer;

class MixinTest extends \PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -82,4 +83,25 @@ public function testScoping()

$this->assertEquals('<h1>Parent Mixin</h1><div class="parent-block"><h2>Child Mixin</h2><div class="child-block"><span>This is test content</span><span>This content is fed from outside</span></div></div>', $this->renderer->render('scoping', ['fedFromOutside' => 'This content is fed from outside']));
}

public function testDuplicateWithoutOverwrite()
{

$this->setExpectedException(Exception::class);
$this->renderer->render('duplicate');
}

public function testDuplicateWithOverwrite()
{

$this->renderer->getCompiler()->setOption('replace_mixins', true);
$this->assertEquals('<p>Testing</p>', $this->renderer->render('duplicate'));
}

public function testDuplicateInInclude()
{

$this->renderer->getCompiler()->setOption('replace_mixins', true);
$this->assertEquals('<p>Testing</p>', $this->renderer->render('duplicate-in-include'));
}
}
4 changes: 4 additions & 0 deletions Test/views/mixins/duplicate-in-include.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

mixin test

include duplicate
9 changes: 9 additions & 0 deletions Test/views/mixins/duplicate.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

mixin test
block

mixin test
block

+test
p Testing

0 comments on commit d8d7652

Please sign in to comment.