Skip to content

Commit

Permalink
infy_tab and infy_ln used for tabs and new lines
Browse files Browse the repository at this point in the history
  • Loading branch information
mitulgolakiya committed Apr 2, 2016
1 parent 13eaa35 commit b6760f4
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Generators/MigrationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
12 changes: 6 additions & 6 deletions src/Generators/ModelGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Generators/RepositoryGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
10 changes: 5 additions & 5 deletions src/Generators/Scaffold/ViewGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
}
Expand All @@ -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 = [];

Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/Generators/TestTraitGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
32 changes: 31 additions & 1 deletion src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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);
}
}

0 comments on commit b6760f4

Please sign in to comment.