Skip to content

Commit

Permalink
custom blade directive small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Illia Sakovich committed Feb 24, 2020
1 parent 82b2df4 commit 9c54cc5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
17 changes: 11 additions & 6 deletions config/shared-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@
],

/*
* Blade directive name.
*
* By default the Blade directive named 'shared'.
*
* It means that the shared data rendering will be available in view files via `@shared`
* The settings for the Blade directive.
*/
'blade_directive' => 'shared',
'blade_directive' => [
/*
* Blade directive name.
*
* By default the Blade directive named 'shared'.
*
* It means that the shared data rendering will be available in view files via `@shared`.
*/
'name' => 'shared',
],
];
2 changes: 1 addition & 1 deletion src/Providers/SharedDataServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function register()
});

$this->app->extend('blade.compiler', function (BladeCompiler $bladeCompiler) {
$bladeCompiler->directive($this->app['config']['shared-data']['blade_directive'], function () {
$bladeCompiler->directive($this->app['config']['shared-data.blade_directive.name'], function () {
return '<?php echo app(\\'.SharedData::class.'::class)->render(); ?>';
});

Expand Down
8 changes: 3 additions & 5 deletions tests/SharedDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,13 @@ public function testBladeDirective()
/**
* @depends testBladeDirective
*/
public function testBladeDirectiveCustom()
public function testBladeDirectiveWithCustomName()
{
$this->app->make('config')->set('shared-data.blade_directive', 'shared_custom');

$this->app->register(SharedDataServiceProvider::class);
$this->app['config']['shared-data.blade_directive.name'] = 'shared_custom';

$this->assertEquals(
shared()->render(),
view('shared-custom')->render()
view('shared_custom')->render()
);
}
}
File renamed without changes.

0 comments on commit 9c54cc5

Please sign in to comment.