Browse Source

Set proper display name for two-words model name

tags/0.1.0
Nafies Luthfi 8 years ago
parent
commit
e6ce09262a
  1. 16
      src/CrudMake.php
  2. 2
      tests/CrudMakeCommandTest.php
  3. 37
      tests/Generators/LangGeneratorTest.php

16
src/CrudMake.php

@ -2,7 +2,6 @@
namespace Luthfi\CrudGenerator;
use Illuminate\Support\Str;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
@ -75,10 +74,10 @@ class CrudMake extends Command
$this->generateTests();
$this->info('CRUD files generated successfully!');
}
} else {
$this->error("{$this->modelNames['model_name']} model already exists.");
}
}
/**
* Generate class properties for model names in different usage
@ -313,7 +312,16 @@ class CrudMake extends Command
public function getLangFileContent()
{
$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;
}
/**

2
tests/CrudMakeCommandTest.php

@ -37,6 +37,8 @@ class CrudMakeCommandTest extends TestCase
{
$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("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]);
$langPath = resource_path('lang/en/'.$this->lang_name.'.php');
$displayModelName = ucwords(str_replace('_', ' ', snake_case($this->model_name)));
$this->assertFileExists($langPath);
$langFileContent = "<?php
return [
// 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
'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
'name' => '{$this->model_name} Name',
'description' => '{$this->model_name} Description',
'name' => '{$displayModelName} Name',
'description' => '{$displayModelName} Description',
];
";
$this->assertEquals($langFileContent, file_get_contents($langPath));

Loading…
Cancel
Save