Skip to content

Commit

Permalink
Fix missing include message
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Jul 29, 2016
1 parent 03e7cdd commit 7604fdf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/Jade/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function getTemplatePath($path)
}
}

protected function getTemplateContents($path)
protected function getTemplateContents($path, $value = null)
{
if ($path !== null) {
return file_get_contents($path);
Expand All @@ -98,7 +98,8 @@ protected function getTemplateContents($path)
return $notFound;
}

throw new \InvalidArgumentException("The included file '$path' does not exists.", 22);
$value = $value ?: $path;
throw new \InvalidArgumentException("The included file '$value' does not exists.", 22);
}

protected function setInput($filename, $input)
Expand Down Expand Up @@ -372,9 +373,10 @@ protected function parseCustomKeyword()

protected function parseExtends()
{
$path = $this->getTemplatePath($this->expect('extends')->value);
$extendValue = $this->expect('extends')->value;
$path = $this->getTemplatePath($extendValue);

$string = $this->getTemplateContents($path);
$string = $this->getTemplateContents($path, $extendValue);
$parser = new static($string, $path, $this->options);
// need to be a reference, or be seted after the parse loop
$parser->blocks = &$this->blocks;
Expand Down Expand Up @@ -428,14 +430,14 @@ protected function parseBlock()
protected function parseInclude()
{
$token = $this->expect('include');
$file = trim($token->value);
$path = $this->getTemplatePath($file);
$includeValue = trim($token->value);
$path = $this->getTemplatePath($includeValue);

if ($path && !$this->hasValidTemplateExtension($path)) {
return new Nodes\Literal(file_get_contents($path));
}

$string = $this->getTemplateContents($path);
$string = $this->getTemplateContents($path, $includeValue);

$parser = new static($string, $path, $this->options);
$parser->blocks = $this->blocks;
Expand Down
1 change: 1 addition & 0 deletions tests/features/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ public function testIncludeNotFoundDisabledViaStaticVariable()
*
* @expectedException \InvalidArgumentException
* @expectedExceptionCode 22
* @expectedExceptionMessageRegExp /does-not-exists/
*/
public function testIncludeNotFoundDisabledViaOption()
{
Expand Down

0 comments on commit 7604fdf

Please sign in to comment.