Skip to content

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

Merged
damiani merged 4 commits intotighten:masterfrom
JoshMoreno:expose-blade-for-extension
Mar 28, 2018
Merged

Expose bladeCompiler in blade.php to make extending blade easier and more future-proof#204
damiani merged 4 commits intotighten:masterfrom
JoshMoreno:expose-blade-for-extension

Conversation

@JoshMoreno
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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

Comment thread jigsaw-core.php Outdated
});

(new BladeDirectivesFile($c['cwd'] . '/blade.php'))->register($bladeCompiler);
BladeDirectivesFile::init($c['cwd'] . '/blade.php', $bladeCompiler)->register();
Copy link
Copy Markdown
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
Copy Markdown
Contributor

damiani commented Mar 27, 2018

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

@JoshMoreno
Copy link
Copy Markdown
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
Copy Markdown
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