Skip to content
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
Merged

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

merged 4 commits into from
Mar 28, 2018

Conversation

JoshMoreno
Copy link
Contributor

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
Copy link
Contributor Author

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
-];

@cossssmin
Copy link

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

jigsaw-core.php Outdated
@@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@damiani
Copy link
Contributor

damiani commented Mar 27, 2018

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

@JoshMoreno
Copy link
Contributor Author

@damiani Sure thing. Removed.

@damiani damiani merged commit c668854 into tighten:master Mar 28, 2018
@JoshMoreno JoshMoreno deleted the expose-blade-for-extension branch March 28, 2018 13:59
@JoshMoreno
Copy link
Contributor Author

@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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants