Skip to content

Commit

Permalink
Create cache automatically (#115)
Browse files Browse the repository at this point in the history
More clear exception and try to create the cache folder automatically
  • Loading branch information
kylekatarnls authored Feb 15, 2017
1 parent 4e0b17a commit ee240d4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/Jade/Compiler/CacheHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,14 @@ protected function getCacheDirectory()
{
$cacheFolder = $this->pug->getOption('cache');

if (!is_dir($cacheFolder)) {
throw new \ErrorException($cacheFolder . ': Cache directory seem\'s to not exists', 5);
if (!is_dir($cacheFolder) && !@mkdir($cacheFolder, 0777, true)) {
throw new \ErrorException(
$cacheFolder . ': Cache directory seem\'s to not exists' . "\n" .
'Create it with:' . "\n" .
'mkdir -p ' . escapeshellarg(realpath($cacheFolder)) . "\n" .
'Or replace your cache setting with a valid writable folder path.',
5
);
}

return $cacheFolder;
Expand Down
2 changes: 1 addition & 1 deletion tests/features/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testMissingDirectory()
{
$jade = new Jade(array(
'singleQuote' => false,
'cache' => 'does/not/exists'
'cache' => '///cannot/be/created'
));
$jade->render(__DIR__ . '/../templates/attrs.jade');
}
Expand Down

0 comments on commit ee240d4

Please sign in to comment.