Skip to content

Commit fbc1772

Browse files
committed
fix: publish templates command removed and use vendor views
1 parent a899872 commit fbc1772

6 files changed

+29
-136
lines changed

config/laravel_generator.php

-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737

3838
'schema_files' => resource_path('model_schemas/'),
3939

40-
'templates_dir' => resource_path('infyom/infyom-generator-templates/'),
41-
4240
'seeder' => database_path('seeders/'),
4341

4442
'database_seeder' => database_path('seeders/DatabaseSeeder.php'),

src/Commands/Publish/PublishTablesCommand.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ public function publishLivewireTableViews()
4545
$viewsPath = config('laravel_generator.path.views', resource_path('views/'));
4646
$templateType = config('infyom.laravel_generator.templates', 'adminlte-templates');
4747
$files = [
48-
'views/templates/scaffold/table/livewire/actions.blade.php' => 'common/livewire-tables/actions.blade.php',
48+
'scaffold.table.livewire.actions' => 'common/livewire-tables/actions.blade.php',
4949
];
5050

5151
g_filesystem()->createDirectoryIfNotExist($viewsPath.'common/livewire-tables');
5252

53-
foreach ($files as $stub => $blade) {
54-
$sourceFile = get_templates_package_path($templateType).'/'.$stub;
55-
$destinationFile = $viewsPath.$blade;
56-
$this->publishFile($sourceFile, $destinationFile, $blade);
53+
foreach ($files as $templateView => $destinationView) {
54+
$content = view($templateType.'::'.$templateView);
55+
$destinationFile = $viewsPath.$destinationView;
56+
g_filesystem()->createFile($destinationFile, $content);
5757
}
5858
}
5959

@@ -62,14 +62,14 @@ protected function publishDataTableViews()
6262
$viewsPath = config('laravel_generator.path.views', resource_path('views/'));
6363

6464
$files = [
65-
'layouts/datatables_css' => 'layouts/datatables_css.blade.php',
66-
'layouts/datatables_js' => 'layouts/datatables_js.blade.php',
65+
'layouts.datatables_css' => 'layouts/datatables_css.blade.php',
66+
'layouts.datatables_js' => 'layouts/datatables_js.blade.php',
6767
];
6868

69-
foreach ($files as $stub => $blade) {
70-
$sourceFile = get_template_file_path('views/scaffold/'.$stub, 'laravel-generator');
71-
$destinationFile = $viewsPath.$blade;
72-
$this->publishFile($sourceFile, $destinationFile, $blade);
69+
foreach ($files as $templateView => $destinationView) {
70+
$content = view('laravel-generator::scaffold.'.$templateView)->render();
71+
$destinationFile = $viewsPath.$destinationView;
72+
g_filesystem()->createFile($destinationFile, $content);
7373
}
7474
}
7575

src/Commands/Publish/PublishTemplatesCommand.php

-78
This file was deleted.

src/Commands/Publish/PublishUserCommand.php

+13-13
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ private function copyViews()
4040

4141
$files = $this->getViews();
4242

43-
foreach ($files as $stub => $blade) {
44-
$sourceFile = get_template_file_path('views/templates/'.$stub, $templateType);
45-
$destinationFile = $viewsPath.$blade;
46-
$this->publishFile($sourceFile, $destinationFile, $blade);
43+
foreach ($files as $templateView => $destinationView) {
44+
$content = view($templateType.'::'.$templateView);
45+
$destinationFile = $viewsPath.$destinationView;
46+
g_filesystem()->createFile($destinationFile, $content);
4747
}
4848
}
4949

@@ -55,13 +55,13 @@ private function createDirectories($dir)
5555
private function getViews(): array
5656
{
5757
return [
58-
'users/create' => 'users/create.blade.php',
59-
'users/edit' => 'users/edit.blade.php',
60-
'users/fields' => 'users/fields.blade.php',
61-
'users/index' => 'users/index.blade.php',
62-
'users/show' => 'users/show.blade.php',
63-
'users/show_fields' => 'users/show_fields.blade.php',
64-
'users/table' => 'users/table.blade.php',
58+
'users.create' => 'users/create.blade.php',
59+
'users.edit' => 'users/edit.blade.php',
60+
'users.fields' => 'users/fields.blade.php',
61+
'users.index' => 'users/index.blade.php',
62+
'users.show' => 'users/show.blade.php',
63+
'users.show_fields' => 'users/show_fields.blade.php',
64+
'users.table' => 'users/table.blade.php',
6565
];
6666
}
6767

@@ -83,8 +83,8 @@ private function updateMenu()
8383
$templateType = config('laravel_generator.templates', 'adminlte-templates');
8484
$path = $viewsPath.'layouts/menu.blade.php';
8585
$menuContents = g_filesystem()->getFile($path);
86-
$sourceFile = g_filesystem()->getFile(get_template_file_path('views/templates/users/menu', $templateType));
87-
$menuContents .= infy_nl().$sourceFile;
86+
$usersMenuContent = view($templateType.'::templates.users.menu')->render();
87+
$menuContents .= infy_nl().$usersMenuContent;
8888

8989
g_filesystem()->createFile($path, $menuContents);
9090
$this->comment("\nUser Menu added");

src/InfyOmGeneratorServiceProvider.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ public function boot()
5353
$configPath = __DIR__.'/../config/laravel_generator.php';
5454
$this->publishes([
5555
$configPath => config_path('laravel_generator.php'),
56-
]);
56+
], 'laravel-generator-config');
57+
58+
$this->publishes([
59+
__DIR__.'/../views' => resource_path('vendor/laravel-generator'),
60+
], 'laravel-generator-templates');
5761
}
5862

5963
$this->registerCommands();

src/helpers.php

-31
Original file line numberDiff line numberDiff line change
@@ -48,37 +48,6 @@ function infy_nl_tab(int $lns = 1, int $tabs = 1): string
4848
}
4949
}
5050

51-
if (!function_exists('get_template_file_path')) {
52-
function get_template_file_path(string $templateName, string $templateType): string
53-
{
54-
$templateName = str_replace('.', '/', $templateName);
55-
56-
$templatesPath = config(
57-
'laravel_generator.path.templates_dir',
58-
resource_path('infyom/infyom-generator-templates/')
59-
);
60-
61-
$path = $templatesPath.$templateName.'.blade.php';
62-
63-
if (file_exists($path)) {
64-
return $path;
65-
}
66-
67-
return get_templates_package_path($templateType).'/'.$templateName.'.blade.php';
68-
}
69-
}
70-
71-
if (!function_exists('get_templates_package_path')) {
72-
function get_templates_package_path(string $templateType): string
73-
{
74-
if (!str_contains($templateType, '/')) {
75-
$templateType = base_path('vendor/infyomlabs/').$templateType;
76-
}
77-
78-
return $templateType;
79-
}
80-
}
81-
8251
if (!function_exists('model_name_from_table_name')) {
8352
function model_name_from_table_name(string $tableName): string
8453
{

0 commit comments

Comments
 (0)