-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7356d67
Showing
5 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017 DevMcC | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# BladeExtended | ||
Expands the blade functionality of the Laravel framework with additional directives. | ||
|
||
|
||
|
||
# Installation | ||
Install this package with the following command from the root directory of your project: | ||
``` | ||
composer require devmcc/blade-extended | ||
``` | ||
|
||
|
||
## ServiceProvider | ||
After you have required this package and updated composer, add the ServiceProvider to the providers array in app/config.php | ||
``` | ||
DevMcC\BladeExtended\ServiceProvider::class, | ||
``` | ||
|
||
|
||
|
||
# Contents | ||
The following is a list of directives that this package adds to blade. | ||
|
||
|
||
## @block | ||
If your project doesn't permit the use of the else statement and it's a struggle to do this with blade without writing some else-in-disguise or some hacky ternary with includes, then the ```@block``` directive might come in handy. | ||
With this directive, you can define codeblocks, the contents of this block will simply work like everything else, with one exception and that is that you can kill this block with a ```@break```. | ||
|
||
``` | ||
@block | ||
@if ($results->isEmpty()) | ||
No results! | ||
@break | ||
@endif | ||
// Showing all results | ||
@endblock | ||
``` | ||
|
||
|
||
## @ifadd | ||
Echoes a string whether the condition is met. | ||
|
||
``` | ||
@ifadd($iNeedToEcho, 'sanitized output (")') | ||
@ifadd($iNeedToEcho, 'unsanitized output (")', false) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "devmcc/blade-extended", | ||
"description": "Expands the blade functionality of the Laravel framework with additional directives.", | ||
"keywords": [ | ||
"laravel", | ||
"blade", | ||
"directive" | ||
], | ||
"license": "MIT", | ||
"type": "library", | ||
"authors": [ | ||
{ | ||
"name": "DevMcC", | ||
"email": "sinbox.c@gmail.com" | ||
} | ||
], | ||
"require": {}, | ||
"autoload": { | ||
"psr-4": { | ||
"DevMcC\\BladeExtended\\": "src" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
/** | ||
* @author DevMcC <sinbox.c@gmail.com> | ||
* | ||
* @param mixed $if | ||
* @param mixed $add | ||
* @param bool $sanitize | ||
* | ||
* @return string | ||
*/ | ||
function __runIfAdd($if, $add, bool $sanitize = true) | ||
{ | ||
if (!$if) { | ||
return ''; | ||
} | ||
|
||
return $sanitize ? e($add) : $add; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace DevMcC\BladeExtended; | ||
|
||
use Illuminate\Support\Facades\Blade; | ||
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider; | ||
|
||
/** | ||
* Class ServiceProvider | ||
* | ||
* @author DevMcC <sinbox.c@gmail.com> | ||
* | ||
* @package DevMcC\BladeExtended | ||
*/ | ||
class ServiceProvider extends IlluminateServiceProvider | ||
{ | ||
/** | ||
* Perform post-0registration booting of services. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
foreach (glob(__DIR__.'/Functions/*.php') as $file) { | ||
require_once($file); | ||
} | ||
|
||
Blade::directive('ifadd', function ($expression) { | ||
return "<?php echo __runIfAdd($expression); ?>"; | ||
}); | ||
|
||
Blade::directive('block', function ($expression) { | ||
return "<?php do { ?>"; | ||
}); | ||
|
||
Blade::directive('endblock', function ($expression) { | ||
return "<?php } while (0); ?>"; | ||
}); | ||
} | ||
|
||
/** | ||
* Register bindings in the container. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
// | ||
} | ||
} |