Browse Source

Add show and edit view stub for full crud

tags/1.0.0
Nafies Luthfi 8 years ago
parent
commit
c9b3f8eba5
  1. 1
      src/CrudMake.php
  2. 29
      src/Generators/ShowViewGenerator.php
  3. 4
      src/stubs/view-edit.stub
  4. 28
      src/stubs/view-show.stub
  5. 43
      tests/Generators/ViewsGeneratorTest.php

1
src/CrudMake.php

@ -109,5 +109,6 @@ class CrudMake extends GeneratorCommand
app('Luthfi\CrudGenerator\Generators\LangFileGenerator', ['command' => $this])->generate();
app('Luthfi\CrudGenerator\Generators\FormViewGenerator', ['command' => $this])->generate();
app('Luthfi\CrudGenerator\Generators\IndexViewGenerator', ['command' => $this])->generate();
app('Luthfi\CrudGenerator\Generators\ShowViewGenerator', ['command' => $this])->generate();
}
}

29
src/Generators/ShowViewGenerator.php

@ -0,0 +1,29 @@
<?php
namespace Luthfi\CrudGenerator\Generators;
/**
* Show View Generator Class
*/
class ShowViewGenerator extends BaseGenerator
{
/**
* {@inheritDoc}
*/
public function generate(string $type = 'full')
{
$viewPath = $this->makeDirectory(resource_path('views/'.$this->modelNames['table_name']));
$this->generateFile($viewPath.'/show.blade.php', $this->getContent('view-show'));
$this->command->info($this->modelNames['model_name'].' show view file generated.');
}
/**
* {@inheritDoc}
*/
protected function getContent(string $stubName)
{
return $this->replaceStubString($this->getStubFileContent($stubName));
}
}

4
src/stubs/view-edit.stub

@ -7,14 +7,14 @@
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">{{ trans('master.edit') }}</h3></div>
{!! Form::model($editableMaster, ['route' => ['masters.update', $editableMaster->id],'method' => 'patch']) !!}
{!! Form::model($singleMstr, ['route' => ['masters.update', $singleMstr->id],'method' => 'patch']) !!}
<div class="panel-body">
{!! FormField::text('name', ['required' => true, 'label' => trans('master.name')]) !!}
{!! FormField::textarea('description', ['label' => trans('master.description')]) !!}
</div>
<div class="panel-footer">
{!! Form::submit(trans('master.update'), ['class' => 'btn btn-success']) !!}
{{ link_to_route('masters.show', trans('app.cancel'), [$editableMaster], ['class' => 'btn btn-default']) }}
{{ link_to_route('masters.show', trans('app.cancel'), [$singleMstr], ['class' => 'btn btn-default']) }}
</div>
{!! Form::close() !!}
</div>

28
src/stubs/view-show.stub

@ -0,0 +1,28 @@
@extends('layouts.app')
@section('title', trans('master.detail'))
@section('content')
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">{{ trans('master.detail') }}</h3></div>
<table class="table table-condensed">
<tbody>
<tr>
<td>{{ trans('master.name') }}</td>
<td>{{ $singleMstr->name }}</td>
</tr>
<tr>
<td>{{ trans('master.description') }}</td>
<td>{{ $singleMstr->description }}</td>
</tr>
</tbody>
</table>
<div class="panel-footer">
{{ link_to_route('masters.edit', trans('app.edit'), [$singleMstr], ['class' => 'btn btn-default', 'id' => 'edit-master-'.$singleMstr->id]) }}
</div>
</div>
</div>
</div>
@endsection

43
tests/Generators/ViewsGeneratorTest.php

@ -77,6 +77,45 @@ class ViewsGeneratorTest extends TestCase
}
/** @test */
public function it_creates_correct_show_view_content()
{
$this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]);
$showFormViewPath = resource_path("views/{$this->table_name}/show.blade.php");
$this->assertFileExists($showFormViewPath);
$showFormViewContent = "@extends('layouts.app')
@section('title', trans('{$this->lang_name}.detail'))
@section('content')
<div class=\"row\">
<div class=\"col-md-6 col-md-offset-3\">
<div class=\"panel panel-default\">
<div class=\"panel-heading\"><h3 class=\"panel-title\">{{ trans('{$this->lang_name}.detail') }}</h3></div>
<table class=\"table table-condensed\">
<tbody>
<tr>
<td>{{ trans('{$this->lang_name}.name') }}</td>
<td>{{ \${$this->single_model_var_name}->name }}</td>
</tr>
<tr>
<td>{{ trans('{$this->lang_name}.description') }}</td>
<td>{{ \${$this->single_model_var_name}->description }}</td>
</tr>
</tbody>
</table>
<div class=\"panel-footer\">
{{ link_to_route('{$this->table_name}.edit', trans('app.edit'), [\${$this->single_model_var_name}], ['class' => 'btn btn-default', 'id' => 'edit-{$this->lang_name}-'.\${$this->single_model_var_name}->id]) }}
</div>
</div>
</div>
</div>
@endsection
";
$this->assertEquals($showFormViewContent, file_get_contents($showFormViewPath));
}
/** @test */
public function it_creates_correct_create_view_content()
{
$this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]);
@ -126,14 +165,14 @@ class ViewsGeneratorTest extends TestCase
<div class=\"col-md-6 col-md-offset-3\">
<div class=\"panel panel-default\">
<div class=\"panel-heading\"><h3 class=\"panel-title\">{{ trans('{$this->lang_name}.edit') }}</h3></div>
{!! Form::model(\$editable{$this->model_name}, ['route' => ['{$this->table_name}.update', \$editable{$this->model_name}->id],'method' => 'patch']) !!}
{!! Form::model(\${$this->single_model_var_name}, ['route' => ['{$this->table_name}.update', \${$this->single_model_var_name}->id],'method' => 'patch']) !!}
<div class=\"panel-body\">
{!! FormField::text('name', ['required' => true, 'label' => trans('{$this->lang_name}.name')]) !!}
{!! FormField::textarea('description', ['label' => trans('{$this->lang_name}.description')]) !!}
</div>
<div class=\"panel-footer\">
{!! Form::submit(trans('{$this->lang_name}.update'), ['class' => 'btn btn-success']) !!}
{{ link_to_route('{$this->table_name}.show', trans('app.cancel'), [\$editable{$this->model_name}], ['class' => 'btn btn-default']) }}
{{ link_to_route('{$this->table_name}.show', trans('app.cancel'), [\${$this->single_model_var_name}], ['class' => 'btn btn-default']) }}
</div>
{!! Form::close() !!}
</div>

Loading…
Cancel
Save