Browse Source

Set proper display name for two-words model name

tags/0.1.0
Nafies Luthfi 8 years ago
parent
commit
e6ce09262a
  1. 20
      src/CrudMake.php
  2. 2
      src/stubs/lang.stub
  3. 2
      tests/CrudMakeCommandTest.php
  4. 37
      tests/Generators/LangGeneratorTest.php

20
src/CrudMake.php

@ -2,7 +2,6 @@
namespace Luthfi\CrudGenerator; namespace Luthfi\CrudGenerator;
use Illuminate\Support\Str;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem; use Illuminate\Filesystem\Filesystem;
@ -63,7 +62,7 @@ class CrudMake extends Command
{ {
$this->getModelName(); $this->getModelName();
if ( ! $this->modelExists()) {
if (! $this->modelExists()) {
$this->generateResourceRoute(); $this->generateResourceRoute();
$this->generateModel(); $this->generateModel();
@ -75,9 +74,9 @@ class CrudMake extends Command
$this->generateTests(); $this->generateTests();
$this->info('CRUD files generated successfully!'); $this->info('CRUD files generated successfully!');
} else {
$this->error("{$this->modelNames['model_name']} model already exists.");
} }
$this->error("{$this->modelNames['model_name']} model already exists.");
} }
/** /**
@ -313,7 +312,16 @@ class CrudMake extends Command
public function getLangFileContent() public function getLangFileContent()
{ {
$stub = $this->files->get(__DIR__.'/stubs/lang.stub'); $stub = $this->files->get(__DIR__.'/stubs/lang.stub');
return $this->replaceStubString($stub);
$displayModelName = ucwords(str_replace('_', ' ', snake_case($this->modelNames['model_name'])));
$properLangFileContent = str_replace(
$this->modelNames['model_name'],
$displayModelName,
$this->replaceStubString($stub)
);
return $properLangFileContent;
} }
/** /**
@ -411,7 +419,7 @@ class CrudMake extends Command
*/ */
protected function replaceStubString($stub) protected function replaceStubString($stub)
{ {
return str_replace($this->stubModelNames, $this->modelNames, $stub );
return str_replace($this->stubModelNames, $this->modelNames, $stub);
} }
/** /**

2
src/stubs/lang.stub

@ -2,7 +2,7 @@
return [ return [
// Labels // Labels
'master' => 'Master',
'master' => 'Master',
'list' => 'Master List', 'list' => 'Master List',
'search' => 'Search Master', 'search' => 'Search Master',
'not_found' => 'Master not found.', 'not_found' => 'Master not found.',

2
tests/CrudMakeCommandTest.php

@ -37,6 +37,8 @@ class CrudMakeCommandTest extends TestCase
{ {
$this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]); $this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]);
$this->assertNotRegExp("/{$this->model_name} model already exists./", app(Kernel::class)->output());
$this->assertFileExists(app_path($this->model_name.'.php')); $this->assertFileExists(app_path($this->model_name.'.php'));
$this->assertFileExists(app_path("Http/Controllers/{$this->plural_model_name}Controller.php")); $this->assertFileExists(app_path("Http/Controllers/{$this->plural_model_name}Controller.php"));

37
tests/Generators/LangGeneratorTest.php

@ -12,33 +12,34 @@ class LangGeneratorTest extends TestCase
$this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]); $this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]);
$langPath = resource_path('lang/en/'.$this->lang_name.'.php'); $langPath = resource_path('lang/en/'.$this->lang_name.'.php');
$displayModelName = ucwords(str_replace('_', ' ', snake_case($this->model_name)));
$this->assertFileExists($langPath); $this->assertFileExists($langPath);
$langFileContent = "<?php $langFileContent = "<?php
return [ return [
// Labels // Labels
'{$this->lang_name}' => '{$this->model_name}',
'list' => '{$this->model_name} List',
'search' => 'Search {$this->model_name}',
'not_found' => '{$this->model_name} not found.',
'empty' => '{$this->model_name} is empty.',
'back_to_show' => 'Back to {$this->model_name} Detail',
'back_to_index' => 'Back to {$this->model_name} List',
'{$this->lang_name}' => '{$displayModelName}',
'list' => '{$displayModelName} List',
'search' => 'Search {$displayModelName}',
'not_found' => '{$displayModelName} not found.',
'empty' => '{$displayModelName} is empty.',
'back_to_show' => 'Back to {$displayModelName} Detail',
'back_to_index' => 'Back to {$displayModelName} List',
// Actions // Actions
'create' => 'Create new {$this->model_name}',
'created' => 'Create new {$this->model_name} succeded.',
'edit' => 'Edit {$this->model_name}',
'update' => 'Update {$this->model_name}',
'updated' => 'Update {$this->model_name} succeded.',
'delete' => 'Delete {$this->model_name}',
'delete_confirm' => 'Are you sure to delete this {$this->model_name}?',
'deleted' => 'Delete {$this->model_name} succeded.',
'undeleted' => '{$this->model_name} not deleted.',
'create' => 'Create new {$displayModelName}',
'created' => 'Create new {$displayModelName} succeded.',
'edit' => 'Edit {$displayModelName}',
'update' => 'Update {$displayModelName}',
'updated' => 'Update {$displayModelName} succeded.',
'delete' => 'Delete {$displayModelName}',
'delete_confirm' => 'Are you sure to delete this {$displayModelName}?',
'deleted' => 'Delete {$displayModelName} succeded.',
'undeleted' => '{$displayModelName} not deleted.',
// Attributes // Attributes
'name' => '{$this->model_name} Name',
'description' => '{$this->model_name} Description',
'name' => '{$displayModelName} Name',
'description' => '{$displayModelName} Description',
]; ];
"; ";
$this->assertEquals($langFileContent, file_get_contents($langPath)); $this->assertEquals($langFileContent, file_get_contents($langPath));

Loading…
Cancel
Save