Skip to content

Commit

Permalink
Add view path to end of compiled blade view
Browse files Browse the repository at this point in the history
This re-adds the functionality that was added in #27544 and #27976 and removed again in 33ce7bb.

The main difference with this approach is that it takes into account the issue from #27996. By not introducing a newline it doesn't changes anything to the rendered view itself. The path is now applied as the final piece of code. This doesn't allows IDE's to rely on it being the last line though. Instead we use /**PATH and ENDPATH**/ to make sure we have an easy way for the IDE to pick up the path it needs.
  • Loading branch information
driesvints committed Apr 4, 2019
1 parent 505325b commit 65f5ead
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/View/Compilers/BladeCompiler.php
Expand Up @@ -122,6 +122,10 @@ public function compile($path = null)
$this->files->get($this->getPath())
);

if (! empty($this->getPath())) {
$contents .= "<?php /**PATH {$this->getPath()} ENDPATH**/ ?>";
}

$this->files->put(
$this->getCompiledPath($this->getPath()), $contents
);
Expand Down
8 changes: 4 additions & 4 deletions tests/View/ViewBladeCompilerTest.php
Expand Up @@ -49,15 +49,15 @@ public function testCompileCompilesFileAndReturnsContents()
{
$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
$files->shouldReceive('get')->once()->with('foo')->andReturn('Hello World');
$files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('foo').'.php', 'Hello World');
$files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('foo').'.php', "Hello World<?php /**PATH foo ENDPATH**/ ?>");
$compiler->compile('foo');
}

public function testCompileCompilesAndGetThePath()
{
$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
$files->shouldReceive('get')->once()->with('foo')->andReturn('Hello World');
$files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('foo').'.php', 'Hello World');
$files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('foo').'.php', "Hello World<?php /**PATH foo ENDPATH**/ ?>");
$compiler->compile('foo');
$this->assertEquals('foo', $compiler->getPath());
}
Expand All @@ -73,7 +73,7 @@ public function testCompileWithPathSetBefore()
{
$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
$files->shouldReceive('get')->once()->with('foo')->andReturn('Hello World');
$files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('foo').'.php', 'Hello World');
$files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('foo').'.php', "Hello World<?php /**PATH foo ENDPATH**/ ?>");
// set path before compilation
$compiler->setPath('foo');
// trigger compilation with null $path
Expand All @@ -97,7 +97,7 @@ public function testIncludePathToTemplate()
{
$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
$files->shouldReceive('get')->once()->with('foo')->andReturn('Hello World');
$files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('foo').'.php', 'Hello World');
$files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('foo').'.php', "Hello World<?php /**PATH foo ENDPATH**/ ?>");
$compiler->compile('foo');
}

Expand Down

0 comments on commit 65f5ead

Please sign in to comment.