laravins / template-file-generator
File generator from template with data customization.
Installs: 13
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 1
Forks: 0
Open Issues: 0
Type:project
This package is auto-updated.
Last update: 2025-04-22 20:06:15 UTC
README
Introduction
This package allows you to generate files based on template with data customization.
Installation
composer require laravins/template-file-generator
This will install the package inside your project and setup example files.
Config file
located atconfig/template-file-generator/example-generator.php
Template files
located atresources/template-file-generator/example-generator/crud-views
Config file
This config file will:
-
Use template folder located at
projet_path/resources/template_file-generator/example-generator/crud-views
-
Generate two files
list.blade.php
andedit.blade.php
inproject_path/resources/views/users
. -
Replace each occurences of
%thanks%
byThanks for using this package 👌
of generatedlist.blade.php
file. -
Replace each occurences of
%stars%
byRoad to 50 ⭐
of generatedlist.blade.php
file. -
Replace each occurences of
%heart%
by❤️
of generatededit.blade.php
file. -
Replace each occurences of
%dev_attitude%
bylazy
of generatededit.blade.php
file.
<?php return [ 'files' => [ // Put here the list of files 'list.blade.php' => [ // Put here variables to replace 'thanks' => 'Thanks for using this package 👌', 'stars' => 'Road to 50 ⭐', ], 'edit.blade.php' => [ 'heart' => '❤️', 'dev_attitude' => 'lazy', ] ], 'config' => [ // Path of your template folder 'base_path' => 'template-file-generator/example-generator/crud-views', // Prefix of template folder path. Please, refer to prefixes section 'base_path_prefix' => 'resource', // Path of your target generated folder 'target_path' => 'views/users', // Prefix of template folder path. Please, refer to prefixes section 'target_path_prefix' => 'resource' ], ];
Prefixes
Allowed prefixes used for base_path_prefix
and target_path_prefix
are:
Prefix | Target |
---|---|
app | app_path() |
base | base_path() |
config | config_path() |
resource | resource_path() |
database | database_path() |
lang | lang_path() |
public | public_path() |
storage | storage_path() |
Template files
You need to set variables that you want to be replaced in %
delimiter like %var_to_change_%
.
<p>Made with %heart%</p> <p>For %dev_attitude% developers</p>
This will be converted into
<p>Made with ❤️</p> <p>For lazy developers</p>
Usage
use Laravins\TemplateFileGenerator\TemplateFileGenerator; // The path of my config file is actually 'config/template-file-generator/example-generator' $generator = new TemplateFileGenerator('template-file-generator/example-generator'); // Generate files $result = $generator->replaceContent(); // Get result dd($result) // ["status' => "success", "message" => ""] // If an error occurs, please refer to the "message" error.
Artisan command
php artisan laravins-tfg:generate template-file-generator/example-generator
Thanks ✌️