From 7604fdf35dccfba79897c3288b8968fe0df9ca6e Mon Sep 17 00:00:00 2001 From: kylekatarnls Date: Fri, 29 Jul 2016 15:10:19 +0200 Subject: [PATCH] Fix missing include message --- src/Jade/Parser.php | 16 +++++++++------- tests/features/settings.php | 1 + 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Jade/Parser.php b/src/Jade/Parser.php index b1531d13..fc056449 100644 --- a/src/Jade/Parser.php +++ b/src/Jade/Parser.php @@ -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); @@ -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) @@ -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; @@ -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; diff --git a/tests/features/settings.php b/tests/features/settings.php index 11986c78..5c2eb1ac 100644 --- a/tests/features/settings.php +++ b/tests/features/settings.php @@ -370,6 +370,7 @@ public function testIncludeNotFoundDisabledViaStaticVariable() * * @expectedException \InvalidArgumentException * @expectedExceptionCode 22 + * @expectedExceptionMessageRegExp /does-not-exists/ */ public function testIncludeNotFoundDisabledViaOption() {