Skip to content

Commit

Permalink
snake case in views folder
Browse files Browse the repository at this point in the history
- snake case for model views folder
- more human friendly names for model name in views
  • Loading branch information
mitulgolakiya committed Aug 18, 2016
1 parent b3862ad commit d0ee6d0
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 32 deletions.
10 changes: 9 additions & 1 deletion src/Common/GeneratorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class GeneratorConfig
public $mSnakePlural;
public $mDashed;
public $mDashedPlural;
public $mHuman;
public $mHumanPlural;

public $forceMigrate;

Expand Down Expand Up @@ -176,7 +178,7 @@ public function loadPaths()
$this->pathViews = config(
'infyom.laravel_generator.path.views',
base_path('resources/views/')
).$viewPrefix.$this->mCamelPlural.'/';
).$viewPrefix.$this->mSnakePlural.'/';

$this->modelJsPath = config(
'infyom.laravel_generator.path.modelsJs',
Expand Down Expand Up @@ -210,6 +212,8 @@ public function loadDynamicVariables(CommandData &$commandData)
$commandData->addDynamicVariable('$MODEL_NAME_PLURAL_SNAKE$', $this->mSnakePlural);
$commandData->addDynamicVariable('$MODEL_NAME_DASHED$', $this->mDashed);
$commandData->addDynamicVariable('$MODEL_NAME_PLURAL_DASHED$', $this->mDashedPlural);
$commandData->addDynamicVariable('$MODEL_NAME_HUMAN$', $this->mHuman);
$commandData->addDynamicVariable('$MODEL_NAME_PLURAL_HUMAN$', $this->mHumanPlural);

if (!empty($this->prefixes['route'])) {
$commandData->addDynamicVariable('$ROUTE_NAMED_PREFIX$', $this->prefixes['route'].'.');
Expand Down Expand Up @@ -266,6 +270,10 @@ public function prepareModelNames()
$this->mCamelPlural = Str::camel($this->mPlural);
$this->mSnake = Str::snake($this->mName);
$this->mSnakePlural = Str::snake($this->mPlural);
$this->mDashed = str_replace("_", "-", Str::snake($this->mSnake));
$this->mDashedPlural = str_replace("_", "-", Str::snake($this->mSnakePlural));
$this->mHuman = title_case(str_replace("_", " ", Str::snake($this->mSnake)));
$this->mHumanPlural = title_case(str_replace("_", " ", Str::snake($this->mSnakePlural)));
}

public function prepareOptions(CommandData &$commandData)
Expand Down
14 changes: 7 additions & 7 deletions templates/api/controller/api_controller.stub
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class $MODEL_NAME$APIController extends AppBaseController
$this->$MODEL_NAME_CAMEL$Repository->pushCriteria(new LimitOffsetCriteria($request));
$$MODEL_NAME_PLURAL_CAMEL$ = $this->$MODEL_NAME_CAMEL$Repository->all();

return $this->sendResponse($$MODEL_NAME_PLURAL_CAMEL$->toArray(), '$MODEL_NAME_PLURAL$ retrieved successfully');
return $this->sendResponse($$MODEL_NAME_PLURAL_CAMEL$->toArray(), '$MODEL_NAME_PLURAL_HUMAN$ retrieved successfully');
}

$DOC_STORE$
Expand All @@ -40,7 +40,7 @@ class $MODEL_NAME$APIController extends AppBaseController

$$MODEL_NAME_PLURAL_CAMEL$ = $this->$MODEL_NAME_CAMEL$Repository->create($input);

return $this->sendResponse($$MODEL_NAME_PLURAL_CAMEL$->toArray(), '$MODEL_NAME$ saved successfully');
return $this->sendResponse($$MODEL_NAME_PLURAL_CAMEL$->toArray(), '$MODEL_NAME_HUMAN$ saved successfully');
}

$DOC_SHOW$
Expand All @@ -50,10 +50,10 @@ class $MODEL_NAME$APIController extends AppBaseController
$$MODEL_NAME_CAMEL$ = $this->$MODEL_NAME_CAMEL$Repository->find($id);

if (empty($$MODEL_NAME_CAMEL$)) {
return $this->sendError('$MODEL_NAME$ not found');
return $this->sendError('$MODEL_NAME_HUMAN$ not found');
}

return $this->sendResponse($$MODEL_NAME_CAMEL$->toArray(), '$MODEL_NAME$ retrieved successfully');
return $this->sendResponse($$MODEL_NAME_CAMEL$->toArray(), '$MODEL_NAM_HUMANE$ retrieved successfully');
}

$DOC_UPDATE$
Expand All @@ -65,7 +65,7 @@ class $MODEL_NAME$APIController extends AppBaseController
$$MODEL_NAME_CAMEL$ = $this->$MODEL_NAME_CAMEL$Repository->find($id);

if (empty($$MODEL_NAME_CAMEL$)) {
return $this->sendError('$MODEL_NAME$ not found');
return $this->sendError('$MODEL_NAME_HUMAN$ not found');
}

$$MODEL_NAME_CAMEL$ = $this->$MODEL_NAME_CAMEL$Repository->update($input, $id);
Expand All @@ -80,11 +80,11 @@ class $MODEL_NAME$APIController extends AppBaseController
$$MODEL_NAME_CAMEL$ = $this->$MODEL_NAME_CAMEL$Repository->find($id);

if (empty($$MODEL_NAME_CAMEL$)) {
return $this->sendError('$MODEL_NAME$ not found');
return $this->sendError('$MODEL_NAME_HUMAN$ not found');
}

$$MODEL_NAME_CAMEL$->delete();

return $this->sendResponse($id, '$MODEL_NAME$ deleted successfully');
return $this->sendResponse($id, '$MODEL_NAME_HUMAN$ deleted successfully');
}
}
22 changes: 11 additions & 11 deletions templates/scaffold/controller/controller.stub
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class $MODEL_NAME$Controller extends AppBaseController
$this->$MODEL_NAME_CAMEL$Repository->pushCriteria(new RequestCriteria($request));
$$MODEL_NAME_PLURAL_CAMEL$ = $this->$MODEL_NAME_CAMEL$Repository->$RENDER_TYPE$;

return view('$VIEW_PREFIX$$MODEL_NAME_PLURAL_CAMEL$.index')
return view('$VIEW_PREFIX$$MODEL_NAME_PLURAL_SNAKE$.index')
->with('$MODEL_NAME_PLURAL_CAMEL$', $$MODEL_NAME_PLURAL_CAMEL$);
}

Expand All @@ -43,7 +43,7 @@ class $MODEL_NAME$Controller extends AppBaseController
*/
public function create()
{
return view('$VIEW_PREFIX$$MODEL_NAME_PLURAL_CAMEL$.create');
return view('$VIEW_PREFIX$$MODEL_NAME_PLURAL_SNAKE$.create');
}

/**
Expand All @@ -59,7 +59,7 @@ class $MODEL_NAME$Controller extends AppBaseController

$$MODEL_NAME_CAMEL$ = $this->$MODEL_NAME_CAMEL$Repository->create($input);

Flash::success('$MODEL_NAME$ saved successfully.');
Flash::success('$MODEL_NAME_HUMAN$ saved successfully.');

return redirect(route('$ROUTE_NAMED_PREFIX$$MODEL_NAME_PLURAL_CAMEL$.index'));
}
Expand All @@ -76,12 +76,12 @@ class $MODEL_NAME$Controller extends AppBaseController
$$MODEL_NAME_CAMEL$ = $this->$MODEL_NAME_CAMEL$Repository->findWithoutFail($id);

if (empty($$MODEL_NAME_CAMEL$)) {
Flash::error('$MODEL_NAME$ not found');
Flash::error('$MODEL_NAME_HUMAN$ not found');

return redirect(route('$ROUTE_NAMED_PREFIX$$MODEL_NAME_PLURAL_CAMEL$.index'));
}

return view('$VIEW_PREFIX$$MODEL_NAME_PLURAL_CAMEL$.show')->with('$MODEL_NAME_CAMEL$', $$MODEL_NAME_CAMEL$);
return view('$VIEW_PREFIX$$MODEL_NAME_PLURAL_SNAKE$.show')->with('$MODEL_NAME_CAMEL$', $$MODEL_NAME_CAMEL$);
}

/**
Expand All @@ -96,12 +96,12 @@ class $MODEL_NAME$Controller extends AppBaseController
$$MODEL_NAME_CAMEL$ = $this->$MODEL_NAME_CAMEL$Repository->findWithoutFail($id);

if (empty($$MODEL_NAME_CAMEL$)) {
Flash::error('$MODEL_NAME$ not found');
Flash::error('$MODEL_NAME_HUMAN$ not found');

return redirect(route('$ROUTE_NAMED_PREFIX$$MODEL_NAME_PLURAL_CAMEL$.index'));
}

return view('$VIEW_PREFIX$$MODEL_NAME_PLURAL_CAMEL$.edit')->with('$MODEL_NAME_CAMEL$', $$MODEL_NAME_CAMEL$);
return view('$VIEW_PREFIX$$MODEL_NAME_PLURAL_SNAKE$.edit')->with('$MODEL_NAME_CAMEL$', $$MODEL_NAME_CAMEL$);
}

/**
Expand All @@ -117,14 +117,14 @@ class $MODEL_NAME$Controller extends AppBaseController
$$MODEL_NAME_CAMEL$ = $this->$MODEL_NAME_CAMEL$Repository->findWithoutFail($id);

if (empty($$MODEL_NAME_CAMEL$)) {
Flash::error('$MODEL_NAME$ not found');
Flash::error('$MODEL_NAME_HUMAN$ not found');

return redirect(route('$ROUTE_NAMED_PREFIX$$MODEL_NAME_PLURAL_CAMEL$.index'));
}

$$MODEL_NAME_CAMEL$ = $this->$MODEL_NAME_CAMEL$Repository->update($request->all(), $id);

Flash::success('$MODEL_NAME$ updated successfully.');
Flash::success('$MODEL_NAME_HUMAN$ updated successfully.');

return redirect(route('$ROUTE_NAMED_PREFIX$$MODEL_NAME_PLURAL_CAMEL$.index'));
}
Expand All @@ -141,14 +141,14 @@ class $MODEL_NAME$Controller extends AppBaseController
$$MODEL_NAME_CAMEL$ = $this->$MODEL_NAME_CAMEL$Repository->findWithoutFail($id);

if (empty($$MODEL_NAME_CAMEL$)) {
Flash::error('$MODEL_NAME$ not found');
Flash::error('$MODEL_NAME_HUMAN$ not found');

return redirect(route('$ROUTE_NAMED_PREFIX$$MODEL_NAME_PLURAL_CAMEL$.index'));
}

$this->$MODEL_NAME_CAMEL$Repository->delete($id);

Flash::success('$MODEL_NAME$ deleted successfully.');
Flash::success('$MODEL_NAME_HUMAN$ deleted successfully.');

return redirect(route('$ROUTE_NAMED_PREFIX$$MODEL_NAME_PLURAL_CAMEL$.index'));
}
Expand Down
22 changes: 11 additions & 11 deletions templates/scaffold/controller/datatable_controller.stub
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class $MODEL_NAME$Controller extends AppBaseController
*/
public function index($MODEL_NAME$DataTable $$MODEL_NAME_CAMEL$DataTable)
{
return $$MODEL_NAME_CAMEL$DataTable->render('$VIEW_PREFIX$$MODEL_NAME_PLURAL_CAMEL$.index');
return $$MODEL_NAME_CAMEL$DataTable->render('$VIEW_PREFIX$$MODEL_NAME_PLURAL_SNAKE$.index');
}

/**
Expand All @@ -39,7 +39,7 @@ class $MODEL_NAME$Controller extends AppBaseController
*/
public function create()
{
return view('$VIEW_PREFIX$$MODEL_NAME_PLURAL_CAMEL$.create');
return view('$VIEW_PREFIX$$MODEL_NAME_PLURAL_SNAKE$.create');
}

/**
Expand All @@ -55,7 +55,7 @@ class $MODEL_NAME$Controller extends AppBaseController

$$MODEL_NAME_CAMEL$ = $this->$MODEL_NAME_CAMEL$Repository->create($input);

Flash::success('$MODEL_NAME$ saved successfully.');
Flash::success('$MODEL_NAME_HUMAN$ saved successfully.');

return redirect(route('$ROUTE_NAMED_PREFIX$$MODEL_NAME_PLURAL_CAMEL$.index'));
}
Expand All @@ -72,12 +72,12 @@ class $MODEL_NAME$Controller extends AppBaseController
$$MODEL_NAME_CAMEL$ = $this->$MODEL_NAME_CAMEL$Repository->findWithoutFail($id);

if (empty($$MODEL_NAME_CAMEL$)) {
Flash::error('$MODEL_NAME$ not found');
Flash::error('$MODEL_NAME_HUMAN$ not found');

return redirect(route('$ROUTE_NAMED_PREFIX$$MODEL_NAME_PLURAL_CAMEL$.index'));
}

return view('$VIEW_PREFIX$$MODEL_NAME_PLURAL_CAMEL$.show')->with('$MODEL_NAME_CAMEL$', $$MODEL_NAME_CAMEL$);
return view('$VIEW_PREFIX$$MODEL_NAME_PLURAL_SNAKE$.show')->with('$MODEL_NAME_CAMEL$', $$MODEL_NAME_CAMEL$);
}

/**
Expand All @@ -92,12 +92,12 @@ class $MODEL_NAME$Controller extends AppBaseController
$$MODEL_NAME_CAMEL$ = $this->$MODEL_NAME_CAMEL$Repository->findWithoutFail($id);

if (empty($$MODEL_NAME_CAMEL$)) {
Flash::error('$MODEL_NAME$ not found');
Flash::error('$MODEL_NAME_HUMAN$ not found');

return redirect(route('$ROUTE_NAMED_PREFIX$$MODEL_NAME_PLURAL_CAMEL$.index'));
}

return view('$VIEW_PREFIX$$MODEL_NAME_PLURAL_CAMEL$.edit')->with('$MODEL_NAME_CAMEL$', $$MODEL_NAME_CAMEL$);
return view('$VIEW_PREFIX$$MODEL_NAME_PLURAL_SNAKE$.edit')->with('$MODEL_NAME_CAMEL$', $$MODEL_NAME_CAMEL$);
}

/**
Expand All @@ -113,14 +113,14 @@ class $MODEL_NAME$Controller extends AppBaseController
$$MODEL_NAME_CAMEL$ = $this->$MODEL_NAME_CAMEL$Repository->findWithoutFail($id);

if (empty($$MODEL_NAME_CAMEL$)) {
Flash::error('$MODEL_NAME$ not found');
Flash::error('$MODEL_NAME_HUMAN$ not found');

return redirect(route('$ROUTE_NAMED_PREFIX$$MODEL_NAME_PLURAL_CAMEL$.index'));
}

$$MODEL_NAME_CAMEL$ = $this->$MODEL_NAME_CAMEL$Repository->update($request->all(), $id);

Flash::success('$MODEL_NAME$ updated successfully.');
Flash::success('$MODEL_NAME_HUMAN$ updated successfully.');

return redirect(route('$ROUTE_NAMED_PREFIX$$MODEL_NAME_PLURAL_CAMEL$.index'));
}
Expand All @@ -137,14 +137,14 @@ class $MODEL_NAME$Controller extends AppBaseController
$$MODEL_NAME_CAMEL$ = $this->$MODEL_NAME_CAMEL$Repository->findWithoutFail($id);

if (empty($$MODEL_NAME_CAMEL$)) {
Flash::error('$MODEL_NAME$ not found');
Flash::error('$MODEL_NAME_HUMAN$ not found');

return redirect(route('$ROUTE_NAMED_PREFIX$$MODEL_NAME_PLURAL_CAMEL$.index'));
}

$this->$MODEL_NAME_CAMEL$Repository->delete($id);

Flash::success('$MODEL_NAME$ deleted successfully.');
Flash::success('$MODEL_NAME_HUMAN$ deleted successfully.');

return redirect(route('$ROUTE_NAMED_PREFIX$$MODEL_NAME_PLURAL_CAMEL$.index'));
}
Expand Down
3 changes: 1 addition & 2 deletions templates/scaffold/datatable.stub
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class $MODEL_NAME$DataTable extends DataTable
{
return $this->datatables
->eloquent($this->query())
->addColumn('action', '$VIEW_PREFIX$$MODEL_NAME_PLURAL_CAMEL$.datatables_actions')
->addColumn('action', '$VIEW_PREFIX$$MODEL_NAME_PLURAL_SNAKE$.datatables_actions')
->make(true);
}

Expand Down Expand Up @@ -47,7 +47,6 @@ class $MODEL_NAME$DataTable extends DataTable
'dom' => 'Bfrtip',
'scrollX' => false,
'buttons' => [
'create',
'print',
'reset',
'reload',
Expand Down

0 comments on commit d0ee6d0

Please sign in to comment.