Browse Source

Add default lang app.php file if it not exists

tags/0.1.0
Nafies Luthfi 8 years ago
parent
commit
cd5531fd4f
  1. 32
      src/CrudMake.php
  2. 19
      src/stubs/lang-app.stub
  3. 30
      tests/Generators/LangGeneratorTest.php
  4. 1
      tests/TestCase.php

32
src/CrudMake.php

@ -179,12 +179,37 @@ class CrudMake extends Command
{ {
$langPath = $this->makeDirectory(resource_path('lang/en')); $langPath = $this->makeDirectory(resource_path('lang/en'));
$this->createAppLangFile($langPath);
$this->generateFile($langPath.'/'.$this->modelNames['lang_name'].'.php', $this->getLangFileContent()); $this->generateFile($langPath.'/'.$this->modelNames['lang_name'].'.php', $this->getLangFileContent());
$this->info($this->modelNames['lang_name'].' lang files generated.'); $this->info($this->modelNames['lang_name'].' lang files generated.');
} }
/** /**
* Generate lang/app.php file if it doesn't exists
*
* @param string $langPath Directory path of lang files
* @return void
*/
public function createAppLangFile($langPath)
{
if (! $this->files->exists($langPath.'/app.php')) {
$this->generateFile($langPath.'/app.php', $this->getAppLangFileContent());
$this->info('lang/app.php generated.');
}
}
/**
* Get lang/app.php file content
*
* @return string
*/
public function getAppLangFileContent()
{
return $this->files->get(__DIR__.'/stubs/lang-app.stub');
}
/**
* Generate model factory file * Generate model factory file
* *
* @return void * @return void
@ -232,14 +257,15 @@ class CrudMake extends Command
if (! $this->files->exists($testsPath.'/BrowserKitTest.php')) { if (! $this->files->exists($testsPath.'/BrowserKitTest.php')) {
$this->generateFile($testsPath.'/BrowserKitTest.php', $this->getBrowserKitBaseTestContent()); $this->generateFile($testsPath.'/BrowserKitTest.php', $this->getBrowserKitBaseTestContent());
}
$this->info('BrowserKitTest generated.');
$this->info('BrowserKitTest generated.');
}
} }
/** /**
* Generate API resource version route for CRUD Operation * Generate API resource version route for CRUD Operation
* @return [type] [description]
*
* @return void
*/ */
public function generateResourceRoute() public function generateResourceRoute()
{ {

19
src/stubs/lang-app.stub

@ -0,0 +1,19 @@
<?php
return [
// Labels
'table_no' => '#',
'total' => 'Total',
'action' => 'Actions',
'views' => 'Views',
'downloads' => 'Downloads',
// Actions
'show' => 'View Detail',
'edit' => 'Edit',
'delete' => 'Delete',
'cancel' => 'Cancel',
'reset' => 'Reset',
'delete_confirm' => 'Are you sure to delete this?',
'delete_confirm_button' => 'YES, delete it!',
];

30
tests/Generators/LangGeneratorTest.php

@ -44,4 +44,34 @@ return [
"; ";
$this->assertEquals($langFileContent, file_get_contents($langPath)); $this->assertEquals($langFileContent, file_get_contents($langPath));
} }
/** @test */
public function it_creates_app_lang_if_it_doesnt_exists()
{
$this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]);
$langPath = resource_path('lang/en/app.php');
$this->assertFileExists($langPath);
$appLangContent = "<?php
return [
// Labels
'table_no' => '#',
'total' => 'Total',
'action' => 'Actions',
'views' => 'Views',
'downloads' => 'Downloads',
// Actions
'show' => 'View Detail',
'edit' => 'Edit',
'delete' => 'Delete',
'cancel' => 'Cancel',
'reset' => 'Reset',
'delete_confirm' => 'Are you sure to delete this?',
'delete_confirm_button' => 'YES, delete it!',
];
";
$this->assertEquals($appLangContent, file_get_contents($langPath));
}
} }

1
tests/TestCase.php

@ -39,6 +39,7 @@ abstract class TestCase extends BaseTestCase
$this->removeFileOrDir(database_path('migrations')); $this->removeFileOrDir(database_path('migrations'));
$this->removeFileOrDir(database_path('factories')); $this->removeFileOrDir(database_path('factories'));
$this->removeFileOrDir(resource_path('views/'.$this->table_name)); $this->removeFileOrDir(resource_path('views/'.$this->table_name));
$this->removeFileOrDir(resource_path("lang/en/app.php"));
$this->removeFileOrDir(resource_path("lang/en/{$this->lang_name}.php")); $this->removeFileOrDir(resource_path("lang/en/{$this->lang_name}.php"));
$this->removeFileOrDir(base_path('routes')); $this->removeFileOrDir(base_path('routes'));
$this->removeFileOrDir(base_path('tests/BrowserKitTest.php')); $this->removeFileOrDir(base_path('tests/BrowserKitTest.php'));

Loading…
Cancel
Save