Skip to content

Commit 1937c8e

Browse files
committed
feat: allow indentation in guidelines and remove in composition
1 parent f8f847a commit 1937c8e

File tree

4 files changed

+355
-4
lines changed

4 files changed

+355
-4
lines changed

src/Install/Assists/Inertia.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Laravel\Boost\Install\Assists;
4+
5+
use Laravel\Roster\Enums\Packages;
6+
use Laravel\Roster\Roster;
7+
8+
class Inertia
9+
{
10+
public function __construct(private Roster $roster) {}
11+
12+
public function gte(string $version): bool
13+
{
14+
return
15+
$this->roster->usesVersion(Packages::INERTIA, $version, '>=') ||
16+
$this->roster->usesVersion(Packages::INERTIA_REACT, $version, '>=') ||
17+
$this->roster->usesVersion(Packages::INERTIA_SVELTE, $version, '>=') ||
18+
$this->roster->usesVersion(Packages::INERTIA_VUE, $version, '>=');
19+
}
20+
21+
public function hasFormComponent(): bool
22+
{
23+
return $this->gte('2.1.0');
24+
}
25+
26+
public function hasFormComponentResets(): bool
27+
{
28+
return $this->gte('2.1.2');
29+
}
30+
}

src/Install/GuidelineAssist.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
namespace Laravel\Boost\Install;
66

77
use Illuminate\Database\Eloquent\Model;
8+
use Laravel\Boost\Install\Assists\Inertia;
9+
use Laravel\Roster\Enums\Packages;
10+
use Laravel\Roster\Roster;
811
use ReflectionClass;
912
use Symfony\Component\Finder\Finder;
1013

@@ -19,7 +22,7 @@ class GuidelineAssist
1922

2023
protected static array $classes = [];
2124

22-
public function __construct()
25+
public function __construct(public Roster $roster)
2326
{
2427
$this->modelPaths = $this->discover(fn ($reflection) => ($reflection->isSubclassOf(Model::class) && ! $reflection->isAbstract()));
2528
$this->controllerPaths = $this->discover(fn (ReflectionClass $reflection) => (stripos($reflection->getName(), 'controller') !== false || stripos($reflection->getNamespaceName(), 'controller') !== false));
@@ -156,4 +159,14 @@ public function enumContents(): string
156159

157160
return file_get_contents(current($this->enumPaths));
158161
}
162+
163+
public function packageGte(Packages $package, string $version): bool
164+
{
165+
return $this->roster->usesVersion($package, $version, '>=');
166+
}
167+
168+
public function inertia(): Inertia
169+
{
170+
return new Inertia($this->roster);
171+
}
159172
}

src/Install/GuidelineComposer.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class GuidelineComposer
2424
public function __construct(protected Roster $roster, protected Herd $herd)
2525
{
2626
$this->config = new GuidelineConfig;
27-
$this->guidelineAssist = new GuidelineAssist;
27+
$this->guidelineAssist = new GuidelineAssist($roster);
2828
}
2929

3030
public function config(GuidelineConfig $config): self
@@ -50,9 +50,19 @@ public function compose(): string
5050
*/
5151
public static function composeGuidelines(Collection $guidelines): string
5252
{
53+
// We want to allow indentation in the guideline blade files
54+
// But we don't want the indentation in the outputted file
55+
5356
return trim($guidelines
5457
->filter(fn ($content) => ! empty(trim($content)))
55-
->map(fn ($content, $key) => "\n=== {$key} rules ===\n\n".trim($content))
58+
->map(function ($content, $key) {
59+
// Remove preceding indentation from `- guidelines`
60+
$content = collect(explode("\n", trim($content)))
61+
->map(fn ($line) => preg_replace('/\s+-/', '-', $line))
62+
->join("\n");
63+
64+
return "\n=== {$key} rules ===\n\n".trim($content);
65+
})
5666
->join("\n\n"));
5767
}
5868

@@ -139,7 +149,7 @@ protected function find(): Collection
139149

140150
return $guidelines
141151
->whereNotNull()
142-
->where(fn ($guideline) => ! empty(trim($guideline)));
152+
->where(fn (string $guideline) => ! empty(trim($guideline)));
143153
}
144154

145155
/**

0 commit comments

Comments
 (0)