Skip to content

Commit

Permalink
Merge pull request #61 from BKWLD/allow-composite-extension
Browse files Browse the repository at this point in the history
Fix .pug.* include/extend support
  • Loading branch information
kylekatarnls authored Apr 27, 2019
2 parents 6d378f6 + 64816dc commit be8f520
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
16 changes: 15 additions & 1 deletion src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ protected function getPugEngine()
$config['basedir'] = resource_path('views');
}

if (!isset($config['extensions']) && $this->app['view']) {
$extensions = array_keys(array_filter($this->app['view']->getExtensions(), function ($engine) {
$engines = explode('.', $engine);

return in_array('pug', $engines) || in_array('jade', $engines);
}));

$config['extensions'] = array_map(function ($extension) {
return ".$extension";
}, $extensions);
}

$pug = new Pug($config);
$this->assets = new Assets($pug);
$getEnv = array('App', 'environment');
Expand Down Expand Up @@ -252,7 +264,9 @@ public function getConfig()
{
$key = $this->version() >= 5 ? 'laravel-pug' : 'laravel-pug::config';

return $this->app->make('config')->get($key);
return array_merge(array(
'allow_composite_extensions' => true,
), $this->app->make('config')->get($key));
}

/**
Expand Down
25 changes: 19 additions & 6 deletions tests/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ class View
{
protected $extensions = array();

public function addExtension($extension)
public function addExtension($extension, $engine)
{
$this->extensions[] = $extension;
$this->extensions[$extension] = $engine;
}

public function getExtensions()
Expand Down Expand Up @@ -344,8 +344,8 @@ public function testBoot()
$this->provider->boot();

self::assertArraySubset(
["pug","pug.php","jade","jade.php","pug.blade","pug.blade.php","jade.blade","jade.blade.php"],
$view->getExtensions()
['pug', 'pug.php', 'jade', 'jade.php', 'pug.blade', 'pug.blade.php', 'jade.blade', 'jade.blade.php'],
array_keys($view->getExtensions())
);
self::assertSame('bkwld/laravel-pug', $this->provider->getCurrentPackage());
self::assertInstanceOf('Illuminate\View\Engines\CompilerEngine', $resolver->get('pug'));
Expand All @@ -365,8 +365,8 @@ public function testBoot()
$provider->boot();

self::assertArraySubset(
["pug","pug.php","jade","jade.php","pug.blade","pug.blade.php","jade.blade","jade.blade.php"],
$view->getExtensions()
['pug', 'pug.php', 'jade', 'jade.php', 'pug.blade', 'pug.blade.php', 'jade.blade', 'jade.blade.php'],
array_keys($view->getExtensions())
);
self::assertCount(1, $provider->getPub());
self::assertStringEndsWith('config.php', array_keys($provider->getPub())[0]);
Expand Down Expand Up @@ -462,6 +462,19 @@ public function testView()
);

@unlink($pug->getCompiler()->getCompiledPath($path));

if (!method_exists($pugEngine, 'renderFile')) {
return; // Skip for Pug-php < 3
}

$path = __DIR__.'/example2.pug.blade.php';

self::assertSame(
'<h1>{{ \'Start\' }}</h1><h1>Pug is there</h1><p>{{ $sentence }}</p>@if (1 === 1)<div>Go</div>@endif',
preg_replace('/\s{2,}/', '', call_user_func($method, $path))
);

@unlink($pug->getCompiler()->getCompiledPath($path));
}

public function testWithEmptyConfig()
Expand Down
5 changes: 5 additions & 0 deletions tests/example1.pug.blade
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
h1 Pug is there
p {{ $sentence }}
| @if (1 === 1)
div Go
| @endif
2 changes: 2 additions & 0 deletions tests/example2.pug.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
h1 {{ 'Start' }}
include example1

0 comments on commit be8f520

Please sign in to comment.