Skip to content

Commit

Permalink
Laravel Pint and per preset
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-butti committed Dec 16, 2023
1 parent 8647bb8 commit 00121f1
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 37 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
]
},
"scripts-descriptions": {
"csfix": "Runs Pint to fix project files.",
"csfix-review": "Runs Pint to show the details of which files are out of code standard."
"csfix": "Runs Pint to fix code style.",
"csfix-review": "Runs Pint to show the code style review."
},
"minimum-stability": "dev",
"prefer-stable": true
Expand Down
2 changes: 1 addition & 1 deletion pint.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"preset": "psr12"
"preset": "per"
}
4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ This command will use the generated files from the `ibis-next build` command to

## Development

This project uses PHP CS Fixer with a code standard defined in `.php_cs`.
This project uses Laravel Pint to fix the code style according to `per` preset.
The `pint.json` file defines the Laravel Pint configuration.
Laravel Pint is built on top of the great tool PHP-CS-Fixer.

To review code out of style, you can run the fix command as a dry run. Run the composer script like this:

Expand Down
22 changes: 11 additions & 11 deletions src/Commands/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
$theme = $this->getTheme($currentPath, $this->themeName);

$this->buildPdf(
$this->buildHtml($currentPath.'/content', $config),
$this->buildHtml($currentPath . '/content', $config),
$config,
$currentPath,
$theme
Expand All @@ -104,9 +104,9 @@ protected function ensureExportDirectoryExists(string $currentPath): void
{
$this->output->writeln('<fg=yellow>==></> Preparing Export Directory ...');

if (!$this->disk->isDirectory($currentPath.'/export')) {
if (!$this->disk->isDirectory($currentPath . '/export')) {
$this->disk->makeDirectory(
$currentPath.'/export',
$currentPath . '/export',
0755,
true
);
Expand Down Expand Up @@ -216,7 +216,7 @@ protected function buildPdf(Collection $chapters, array $config, string $current
'margin_right' => $config['document']['margin_right'] ?? 27,
'margin_bottom' => $config['document']['margin_bottom'] ?? 14,
'margin_top' => $config['document']['margin_top'] ?? 14,
'fontDir' => array_merge($fontDirs, [getcwd().'/assets/fonts']),
'fontDir' => array_merge($fontDirs, [getcwd() . '/assets/fonts']),
'fontdata' => $this->fonts($config, $fontData),
]);

Expand All @@ -238,7 +238,7 @@ protected function buildPdf(Collection $chapters, array $config, string $current
if (key_exists("image", $config['cover'])) {
$coverImage = $config['cover']['image'];
}
if ($this->disk->isFile($currentPath.'/assets/' . $coverImage)) {
if ($this->disk->isFile($currentPath . '/assets/' . $coverImage)) {
$this->output->writeln('<fg=yellow>==></> Adding Book Cover ...');

$coverPosition = $config['cover']['position'] ?? 'position: absolute; left:0; right: 0; top: -.2; bottom: 0;';
Expand All @@ -253,10 +253,10 @@ protected function buildPdf(Collection $chapters, array $config, string $current
);

$pdf->AddPage();
} elseif ($this->disk->isFile($currentPath.'/assets/cover.html')) {
} elseif ($this->disk->isFile($currentPath . '/assets/cover.html')) {
$this->output->writeln('<fg=yellow>==></> Adding Book Cover ...');

$cover = $this->disk->get($currentPath.'/assets/cover.html');
$cover = $this->disk->get($currentPath . '/assets/cover.html');

$pdf->WriteHTML($cover);

Expand All @@ -274,7 +274,7 @@ protected function buildPdf(Collection $chapters, array $config, string $current
);

foreach ($chapters as $key => $chapter) {
$this->output->writeln('<fg=yellow>==></> ❇️ '.$chapter["mdfile"].' ...');
$this->output->writeln('<fg=yellow>==></> ❇️ ' . $chapter["mdfile"] . ' ...');
if (array_key_exists('header', $config)) {
$pdf->SetHTMLHeader(
'
Expand All @@ -291,10 +291,10 @@ protected function buildPdf(Collection $chapters, array $config, string $current
$this->output->writeln('<fg=yellow>==></> Writing PDF To Disk ...');

$this->output->writeln('');
$this->output->writeln('✨✨ '.$pdf->page.' PDF pages ✨✨');
$this->output->writeln('✨✨ ' . $pdf->page . ' PDF pages ✨✨');

$pdf->Output(
$currentPath.'/export/'.Ibis::outputFileName().'-'.$this->themeName.'.pdf'
$currentPath . '/export/' . Ibis::outputFileName() . '-' . $this->themeName . '.pdf'
);
}

Expand All @@ -306,7 +306,7 @@ protected function buildPdf(Collection $chapters, array $config, string $current
*/
private function getTheme($currentPath, $themeName)
{
return $this->disk->get($currentPath."/assets/theme-$themeName.html");
return $this->disk->get($currentPath . "/assets/theme-$themeName.html");
}

/**
Expand Down
28 changes: 14 additions & 14 deletions src/Commands/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,48 +47,48 @@ public function execute(InputInterface $input, OutputInterface $output): int

$currentPath = getcwd();

if ($this->disk->isDirectory($currentPath.'/assets')) {
if ($this->disk->isDirectory($currentPath . '/assets')) {
$this->output->writeln('');
$this->output->writeln('<info>Project already initialised!</info>');

return 0;
}

$this->disk->makeDirectory(
$currentPath.'/assets'
$currentPath . '/assets'
);

$this->disk->makeDirectory(
$currentPath.'/assets/fonts'
$currentPath . '/assets/fonts'
);

$this->disk->makeDirectory(
$currentPath.'/content'
$currentPath . '/content'
);

$this->disk->copyDirectory(
__DIR__.'/../../stubs/content',
$currentPath.'/content'
__DIR__ . '/../../stubs/content',
$currentPath . '/content'
);

$this->disk->put(
$currentPath.'/ibis.php',
$this->disk->get(__DIR__.'/../../stubs/ibis.php')
$currentPath . '/ibis.php',
$this->disk->get(__DIR__ . '/../../stubs/ibis.php')
);

$this->disk->put(
$currentPath.'/assets/cover.jpg',
$this->disk->get(__DIR__.'/../../stubs/assets/cover.jpg')
$currentPath . '/assets/cover.jpg',
$this->disk->get(__DIR__ . '/../../stubs/assets/cover.jpg')
);

$this->disk->put(
$currentPath.'/assets/theme-dark.html',
$this->disk->get(__DIR__.'/../../stubs/assets/theme-dark.html')
$currentPath . '/assets/theme-dark.html',
$this->disk->get(__DIR__ . '/../../stubs/assets/theme-dark.html')
);

$this->disk->put(
$currentPath.'/assets/theme-light.html',
$this->disk->get(__DIR__.'/../../stubs/assets/theme-light.html')
$currentPath . '/assets/theme-light.html',
$this->disk->get(__DIR__ . '/../../stubs/assets/theme-light.html')
);

$this->output->writeln('');
Expand Down
10 changes: 5 additions & 5 deletions src/Commands/SampleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ public function execute(InputInterface $input, OutputInterface $output): int

$currentPath = getcwd();

$config = require $currentPath.'/ibis.php';
$config = require $currentPath . '/ibis.php';

$mpdf = new \Mpdf\Mpdf();

$fileName = Ibis::outputFileName().'-'.$input->getArgument('theme');
$fileName = Ibis::outputFileName() . '-' . $input->getArgument('theme');

$mpdf->setSourceFile($currentPath.'/export/'.$fileName.'.pdf');
$mpdf->setSourceFile($currentPath . '/export/' . $fileName . '.pdf');

foreach ($config['sample'] as $range) {
foreach (range($range[0], $range[1]) as $page) {
Expand All @@ -66,10 +66,10 @@ public function execute(InputInterface $input, OutputInterface $output): int
}
}

$mpdf->WriteHTML('<p style="text-align: center; font-size: 16px; line-height: 40px;">'.$config['sample_notice'].'</p>');
$mpdf->WriteHTML('<p style="text-align: center; font-size: 16px; line-height: 40px;">' . $config['sample_notice'] . '</p>');

$mpdf->Output(
$currentPath.'/export/sample-.'.$fileName.'.pdf'
$currentPath . '/export/sample-.' . $fileName . '.pdf'
);

return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/SortContentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function execute(InputInterface $input, OutputInterface $output): int

$currentPath = getcwd();

collect($this->disk->files($currentPath.'/content'))->each(function ($file, $index) use ($currentPath) {
collect($this->disk->files($currentPath . '/content'))->each(function ($file, $index) use ($currentPath) {
$markdown = $this->disk->get(
$file->getPathname()
);
Expand All @@ -60,7 +60,7 @@ public function execute(InputInterface $input, OutputInterface $output): int

$this->disk->move(
$file->getPathName(),
$currentPath.'/content/'.Str::slug($newName).'.md'
$currentPath . '/content/' . Str::slug($newName) . '.md'
);
});

Expand Down
2 changes: 1 addition & 1 deletion src/Ibis.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private static function config()
return static::$config;
}

static::$config = require getcwd().'/ibis.php';
static::$config = require getcwd() . '/ibis.php';

return static::$config;
}
Expand Down

0 comments on commit 00121f1

Please sign in to comment.