Skip to content

Commit b8a1990

Browse files
committed
Add compilers as filters callback arguments
1 parent f51ba37 commit b8a1990

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/Phug/Compiler.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ public function importBlocks(array $blocks)
593593
*/
594594
public function registerImportPath($path)
595595
{
596-
$current = $this->getPath() ?: $this->getOption('filename');
596+
$current = $this->getPath();
597597
if (!isset($this->importPaths[$current])) {
598598
$this->importPaths[$current] = [];
599599
}
@@ -628,7 +628,7 @@ public function getImportPaths($path = null)
628628
*/
629629
public function getCurrentImportPaths()
630630
{
631-
return $this->getImportPaths($this->getPath() ?: $this->getOption('filename'));
631+
return $this->getImportPaths($this->getPath());
632632
}
633633

634634
/**
@@ -702,6 +702,7 @@ public function compile($input, $path = null)
702702

703703
$input = $compileEvent->getInput();
704704
$path = $compileEvent->getPath();
705+
$this->importPaths = [];
705706
$includes = [];
706707
foreach ($this->getOption('includes') as $include) {
707708
$includes[] = $this->compileDocument(file_get_contents($include), $include);

src/Phug/Compiler/NodeCompiler/FilterNodeCompiler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ public function proceedFilter($filter, $input, $options)
9999
return strval(call_user_func(
100100
$filter,
101101
$input,
102-
$options
102+
$options,
103+
$this->getCompiler(),
104+
$this
103105
));
104106
}
105107
}

tests/Phug/Compiler/NodeCompiler/FilterNodeCompilerTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Phug\Compiler;
66
use Phug\Compiler\NodeCompiler\FilterNodeCompiler;
7+
use Phug\CompilerInterface;
78
use Phug\Formatter\Element\DocumentElement;
89
use Phug\Formatter\Element\TextElement;
910
use Phug\Parser\Node\ElementNode;
@@ -140,6 +141,27 @@ public function testFilterOption()
140141
);
141142
}
142143

144+
/**
145+
* @covers ::<public>
146+
*/
147+
public function testFilterCompilerArgument()
148+
{
149+
$compiler = new Compiler([
150+
'filename' => '/directory/bar.pug',
151+
'filters' => [
152+
'foo' => function ($contents, $options, CompilerInterface $compiler) {
153+
return basename($compiler->getPath());
154+
},
155+
],
156+
]);
157+
self::assertSame(
158+
'bar.pug',
159+
$compiler->compile(
160+
':foo'
161+
)
162+
);
163+
}
164+
143165
/**
144166
* @covers ::compileText
145167
* @expectedException \Phug\CompilerException

0 commit comments

Comments
 (0)