Skip to content

Commit 9f91e43

Browse files
Merge pull request #1021 from InfyOmLabs/blade_templates
Blade templates
2 parents f15d1ad + fe7b70d commit 9f91e43

File tree

122 files changed

+2370
-4569
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+2370
-4569
lines changed

config/laravel_generator.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
|
104104
*/
105105

106-
'templates' => 'adminlte-templates',
106+
'templates' => 'adminlte-templates',
107107

108108
/*
109109
|--------------------------------------------------------------------------
@@ -146,6 +146,10 @@
146146

147147
'seeder' => false,
148148

149+
'swagger' => false, // generate swagger for your APIs
150+
151+
'tests' => false, // generate test cases for your APIs
152+
149153
'excluded_fields' => ['id'], // Array of columns that doesn't required while creating module
150154
],
151155

@@ -180,20 +184,6 @@
180184

181185
'tables' => 'blade',
182186

183-
/*
184-
|--------------------------------------------------------------------------
185-
| Add-Ons
186-
|--------------------------------------------------------------------------
187-
|
188-
*/
189-
190-
'add_ons' => [
191-
192-
'swagger' => false, // generate swagger for your APIs
193-
194-
'tests' => false, // generate test cases for your APIs
195-
],
196-
197187
/*
198188
|--------------------------------------------------------------------------
199189
| Timestamp Fields

src/Commands/BaseCommand.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function generateCommonItems()
7272
$repositoryGenerator->generate();
7373
}
7474

75-
if ($this->config->options->factory || (!$this->isSkip('tests') and $this->config->addons->tests)) {
75+
if ($this->config->options->factory || (!$this->isSkip('tests') and $this->config->options->tests)) {
7676
$factoryGenerator = app(FactoryGenerator::class);
7777
$factoryGenerator->generate();
7878
}
@@ -100,7 +100,7 @@ public function generateAPIItems()
100100
$routesGenerator->generate();
101101
}
102102

103-
if (!$this->isSkip('tests') and $this->config->addons->tests) {
103+
if (!$this->isSkip('tests') and $this->config->options->tests) {
104104
if ($this->config->options->repositoryPattern) {
105105
$repositoryTestGenerator = app(RepositoryTestGenerator::class);
106106
$repositoryTestGenerator->generate();
@@ -109,6 +109,7 @@ public function generateAPIItems()
109109
$apiTestGenerator = app(APITestGenerator::class);
110110
$apiTestGenerator->generate();
111111
}
112+
112113
if ($this->config->options->resources) {
113114
$apiResourceGenerator = app(APIResourceGenerator::class);
114115
$apiResourceGenerator->generate();
@@ -156,7 +157,7 @@ public function performPostActions($runMigration = false)
156157
$requestFromConsole = (php_sapi_name() == 'cli');
157158
if ($this->option('jsonFromGUI') && $requestFromConsole) {
158159
$this->runMigration();
159-
} elseif ($requestFromConsole && $this->confirm(PHP_EOL.'Do you want to migrate database? [y|N]', false)) {
160+
} elseif ($requestFromConsole && $this->confirm(infy_nl().'Do you want to migrate database? [y|N]', false)) {
160161
$this->runMigration();
161162
}
162163
}
@@ -252,7 +253,7 @@ private function saveLocaleFile()
252253
if (file_exists($path.$fileName) && !$this->confirmOverwrite($fileName)) {
253254
return;
254255
}
255-
$content = "<?php\n\nreturn ".var_export($locales, true).';'.PHP_EOL;
256+
$content = "<?php\n\nreturn ".var_export($locales, true).';'.infy_nl();
256257
g_filesystem()->createFile($path.$fileName, $content);
257258
$this->comment("\nModel Locale File saved: ");
258259
$this->info($fileName);

src/Commands/Publish/GeneratorPublishCommand.php

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,6 @@ public function handle()
3434
}
3535
}
3636

37-
private function fillTemplate(string $templateData): string
38-
{
39-
$apiPrefix = config('laravel_generator.api_prefix', 'api');
40-
41-
$templateData = str_replace('$API_PREFIX$', $apiPrefix, $templateData);
42-
$appNamespace = $this->getLaravel()->getNamespace();
43-
$appNamespace = substr($appNamespace, 0, strlen($appNamespace) - 1);
44-
45-
return str_replace('$NAMESPACE_APP$', $appNamespace, $templateData);
46-
}
47-
4837
private function updateRouteServiceProvider()
4938
{
5039
$routeServiceProviderPath = app_path('Providers'.DIRECTORY_SEPARATOR.'RouteServiceProvider.php');
@@ -57,11 +46,11 @@ private function updateRouteServiceProvider()
5746

5847
$fileContent = g_filesystem()->getFile($routeServiceProviderPath);
5948

60-
$search = "Route::middleware('api')".PHP_EOL.str(' ')->repeat(16)."->prefix('api')";
49+
$search = "Route::middleware('api')".infy_nl().str(' ')->repeat(16)."->prefix('api')";
6150
$beforeContent = str($fileContent)->before($search);
6251
$afterContent = str($fileContent)->after($search);
6352

64-
$finalContent = $beforeContent.$search.PHP_EOL.str(' ')->repeat(16)."->as('api.')".$afterContent;
53+
$finalContent = $beforeContent.$search.infy_nl().str(' ')->repeat(16)."->as('api.')".$afterContent;
6554
g_filesystem()->createFile($routeServiceProviderPath, $finalContent);
6655
}
6756

@@ -72,10 +61,10 @@ private function publishTestCases()
7261
$createdAtField = config('laravel_generator.timestamps.created_at', 'created_at');
7362
$updatedAtField = config('laravel_generator.timestamps.updated_at', 'updated_at');
7463

75-
$templateData = get_template('test.api_test_trait', 'laravel-generator');
76-
77-
$templateData = str_replace('$NAMESPACE_TESTS$', $testsNameSpace, $templateData);
78-
$templateData = str_replace('$TIMESTAMPS$', "['$createdAtField', '$updatedAtField']", $templateData);
64+
$templateData = view('laravel-generator::api.test.api_test_trait', [
65+
'timestamps' => "['$createdAtField', '$updatedAtField']",
66+
'namespacesTests' => $testsNameSpace,
67+
])->render();
7968

8069
$fileName = 'ApiTestTrait.php';
8170

@@ -101,39 +90,39 @@ private function publishTestCases()
10190

10291
private function publishBaseController()
10392
{
104-
$templateData = get_template('app_base_controller', 'laravel-generator');
105-
106-
$templateData = $this->fillTemplate($templateData);
107-
10893
$controllerPath = app_path('Http/Controllers/');
109-
11094
$fileName = 'AppBaseController.php';
11195

11296
if (file_exists($controllerPath.$fileName) && !$this->confirmOverwrite($fileName)) {
11397
return;
11498
}
11599

100+
$templateData = view('laravel-generator::stubs.app_base_controller', [
101+
'namespaceApp' => $this->getLaravel()->getNamespace(),
102+
'apiPrefix' => config('laravel_generator.api_prefix'),
103+
])->render();
104+
116105
g_filesystem()->createFile($controllerPath.$fileName, $templateData);
117106

118107
$this->info('AppBaseController created');
119108
}
120109

121110
private function publishBaseRepository()
122111
{
123-
$templateData = get_template('base_repository', 'laravel-generator');
124-
125-
$templateData = $this->fillTemplate($templateData);
126-
127112
$repositoryPath = app_path('Repositories/');
128113

129-
g_filesystem()->createDirectoryIfNotExist($repositoryPath);
130-
131114
$fileName = 'BaseRepository.php';
132115

133116
if (file_exists($repositoryPath.$fileName) && !$this->confirmOverwrite($fileName)) {
134117
return;
135118
}
136119

120+
g_filesystem()->createDirectoryIfNotExist($repositoryPath);
121+
122+
$templateData = view('laravel-generator::stubs.base_repository', [
123+
'namespaceApp' => $this->getLaravel()->getNamespace(),
124+
])->render();
125+
137126
g_filesystem()->createFile($repositoryPath.$fileName, $templateData);
138127

139128
$this->info('BaseRepository created');

src/Commands/Publish/PublishBaseCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace InfyOm\Generator\Commands\Publish;
44

5+
use Illuminate\Console\Command;
56
use Illuminate\Support\Facades\File;
6-
use InfyOm\Generator\Commands\BaseCommand;
77

8-
class PublishBaseCommand extends BaseCommand
8+
class PublishBaseCommand extends Command
99
{
1010
public function handle()
1111
{

src/Commands/Publish/PublishTemplatesCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function handle()
3535

3636
public function publishGeneratorTemplates(): bool
3737
{
38-
$templatesPath = __DIR__.'/../../../templates';
38+
$templatesPath = __DIR__.'/../../../views';
3939

4040
return $this->publishDirectory($templatesPath, $this->templatesDir, 'infyom-generator-templates');
4141
}

src/Commands/RollbackGeneratorCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ public function handle()
9494
$menuGenerator->rollback();
9595
}
9696

97-
if ($this->config->addons->tests) {
97+
if ($this->config->options->tests) {
9898
$repositoryTestGenerator = app(RepositoryTestGenerator::class);
9999
$repositoryTestGenerator->rollback();
100100

101101
$apiTestGenerator = app(APITestGenerator::class);
102102
$apiTestGenerator->rollback();
103103
}
104104

105-
if ($this->config->options->factory or $this->config->addons->tests) {
105+
if ($this->config->options->factory or $this->config->options->tests) {
106106
$factoryGenerator = app(FactoryGenerator::class);
107107
$factoryGenerator->rollback();
108108
}

0 commit comments

Comments
 (0)