Skip to content

Commit 7fb490f

Browse files
committed
fix: various fixes after PR reviews
1 parent 1865898 commit 7fb490f

File tree

6 files changed

+24
-104
lines changed

6 files changed

+24
-104
lines changed

src/Commands/Publish/PublishTablesCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function publishDataTableViews()
6767
];
6868

6969
foreach ($files as $stub => $blade) {
70-
$sourceFile = get_file_path('views/scaffold/'.$stub, 'laravel-generator');
70+
$sourceFile = get_template_file_path('views/scaffold/'.$stub, 'laravel-generator');
7171
$destinationFile = $viewsPath.$blade;
7272
$this->publishFile($sourceFile, $destinationFile, $blade);
7373
}

src/Commands/Publish/PublishUserCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private function copyViews()
4141
$files = $this->getViews();
4242

4343
foreach ($files as $stub => $blade) {
44-
$sourceFile = get_file_path('views/templates/'.$stub, $templateType);
44+
$sourceFile = get_template_file_path('views/templates/'.$stub, $templateType);
4545
$destinationFile = $viewsPath.$blade;
4646
$this->publishFile($sourceFile, $destinationFile, $blade);
4747
}
@@ -71,7 +71,7 @@ private function updateRoutes()
7171

7272
$routeContents = g_filesystem()->getFile($path);
7373
$controllerNamespace = config('laravel_generator.namespace.controller');
74-
$routeContents .= "\n\n"."Route::resource('users', '$controllerNamespace\UserController')->middleware('auth');";
74+
$routeContents .= infy_nls(2)."Route::resource('users', '$controllerNamespace\UserController')->middleware('auth');";
7575

7676
g_filesystem()->createFile($path, $routeContents);
7777
$this->comment("\nUser route added");
@@ -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_file_path('views/templates/users/menu', $templateType));
87-
$menuContents .= "\n".$sourceFile;
86+
$sourceFile = g_filesystem()->getFile(get_template_file_path('views/templates/users/menu', $templateType));
87+
$menuContents .= infy_nl().$sourceFile;
8888

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

src/helpers.php

Lines changed: 16 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,6 @@ function get_template_file_path(string $templateName, string $templateType): str
6565
return $path;
6666
}
6767

68-
return get_templates_package_path($templateType).'/templates/'.$templateName.'.blade.php';
69-
}
70-
}
71-
72-
if (!function_exists('get_file_path')) {
73-
function get_file_path(string $templateName, string $templateType): string
74-
{
75-
$templateName = str_replace('.', '/', $templateName);
76-
77-
$templatesPath = config(
78-
'laravel_generator.path.templates_dir',
79-
resource_path('infyom/infyom-generator-templates/')
80-
);
81-
82-
$path = $templatesPath.$templateName.'.blade.php';
83-
84-
if (file_exists($path)) {
85-
return $path;
86-
}
87-
8868
return get_templates_package_path($templateType).'/'.$templateName.'.blade.php';
8969
}
9070
}
@@ -100,89 +80,29 @@ function get_templates_package_path(string $templateType): string
10080
}
10181
}
10282

103-
if (!function_exists('get_template')) {
104-
function get_template(string $templateName, string $templateType): string
105-
{
106-
$path = get_template_file_path($templateName, $templateType);
107-
108-
return g_filesystem()->getFile($path);
109-
}
110-
}
111-
112-
if (!function_exists('fill_template')) {
113-
function fill_template(array $variables, string $template): string
114-
{
115-
foreach ($variables as $variable => $value) {
116-
$template = str_replace($variable, $value, $template);
117-
}
118-
119-
return $template;
120-
}
121-
}
122-
123-
if (!function_exists('fill_field_template')) {
124-
function fill_field_template(array $variables, string $template, GeneratorField $field): string
125-
{
126-
foreach ($variables as $variable => $key) {
127-
$template = str_replace($variable, $field->$key, $template);
128-
}
129-
130-
return $template;
131-
}
132-
}
133-
134-
if (!function_exists('fill_template_with_field_data')) {
135-
function fill_template_with_field_data(array $variables, array $fieldVariables, string $template, GeneratorField $field): string
83+
if (!function_exists('model_name_from_table_name')) {
84+
function model_name_from_table_name(string $tableName): string
13685
{
137-
$template = fill_template($variables, $template);
138-
139-
return fill_field_template($fieldVariables, $template, $field);
86+
return Str::ucfirst(Str::camel(Str::singular($tableName)));
14087
}
14188
}
14289

143-
if (!function_exists('fill_template_with_field_data_locale')) {
144-
function fill_template_with_field_data_locale(array $variables, array $fieldVariables, string $template, GeneratorField $field): string
90+
if (!function_exists('create_resource_route_names')) {
91+
function create_resource_route_names($name, $isScaffold = false): array
14592
{
146-
$template = fill_template($variables, $template);
147-
$modelName = $variables['$MODEL_NAME_PLURAL_CAMEL$'];
148-
149-
return fill_field_template_locale($fieldVariables, $template, $field, $modelName);
150-
}
151-
}
93+
$result = [
94+
"'index' => '$name.index'",
95+
"'store' => '$name.store'",
96+
"'show' => '$name.show'",
97+
"'update' => '$name.update'",
98+
"'destroy' => '$name.destroy'",
99+
];
152100

153-
if (!function_exists('fill_field_template_locale')) {
154-
function fill_field_template_locale(array $variables, string $template, GeneratorField $field, string $modelName): string
155-
{
156-
foreach ($variables as $variable => $key) {
157-
$value = $field->name;
158-
$template = str_replace($variable, "@lang('models/$modelName.fields.$value')", $template);
101+
if ($isScaffold) {
102+
$result[] = "'create' => '$name.create'";
103+
$result[] = "'edit' => '$name.edit'";
159104
}
160105

161-
return $template;
106+
return $result;
162107
}
163108
}
164-
165-
if (!function_exists('model_name_from_table_name')) {
166-
function model_name_from_table_name(string $tableName): string
167-
{
168-
return Str::ucfirst(Str::camel(Str::singular($tableName)));
169-
}
170-
}
171-
172-
function createResourceRouteNames($name, $isScaffold = false)
173-
{
174-
$result = [
175-
"'index' => '$name.index'",
176-
"'store' => '$name.store'",
177-
"'show' => '$name.show'",
178-
"'update' => '$name.update'",
179-
"'destroy' => '$name.destroy'",
180-
];
181-
182-
if ($isScaffold) {
183-
$result[] = "'create' => '$name.create'";
184-
$result[] = "'edit' => '$name.edit'";
185-
}
186-
187-
return $result;
188-
}

views/api/routes.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Route::resource('{{ $config->prefixes->getRoutePrefixWith('/') }}{{ $config->modelNames->dashedPlural }}', {{ $config->namespaces->apiController }}\{{ $config->modelNames->name }}APIController::class){!! infy_nl_tab() !!}->except(['create', 'edit'])@if(!$config->prefixes->route);@endif
2-
@if($config->prefixes->route){!! infy_nl_tab().'->names(['.infy_nl_tab(1,2).implode(','.infy_nl_tab(1, 2), createResourceRouteNames($config->prefixes->getRoutePrefixWith('.').$config->modelNames->camelPlural)).infy_nl_tab().']);' !!}@endif
2+
@if($config->prefixes->route){!! infy_nl_tab().'->names(['.infy_nl_tab(1,2).implode(','.infy_nl_tab(1, 2), create_resource_route_names($config->prefixes->getRoutePrefixWith('.').$config->modelNames->camelPlural)).infy_nl_tab().']);' !!}@endif

views/scaffold/controller/controller_repository.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace {{ $config->namespaces->controller }};
66

7-
@if(config('laravel_generator.tables') == 'datatables')
7+
@if(config('laravel_generator.tables') === 'datatables')
88
use {{ $config->namespaces->dataTables }}\{{ $config->modelNames->name }}DataTable;
99
@endif
1010
use {{ $config->namespaces->request }}\Create{{ $config->modelNames->name }}Request;

views/scaffold/routes.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Route::resource('{{ $config->prefixes->getRoutePrefixWith('/') }}{{ $config->modelNames->dashedPlural }}', {{ $config->namespaces->controller }}\{{ $config->modelNames->name }}Controller::class)@if(!$config->prefixes->route);@endif
2-
@if($config->prefixes->route){!! infy_nl_tab().'->names(['.infy_nl_tab(1, 2).implode(','.infy_nl_tab(1, 2), createResourceRouteNames($config->prefixes->getRoutePrefixWith('.').$config->modelNames->camelPlural, true)).infy_nl_tab().']);' !!}@endif
2+
@if($config->prefixes->route){!! infy_nl_tab().'->names(['.infy_nl_tab(1, 2).implode(','.infy_nl_tab(1, 2), create_resource_route_names($config->prefixes->getRoutePrefixWith('.').$config->modelNames->camelPlural, true)).infy_nl_tab().']);' !!}@endif

0 commit comments

Comments
 (0)