takemo101 / laravel-simple-templa
Laravel Simple Templa
v0.1.5
2022-06-20 02:01 UTC
Requires
- php: ^8.0
- illuminate/console: ^8|^9
- illuminate/filesystem: ^8|^9
- illuminate/support: ^8|^9
- illuminate/validation: ^8|^9
- takemo101/simple-templa: ^0.1.4
Requires (Dev)
- php: ^8.0
- orchestra/testbench: ^7.0
- phpstan/phpstan: ^1.4
- phpunit/phpunit: ^9.5
README
This package is a wrap of Simple Templa for Laravel.
A Scaffold function using Simple Templa has also been added.
Installation
Execute the following composer command.
composer require takemo101/laravel-simple-templa
Publish the config
Publish the config with the following artisan command.
You can set filters and scaffolds from the config.
php artisan vendor:publish --tag="simple-templa"
How to use
Please use as follows
Simple Templa Facade
You can use the template language by using the Facade class.
// Get Template object $template = \SimpleTempla::template('{{ data.a }} {{ data.b }}'); // Run parse echo $template->parse([ 'data' => [ 'a' => 'hello', 'b' => 'world', ], ]); // hello world // Run parse immediately echo \SimpleTempla::parse( '{{ data.a }} {{ data.b }}'), [ 'data' => [ 'a' => 'hello', 'b' => 'world', ], ] ); // hello world
Scaffold
Run the Artisan command below to generate the Scaffold class.
php artisan make:scaff ClassName
Please set the input rule and output path in the generated Scaffold class.
<?php namespace App\Scaffolds; use Takemo101\LaravelSimpleTempla\Scaffold\Scaffold; // Must inherit from Scaffold class class DemoScaffold extends Scaffold { /** * Constructor injection is possible */ public function __construct() { // } /** * get need command option validation rules * * @return string[] */ public function rules(): array { return [ 'name' => 'required', ]; } /** * get inout path sets * * @param mixed[] $data * @return array<string,string|string[]> */ public function inoutPaths(array $data): array { // You can create a class file using the template language from the file return [ resource_path("stub/Entity.stub") => app_path("Entity/{{ name|ucfirst }}Entity.php"), ]; } }
Create a stub file as the output source.
<?php // ./resources/stub/Entity.stub namespace Stub\Entity\Demo{{ name|ucfirst }}; class Demo{{ name|ucfirst }}Entity { /** * @var string */ private string $name = '{{ key|lower }}'; }
Set the created Scaffold class in the config.
<?php // ./config/simple-sample.php return [ ... 'scaffolds' => [ 'demo' => App\Scaffolds\DemoScaffold::class, ], ]
After setting the Scaffold class, run Artisan to create the file.
php artisan simple-templa:exec demo
Filter for Laravel
In the template language, you can use Filter using Laravel's Str class.