diff --git a/src/Generators/MigrationGenerator.php b/src/Generators/MigrationGenerator.php index 111e427d2..4e6d1738e 100644 --- a/src/Generators/MigrationGenerator.php +++ b/src/Generators/MigrationGenerator.php @@ -56,6 +56,6 @@ private function generateFields() $fields[] = '$table->softDeletes();'; } - return implode(PHP_EOL.str_repeat(' ', 12), $fields); + return implode(infy_nl_tab(1, 3), $fields); } } diff --git a/src/Generators/ModelGenerator.php b/src/Generators/ModelGenerator.php index 6160b1bcb..79737df8c 100644 --- a/src/Generators/ModelGenerator.php +++ b/src/Generators/ModelGenerator.php @@ -54,18 +54,18 @@ private function fillTemplate($templateData) $templateData = $this->fillTimestamps($templateData); if ($this->commandData->getOption('primary')) { - $primary = str_repeat(' ', 4)."protected \$primaryKey = '".$this->commandData->getOption('primary')."';\n"; + $primary = infy_tab()."protected \$primaryKey = '".$this->commandData->getOption('primary')."';\n"; } else { $primary = ''; } $templateData = str_replace('$PRIMARY$', $primary, $templateData); - $templateData = str_replace('$FIELDS$', implode(','.PHP_EOL.str_repeat(' ', 8), $fillables), $templateData); + $templateData = str_replace('$FIELDS$', implode(','.infy_nl_tab(1, 2), $fillables), $templateData); - $templateData = str_replace('$RULES$', implode(','.PHP_EOL.str_repeat(' ', 8), $this->generateRules()), $templateData); + $templateData = str_replace('$RULES$', implode(','.infy_nl_tab(1, 2), $this->generateRules()), $templateData); - $templateData = str_replace('$CAST$', implode(','.PHP_EOL.str_repeat(' ', 8), $this->generateCasts()), $templateData); + $templateData = str_replace('$CAST$', implode(','.infy_nl_tab(1, 2), $this->generateCasts()), $templateData); return $templateData; } @@ -81,10 +81,10 @@ private function fillSoftDeletes($templateData) '$SOFT_DELETE_IMPORT$', "use Illuminate\\Database\\Eloquent\\SoftDeletes;\n", $templateData ); - $templateData = str_replace('$SOFT_DELETE$', str_repeat(' ', 4)."use SoftDeletes;\n", $templateData); + $templateData = str_replace('$SOFT_DELETE$', infy_tab()."use SoftDeletes;\n", $templateData); $deletedAtTimestamp = config('infyom.laravel_generator.timestamps.deleted_at', 'deleted_at'); $templateData = str_replace( - '$SOFT_DELETE_DATES$', PHP_EOL.str_repeat(' ', 4)."protected \$dates = ['".$deletedAtTimestamp."'];\n", + '$SOFT_DELETE_DATES$', infy_nl_tab()."protected \$dates = ['".$deletedAtTimestamp."'];\n", $templateData ); } diff --git a/src/Generators/RepositoryGenerator.php b/src/Generators/RepositoryGenerator.php index a84678193..245126340 100644 --- a/src/Generators/RepositoryGenerator.php +++ b/src/Generators/RepositoryGenerator.php @@ -34,7 +34,7 @@ public function generate() } } - $templateData = str_replace('$FIELDS$', implode(','.PHP_EOL.str_repeat(' ', 8), $searchables), $templateData); + $templateData = str_replace('$FIELDS$', implode(','.infy_nl_tab(1, 2), $searchables), $templateData); $fileName = $this->commandData->modelName.'Repository.php'; diff --git a/src/Generators/Scaffold/ViewGenerator.php b/src/Generators/Scaffold/ViewGenerator.php index a9c01ad99..4caf664dc 100644 --- a/src/Generators/Scaffold/ViewGenerator.php +++ b/src/Generators/Scaffold/ViewGenerator.php @@ -79,7 +79,7 @@ private function generateTableHeaderFields() ); } - return implode(PHP_EOL.str_repeat(' ', 8), $headerFields); + return implode(infy_nl_tab(1, 2), $headerFields); } private function generateBladeTableBody() @@ -107,7 +107,7 @@ private function generateBladeTableBody() ); } - $tableBodyFields = implode(PHP_EOL.str_repeat(' ', 12), $tableBodyFields); + $tableBodyFields = implode(infy_nl_tab(1, 3), $tableBodyFields); return str_replace('$FIELD_BODY$', $tableBodyFields, $templateData); } @@ -120,7 +120,7 @@ private function generateDataTableBody() $templateData = str_replace('$FIELD_HEADERS$', $this->generateTableHeaderFields(), $templateData); - $cellFieldTemplate = TemplateUtil::getTemplate('scaffold.views.table_cell', $this->templateType); + $cellFieldTemplate = TemplateUtil::getTemplate('scaffold.views.datatable_column', $this->templateType); $tableBodyFields = []; @@ -137,9 +137,9 @@ private function generateDataTableBody() ); } - $tableBodyFields = implode(PHP_EOL.str_repeat(' ', 12), $tableBodyFields); + $tableBodyFields = implode(",".infy_nl_tab(1, 5), $tableBodyFields); - return str_replace('$FIELD_BODY$', $tableBodyFields, $templateData); + return str_replace('$DATATABLE_COLUMNS$', $tableBodyFields, $templateData); } private function generateIndex() diff --git a/src/Generators/TestTraitGenerator.php b/src/Generators/TestTraitGenerator.php index 9629976cb..4160feee7 100644 --- a/src/Generators/TestTraitGenerator.php +++ b/src/Generators/TestTraitGenerator.php @@ -39,7 +39,7 @@ private function fillTemplate($templateData) { $templateData = TemplateUtil::fillTemplate($this->commandData->dynamicVars, $templateData); - $templateData = str_replace('$FIELDS$', implode(','.PHP_EOL.str_repeat(' ', 12), $this->generateFields()), $templateData); + $templateData = str_replace('$FIELDS$', implode(','.infy_nl_tab(1, 3), $this->generateFields()), $templateData); return $templateData; } diff --git a/src/helpers.php b/src/helpers.php index 7758e0030..566999e6b 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -14,6 +14,21 @@ function infy_tab($spaces = 4) } } +if (!function_exists('infy_tabs')) { + /** + * Generates tab with spaces. + * + * @param int $tabs + * @param int $spaces + * + * @return string + */ + function infy_tabs($tabs, $spaces = 4) + { + return str_repeat(infy_tab($spaces), $tabs); + } +} + if (!function_exists('infy_nl')) { /** * Generates new line char. @@ -28,6 +43,21 @@ function infy_nl($count = 1) } } +if (!function_exists('infy_nls')) { + /** + * Generates new line char. + * + * @param int $count + * @param int $nls + * + * @return string + */ + function infy_nls($count, $nls = 1) + { + return str_repeat(infy_nl($nls), $count); + } +} + if (!function_exists('infy_nl_tab')) { /** * Generates new line char. @@ -39,6 +69,6 @@ function infy_nl($count = 1) */ function infy_nl_tab($lns = 1, $tabs = 1) { - return infy_nl($lns).infy_tab($tabs); + return infy_nls($lns).infy_tabs($tabs); } }