New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose bladeCompiler in blade.php to make extending blade easier and more future-proof #204

Merged
merged 4 commits into from Mar 28, 2018

Conversation

Projects
None yet
3 participants
@JoshMoreno
Copy link
Contributor

JoshMoreno commented Mar 26, 2018

In blade.php the BladeCompiler is now exposed as $bladeCompiler;

An example of registering a component alias:

blade.php

/** @var \Illuminate\View\Compilers\BladeCompiler $bladeCompiler */
$bladeCompiler->component('_components.title');

// extend more
$bladeCompiler->include(...);
$bladeCompiler->directive(...);

// make sure you still return an array!
return [
    // custom directives... 
    // Same thing as calling $bladeCompiler->directive(...) above
];

index.blade.php

{{--before--}}
@component('_components.title')
    Title 1
@endcomponent

{{--after--}}
@title
    Title 2
@endtitle
@JoshMoreno

This comment has been minimized.

Copy link
Contributor

JoshMoreno commented Mar 26, 2018

Just made it optional to return an array from blade.php. Now you can still return an array of custom directives and/or simply interact with $bladeCompiler yourself.

So just to be clear, from the example above, returning an array is now optional:

/** @var \Illuminate\View\Compilers\BladeCompiler $bladeCompiler */
$bladeCompiler->component('_components.title');

// extend more
$bladeCompiler->include(...);
$bladeCompiler->directive(...);

-// make sure you still return an array!
-return [
-    // custom directives... 
-    // Same thing as calling $bladeCompiler->directive(...) above
-];
@hellocosmin

This comment has been minimized.

Copy link

hellocosmin commented Mar 27, 2018

This is awesome, can't wait to use it! Thanks Josh!

@@ -101,7 +101,7 @@
return new BladeMarkdownEngine($compilerEngine, $c[FrontMatterParser::class]);
});
(new BladeDirectivesFile($c['cwd'] . '/blade.php'))->register($bladeCompiler);
BladeDirectivesFile::init($c['cwd'] . '/blade.php', $bladeCompiler)->register();

This comment has been minimized.

@damiani

damiani Mar 27, 2018

Contributor

I think we can ditch the init static function, and just new the class up here directly.

@damiani

This comment has been minimized.

Copy link
Contributor

damiani commented Mar 27, 2018

@JoshMoreno Thanks! I've suggested one change, and then we can merge this in.

@JoshMoreno

This comment has been minimized.

Copy link
Contributor

JoshMoreno commented Mar 27, 2018

@damiani Sure thing. Removed.

@damiani damiani merged commit c668854 into tightenco:master Mar 28, 2018

@JoshMoreno JoshMoreno deleted the JoshMoreno:expose-blade-for-extension branch Mar 28, 2018

@JoshMoreno

This comment has been minimized.

Copy link
Contributor

JoshMoreno commented Mar 28, 2018

@damiani Thanks for merging! Really enjoying jigsaw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment