diff --git a/src/CrudMake.php b/src/CrudMake.php index d0900df..1343816 100644 --- a/src/CrudMake.php +++ b/src/CrudMake.php @@ -12,6 +12,7 @@ class CrudMake extends Command private $modelName; private $pluralModelName; private $lowerCasePluralModel; + private $singleModelName; public function __construct(Filesystem $files) { @@ -47,6 +48,7 @@ class CrudMake extends Command $this->generateMigration(); $this->generateController(); $this->generateViews(); + $this->generateLangFile(); $this->generateTests(); $this->info('CRUD files generated successfully!'); @@ -58,6 +60,7 @@ class CrudMake extends Command $this->pluralModelName = str_plural($this->modelName); $this->lowerCasePluralModel = strtolower($this->pluralModelName); + $this->singleModelName = strtolower($this->modelName); } public function generateModel() @@ -97,6 +100,15 @@ class CrudMake extends Command $this->info($this->modelName.' view files generated.'); } + public function generateLangFile() + { + $langPath = $this->makeDirectory(resource_path('lang/en')); + + $this->files->put($langPath.'/'.$this->singleModelName.'.php', $this->getLangFileContent()); + + $this->info($this->singleModelName.' lang files generated.'); + } + public function generateTests() { $featureTestPath = $this->makeDirectory(base_path('tests/Feature')); @@ -132,6 +144,12 @@ class CrudMake extends Command return $this->replaceViewDummyStrings($stub)->replaceClass($stub); } + public function getLangFileContent() + { + $stub = $this->files->get(__DIR__.'/stubs/lang.stub'); + return $this->replaceViewDummyStrings($stub)->replaceClass($stub); + } + public function getFeatureTestContent() { $stub = $this->files->get(__DIR__.'/stubs/test.stub'); @@ -157,7 +175,7 @@ class CrudMake extends Command { $stub = str_replace( ['master', 'Master'], - [strtolower($this->modelName), $this->modelName], + [$this->singleModelName, $this->modelName], $stub ); @@ -201,7 +219,7 @@ class CrudMake extends Command { $stub = str_replace( ['Master', 'master', 'masters'], - [$this->modelName, strtolower($this->modelName), $this->lowerCasePluralModel], + [$this->modelName, $this->singleModelName, $this->lowerCasePluralModel], $stub ); diff --git a/src/stubs/lang.stub b/src/stubs/lang.stub new file mode 100644 index 0000000..d869952 --- /dev/null +++ b/src/stubs/lang.stub @@ -0,0 +1,27 @@ + 'Master', + 'list' => 'Master List', + 'search' => 'Search Master', + 'not_found' => 'Master not found.', + 'empty' => 'Master is empty.', + 'back_to_show' => 'Back to Master Detail', + 'back_to_index' => 'Back to Master List', + + // Actions + 'create' => 'Create new Master', + 'created' => 'Create new Master succeded.', + 'edit' => 'Edit Master', + 'update' => 'Update Master', + 'updated' => 'Update Master succeded.', + 'delete' => 'Delete Master', + 'delete_confirm' => 'Are you sure to delete this Master?', + 'deleted' => 'Delete Master succeded.', + 'undeleted' => 'Master not deleted.', + + // Attributes + 'name' => 'Master Name', + 'description' => 'Master Description', +]; diff --git a/tests/CrudMakeCommandTest.php b/tests/CrudMakeCommandTest.php index 749f5d4..a645c31 100644 --- a/tests/CrudMakeCommandTest.php +++ b/tests/CrudMakeCommandTest.php @@ -17,6 +17,7 @@ class CrudMakeCommandTest extends TestCase $this->assertFileExists(resource_path("views/{$this->tableName}/index.blade.php")); $this->assertFileExists(resource_path("views/{$this->tableName}/forms.blade.php")); + $this->assertFileExists(resource_path("lang/en/{$this->singleModelName}.php")); $this->assertFileExists(base_path("tests/Feature/Manage{$this->pluralModelName}Test.php")); $this->assertFileExists(base_path("tests/Unit/Models/{$this->modelName}Test.php")); } diff --git a/tests/Generators/LangGeneratorTest.php b/tests/Generators/LangGeneratorTest.php new file mode 100644 index 0000000..9042a5f --- /dev/null +++ b/tests/Generators/LangGeneratorTest.php @@ -0,0 +1,46 @@ +artisan('make:crud', ['name' => $this->modelName, '--no-interaction' => true]); + + $langPath = resource_path('lang/en/'.$this->singleModelName.'.php'); + $this->assertFileExists($langPath); + $langFileContent = " 'Item', + 'list' => 'Item List', + 'search' => 'Search Item', + 'not_found' => 'Item not found.', + 'empty' => 'Item is empty.', + 'back_to_show' => 'Back to Item Detail', + 'back_to_index' => 'Back to Item List', + + // Actions + 'create' => 'Create new Item', + 'created' => 'Create new Item succeded.', + 'edit' => 'Edit Item', + 'update' => 'Update Item', + 'updated' => 'Update Item succeded.', + 'delete' => 'Delete Item', + 'delete_confirm' => 'Are you sure to delete this Item?', + 'deleted' => 'Delete Item succeded.', + 'undeleted' => 'Item not deleted.', + + // Attributes + 'title' => 'Item Title', + 'body' => 'Item Content', +]; +"; + $this->assertEquals($langFileContent, file_get_contents($langPath)); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 2db688b..74f31c3 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -9,6 +9,7 @@ abstract class TestCase extends BaseTestCase protected $modelName; protected $pluralModelName; protected $tableName; + protected $singleModelName; public function setUp() { @@ -17,6 +18,7 @@ abstract class TestCase extends BaseTestCase $this->pluralModelName = str_plural($this->modelName); $this->tableName = strtolower($this->pluralModelName); + $this->singleModelName = strtolower($this->modelName); } public function tearDown()