Browse Source

Generate lang file within locale config

tags/0.1.1^0 0.1.1
Nafies Luthfi 8 years ago
parent
commit
b9a6cc6811
  1. 6
      src/CrudMake.php
  2. 9
      src/Generators/LangFileGenerator.php
  3. 10
      src/config.php
  4. 25
      tests/CrudMakeCommandTest.php
  5. 7
      tests/Generators/LangGeneratorTest.php
  6. 25
      tests/TestCase.php

6
src/CrudMake.php

@ -86,7 +86,7 @@ class CrudMake extends Command
{
$this->getModelName();
if (! $this->modelExists()) {
if ( ! $this->modelExists()) {
app(WebRouteGenerator::class, ['command' => $this])->generate();
app(ModelGenerator::class, ['command' => $this])->generate();
app(MigrationGenerator::class, ['command' => $this])->generate();
@ -165,6 +165,8 @@ class CrudMake extends Command
*/
public function modelExists()
{
return $this->files->exists(app_path($this->modelNames['model_path'].'/'.$this->modelNames['model_name'].'.php'));
return $this->files->exists(
app_path($this->modelNames['model_path'].'/'.$this->modelNames['model_name'].'.php')
);
}
}

9
src/Generators/LangFileGenerator.php

@ -3,8 +3,8 @@
namespace Luthfi\CrudGenerator\Generators;
/**
* Lang File Generator Class
*/
* Lang File Generator Class
*/
class LangFileGenerator extends BaseGenerator
{
/**
@ -12,7 +12,8 @@ class LangFileGenerator extends BaseGenerator
*/
public function generate()
{
$langPath = $this->makeDirectory(resource_path('lang/en'));
$locale = config('app.locale');
$langPath = $this->makeDirectory(resource_path('lang/'.$locale));
$this->createAppLangFile($langPath);
$this->generateFile($langPath.'/'.$this->modelNames['lang_name'].'.php', $this->getContent());
@ -46,7 +47,7 @@ class LangFileGenerator extends BaseGenerator
*/
private function createAppLangFile($langPath)
{
if (! $this->files->exists($langPath.'/app.php')) {
if ( ! $this->files->exists($langPath.'/app.php')) {
$this->generateFile($langPath.'/app.php', $this->getAppLangFileContent());
$this->command->info('lang/app.php generated.');
}

10
src/config.php

@ -9,7 +9,7 @@ return [
|
| Default Laravel view layout
|
*/
*/
'default_layout_view' => 'layouts.app',
@ -20,9 +20,9 @@ return [
|
| Base TestCase Path on Laravel application
|
*/
*/
'base_test_path' => 'tests/BrowserKitTest.php',
'base_test_path' => 'tests/BrowserKitTest.php',
/*
|--------------------------------------------------------------------------
@ -32,8 +32,8 @@ return [
| Base Test Class that used on Laravel application
| according to 'base_test_path' config above
|
*/
*/
'base_test_class' => 'Tests\BrowserKitTest',
'base_test_class' => 'Tests\BrowserKitTest',
];

25
tests/CrudMakeCommandTest.php

@ -21,7 +21,10 @@ class CrudMakeCommandTest extends TestCase
$this->assertFileExists(resource_path("views/{$this->table_name}/index.blade.php"));
$this->assertFileExists(resource_path("views/{$this->table_name}/forms.blade.php"));
$this->assertFileExists(resource_path("lang/en/{$this->lang_name}.php"));
$localeConfig = config('app.locale');
$this->assertFileExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
$this->assertFileExists(database_path("factories/{$this->model_name}Factory.php"));
$this->assertFileExists(base_path("routes/web.php"));
$this->assertFileExists(app_path("Policies/{$this->model_name}Policy.php"));
@ -45,7 +48,10 @@ class CrudMakeCommandTest extends TestCase
$this->assertFileNotExists(resource_path("views/{$this->table_name}/index.blade.php"));
$this->assertFileNotExists(resource_path("views/{$this->table_name}/forms.blade.php"));
$this->assertFileNotExists(resource_path("lang/en/{$this->lang_name}.php"));
$localeConfig = config('app.locale');
$this->assertFileNotExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
$this->assertFileNotExists(database_path("factories/{$this->model_name}Factory.php"));
$this->assertFileNotExists(base_path("routes/web.php"));
$this->assertFileNotExists(app_path("Policies/{$this->model_name}Policy.php"));
@ -69,7 +75,10 @@ class CrudMakeCommandTest extends TestCase
$this->assertFileNotExists(resource_path("views/problems/index.blade.php"));
$this->assertFileNotExists(resource_path("views/problems/forms.blade.php"));
$this->assertFileNotExists(resource_path("lang/en/problem.php"));
$localeConfig = config('app.locale');
$this->assertFileNotExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
$this->assertFileNotExists(database_path("factories/ProblemFactory.php"));
$this->assertFileNotExists(app_path("Policies/ProblemPolicy.php"));
$this->assertFileNotExists(base_path("tests/Feature/ManageProblemsTest.php"));
@ -102,7 +111,10 @@ class CrudMakeCommandTest extends TestCase
$this->assertFileExists(resource_path("views/{$tableName}/index.blade.php"));
$this->assertFileExists(resource_path("views/{$tableName}/forms.blade.php"));
$this->assertFileExists(resource_path("lang/en/{$langName}.php"));
$localeConfig = config('app.locale');
$this->assertFileExists(resource_path("lang/{$localeConfig}/{$langName}.php"));
$this->assertFileExists(database_path("factories/{$modelName}Factory.php"));
$this->assertFileExists(app_path("Policies/{$modelName}Policy.php"));
$this->assertFileExists(base_path("tests/Feature/Manage{$pluralModelName}Test.php"));
@ -132,7 +144,10 @@ class CrudMakeCommandTest extends TestCase
$this->assertFileExists(resource_path("views/{$tableName}/index.blade.php"));
$this->assertFileExists(resource_path("views/{$tableName}/forms.blade.php"));
$this->assertFileExists(resource_path("lang/en/{$langName}.php"));
$localeConfig = config('app.locale');
$this->assertFileExists(resource_path("lang/{$localeConfig}/{$langName}.php"));
$this->assertFileExists(database_path("factories/{$modelName}Factory.php"));
$this->assertFileExists(app_path("Policies/{$parentName}/{$modelName}Policy.php"));
$this->assertFileExists(base_path("tests/Feature/Manage{$pluralModelName}Test.php"));

7
tests/Generators/LangGeneratorTest.php

@ -11,7 +11,8 @@ class LangGeneratorTest extends TestCase
{
$this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]);
$langPath = resource_path('lang/en/'.$this->lang_name.'.php');
$locale = config('app.locale');
$langPath = resource_path('lang/'.$locale.'/'.$this->lang_name.'.php');
$displayModelName = ucwords(str_replace('_', ' ', snake_case($this->model_name)));
$this->assertFileExists($langPath);
$langFileContent = "<?php
@ -50,7 +51,9 @@ return [
{
$this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]);
$langPath = resource_path('lang/en/app.php');
$locale = config('app.locale');
$langPath = resource_path('lang/'.$locale.'/app.php');
$this->assertFileExists($langPath);
$appLangContent = "<?php

25
tests/TestCase.php

@ -19,12 +19,12 @@ abstract class TestCase extends BaseTestCase
parent::setUp();
$this->model_name = class_basename('References/Category');
$this->full_model_name = 'App\\' . $this->model_name;
$this->plural_model_name = str_plural($this->model_name);
$this->table_name = snake_case($this->plural_model_name);
$this->lang_name = snake_case($this->model_name);
$this->full_model_name = 'App\\'.$this->model_name;
$this->plural_model_name = str_plural($this->model_name);
$this->table_name = snake_case($this->plural_model_name);
$this->lang_name = snake_case($this->model_name);
$this->collection_model_var_name = camel_case($this->plural_model_name);
$this->single_model_var_name = camel_case($this->model_name);
$this->single_model_var_name = camel_case($this->model_name);
}
public function tearDown()
@ -36,14 +36,17 @@ abstract class TestCase extends BaseTestCase
protected function cleanUpGeneratedFiles()
{
$this->removeFileOrDir(app_path($this->model_name . '.php'));
$this->removeFileOrDir(app_path($this->model_name.'.php'));
$this->removeFileOrDir(app_path('Entities'));
$this->removeFileOrDir(app_path('Http'));
$this->removeFileOrDir(database_path('migrations'));
$this->removeFileOrDir(database_path('factories'));
$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('views/'.$this->table_name));
$locale = config('app.locale');
$this->removeFileOrDir(resource_path("lang/{$locale}/app.php"));
$this->removeFileOrDir(resource_path("lang/{$locale}/{$this->lang_name}.php"));
$this->removeFileOrDir(base_path('routes'));
$this->removeFileOrDir(app_path('Policies'));
$this->removeFileOrDir(app_path('Providers'));
@ -53,11 +56,11 @@ abstract class TestCase extends BaseTestCase
protected function removeFileOrDir($path)
{
if (file_exists($path) && is_file($path)) {
exec('rm ' . $path);
exec('rm '.$path);
}
if (file_exists($path) && is_dir($path)) {
exec('rm -r ' . $path);
exec('rm -r '.$path);
}
}

Loading…
Cancel
Save