Skip to content

Commit

Permalink
Merge pull request #4 from kellymears/hotfix-undefined-variable
Browse files Browse the repository at this point in the history
[hotfix] undefined variable
  • Loading branch information
Log1x authored Nov 28, 2019
2 parents 6f19ed0 + a78c3ed commit 1fe65c4
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/SageSvgServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Log1x\SageSvg;

use Roots\Acorn\ServiceProvider;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Blade;

class SageSvgServiceProvider extends ServiceProvider
Expand All @@ -29,6 +28,7 @@ public function boot()
{
if ($this->app->bound('blade.compiler')) {
$this->directives();
$this->customDirectives();
}

$this->publishes([
Expand Down Expand Up @@ -64,18 +64,34 @@ protected function directives()
Blade::directive('svg', function ($expression) {
return "<?php echo e(get_svg($expression)); ?>";
});
}

if (! $directives = $this->config()['directives']) {
/**
* Register custom Blade directives.
*
* @return void
*/
protected function customDirectives()
{
if (class_exists('\BladeSvgSage\BladeSvgSage') || class_exists('\BladeSvg\SvgFactory')) {
return;
}

Collection::make($directives)->each(function ($path, $directive) {
if ($directives = collect($this->app->config->get('svg.directives')))->isEmpty()) {
return;
}

$directives->each(function ($path, $directive) {
Blade::directive($directive, function ($expression) use ($path) {
$parts = Collection::make(explode(',', $expression))->toArray();
$parts[0] = printf("'%s.%s'", $path, str_replace("'", "", $parts[0]));
$expression = Collection::make($parts)->implode(',');
$expression = collect(explode(',', $expression));

$expression = $expression->put(0, sprintf(
"'%s.%s'",
$path,
str_replace("'", '', $expression->first())
))->implode(',');

return "<?php echo e(get_svg($customExpression)); ?>";
return "<?php echo e(get_svg($expression)); ?>";
});
});
}
Expand Down

0 comments on commit 1fe65c4

Please sign in to comment.