Skip to content

Commit

Permalink
Support namespace with debug mode on
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Sep 25, 2020
1 parent feaec94 commit 8dea3b4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/Phug/Formatter/Formatter/Util/PhpUnwrapString.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,20 @@ public static function withoutOpenTag($code)
{
$unwrappedCode = new self($code);
$unwrappedCode->unwrapStart();
$unwrappedCode->movePhugCodeAfterNamespace();

return $unwrappedCode;
}

public function movePhugCodeAfterNamespace()
{
$this->code = preg_replace(
'/^((?:[ \t]*(?:\\\\Phug\\\\.*\n|\\/\\/.*\n|(?:\?><\?php)?[ \t\n]+)?)*)(namespace (?:.*)\n)/',
'$2$1',
$this->code
);
}

public function unwrapStart()
{
$this->code = preg_match('/^<\?php\s/', $this->code)
Expand Down
2 changes: 1 addition & 1 deletion tests/Phug/CasesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function caseProvider()
public function testRender($expected, $actual, $message)
{
$debug = $this->renderer->getOption('debug');
$this->renderer->setOption('debug', pathinfo($actual)['filename'] !== 'scope');
$this->renderer->setOption('debug', true);
$render = $this->renderer->renderFile($actual);
$this->renderer->setOption('debug', $debug);

Expand Down

0 comments on commit 8dea3b4

Please sign in to comment.