Browse Source

Added blade view files

tags/0.1.0
Nafies Luthfi 8 years ago
parent
commit
44a8742b05
  1. 23
      src/CrudMake.php
  2. 33
      src/stubs/view-forms.stub
  3. 40
      src/stubs/view-index.stub
  4. 6
      tests/CrudMakeCommandTest.php

23
src/CrudMake.php

@ -4,9 +4,19 @@ namespace Luthfi\CrudGenerator;
use Illuminate\Support\Str;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
class CrudMake extends Command
{
private $files;
public function __construct(Filesystem $files)
{
parent::__construct();
$this->files = $files;
}
/**
* The name and signature of the console command.
*
@ -30,13 +40,26 @@ class CrudMake extends Command
{
$model = $this->argument('name');
$pluralModel = str_plural($model);
$lowerCasePluralModel = strtolower($pluralModel);
$this->callSilent('make:model', ['name' => $model]);
$this->info($model.' model generated.');
$this->callSilent('make:controller', ['name' => $pluralModel.'Controller']);
$this->info($pluralModel.'Controller generated.');
$path = resource_path('views/'.$lowerCasePluralModel);
if (! $this->files->isDirectory($path)) {
$this->files->makeDirectory($path, 0777, true, true);
}
$this->files->put($path.'/index.blade.php', $this->files->get(__DIR__.'/stubs/view-index.stub'));
$this->files->put($path.'/forms.blade.php', $this->files->get(__DIR__.'/stubs/view-forms.stub'));
$this->callSilent('make:test', ['name' => 'Manage'.$pluralModel.'Test']);
$this->info('Manage'.$pluralModel.'Test generated.');
$this->callSilent('make:test', ['name' => 'Models/'.$model.'Test', '--unit' => true]);
$this->info($model.'Test (model) generated.');
$this->info('CRUD files generated successfully!');
}

33
src/stubs/view-forms.stub

@ -0,0 +1,33 @@
@if (Request::get('action') == 'create')
{!! Form::open(['route' => 'masters.store']) !!}
{!! FormField::text('name') !!}
{!! FormField::textarea('description') !!}
{!! Form::submit(trans('master.create'), ['class' => 'btn btn-success']) !!}
{!! Form::hidden('cat', 'master') !!}
{{ link_to_route('masters.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }}
{!! Form::close() !!}
@endif
@if (Request::get('action') == 'edit' && $editableMaster)
{!! Form::model($editableMaster, ['route' => ['masters.update', $editableMaster->id],'method' => 'patch']) !!}
{!! FormField::text('name') !!}
{!! FormField::textarea('description') !!}
{!! Form::submit(trans('master.update'), ['class' => 'btn btn-success']) !!}
{{ link_to_route('masters.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }}
{!! Form::close() !!}
@endif
@if (Request::get('action') == 'delete' && $editableMaster)
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">{{ trans('master.delete') }}</h3></div>
<div class="panel-body">
<label class="control-label">{{ trans('master.name') }}</label>
<p>{{ $editableMaster->name }}</p>
{!! $errors->first('master_id', '<span class="form-error small">:message</span>') !!}
</div>
<hr style="margin:0">
<div class="panel-body">{{ trans('app.delete_confirm') }}</div>
<div class="panel-footer">
{!! FormField::delete(['route'=>['masters.destroy',$editableMaster->id]], trans('app.delete_confirm_button'), ['class'=>'btn btn-danger'], ['master_id' => $editableMaster->id]) !!}
{{ link_to_route('masters.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }}
</div>
</div>
@endif

40
src/stubs/view-index.stub

@ -0,0 +1,40 @@
@extends('layouts.app')
@section('title', trans('master.list'))
@section('content')
{{ link_to_route('masters.index', trans('master.create'), ['action' => 'create'], ['class' => 'btn btn-success pull-right']) }}
<h3 class="page-header">{{ trans('master.list') }}</h3>
<div class="row">
<div class="col-md-8">
<div class="panel panel-default table-responsive">
<table class="table table-condensed">
<thead>
<tr>
<th class="text-center">{{ trans('app.table_no') }}</th>
<th>{{ trans('master.name') }}</th>
<th>{{ trans('master.description') }}</th>
<th class="text-center">{{ trans('app.action') }}</th>
</tr>
</thead>
<tbody>
@foreach($masters as $key => $master)
<tr>
<td class="text-center">{{ 1 + $key }}</td>
<td>{{ $master->name }}</td>
<td>{{ $master->description }}</td>
<td class="text-center">
{!! link_to_route('masters.index', trans('app.edit'), ['action' => 'edit', 'id' => $master->id], ['id' => 'edit-master-' . $master->id]) !!} |
{!! link_to_route('masters.index', trans('app.delete'), ['action' => 'delete', 'id' => $master->id], ['id' => 'del-master-' . $master->id]) !!}
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
<div class="col-md-4">
@includeWhen(Request::has('action'), 'masters.forms')
</div>
</div>
@endsection

6
tests/CrudMakeCommandTest.php

@ -16,14 +16,14 @@ class CrudMakeCommandTest extends TestCase
$this->assertFileExists(app_path('Test.php'));
$this->assertFileExists(app_path('Http/Controllers/TestsController.php'));
// $this->assertFileExists(resource_path('views/tests/index.blade.php'));
// $this->assertFileExists(resource_path('views/tests/forms.blade.php'));
$this->assertFileExists(resource_path('views/tests/index.blade.php'));
$this->assertFileExists(resource_path('views/tests/forms.blade.php'));
$this->assertFileExists(base_path('tests/Feature/ManageTestsTest.php'));
$this->assertFileExists(base_path('tests/Unit/Models/TestTest.php'));
exec('rm '.app_path('Test.php'));
exec('rm -r '.app_path('Http'));
// exec('rm -r '.resource_path('views/tests'));
exec('rm -r '.resource_path('views/tests'));
exec('rm -r '.base_path('tests/Feature'));
exec('rm -r '.base_path('tests/Unit'));
}

Loading…
Cancel
Save