structure and style updates

This commit is contained in:
Mark Gregory
2026-06-16 23:21:49 +01:00
parent 80991208af
commit 2c2af4c50e
60 changed files with 209 additions and 216 deletions
@@ -9,9 +9,9 @@ use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Storage;
use Modules\Documentation\Http\Requests\StoreDocumentationDocumentRequest;
use Modules\Documentation\Http\Requests\UpdateDocumentationDocumentRequest;
use Modules\Documentation\Models\DocumentationAttachment;
use Modules\Documentation\Models\DocumentationCategory;
use Modules\Documentation\Models\DocumentationDocument;
use Modules\Documentation\Models\DocumentationAttachment;
class DocumentationController extends Controller
{
@@ -31,7 +31,7 @@ class DocumentationController extends Controller
}
if ($request->filled('search')) {
$search = '%' . $request->string('search')->trim()->toString() . '%';
$search = '%'.$request->string('search')->trim()->toString().'%';
$query->where(function ($builder) use ($search): void {
$builder->where('title', 'like', $search)
->orWhere('summary', 'like', $search)
@@ -197,7 +197,6 @@ class DocumentationController extends Controller
return redirect()->route('documentation.documents.edit', $document)->with('status', 'Attachment removed successfully.');
}
/**
* Extract body content from an uploaded Markdown file when requested.
*/
@@ -33,9 +33,9 @@ class StoreDocumentationDocumentRequest extends FormRequest
'is_featured' => ['nullable', 'boolean'],
'version' => ['required', 'string', 'max:50'],
'reference' => ['nullable', 'string', 'max:100'],
'attachment' => ['nullable', 'file', 'max:' . config('documentation.max_upload_kb', 20480), 'mimes:' . implode(',', config('documentation.allowed_upload_mimes', []))],
'attachment' => ['nullable', 'file', 'max:'.config('documentation.max_upload_kb', 20480), 'mimes:'.implode(',', config('documentation.allowed_upload_mimes', []))],
'attachments' => ['nullable', 'array'],
'attachments.*' => ['file', 'max:' . config('documentation.max_upload_kb', 20480), 'mimes:' . implode(',', config('documentation.allowed_upload_mimes', []))],
'attachments.*' => ['file', 'max:'.config('documentation.max_upload_kb', 20480), 'mimes:'.implode(',', config('documentation.allowed_upload_mimes', []))],
];
}
}
@@ -36,9 +36,9 @@ class UpdateDocumentationDocumentRequest extends FormRequest
'is_featured' => ['nullable', 'boolean'],
'version' => ['required', 'string', 'max:50'],
'reference' => ['nullable', 'string', 'max:100'],
'attachment' => ['nullable', 'file', 'max:' . config('documentation.max_upload_kb', 20480), 'mimes:' . implode(',', config('documentation.allowed_upload_mimes', []))],
'attachment' => ['nullable', 'file', 'max:'.config('documentation.max_upload_kb', 20480), 'mimes:'.implode(',', config('documentation.allowed_upload_mimes', []))],
'attachments' => ['nullable', 'array'],
'attachments.*' => ['file', 'max:' . config('documentation.max_upload_kb', 20480), 'mimes:' . implode(',', config('documentation.allowed_upload_mimes', []))],
'attachments.*' => ['file', 'max:'.config('documentation.max_upload_kb', 20480), 'mimes:'.implode(',', config('documentation.allowed_upload_mimes', []))],
'remove_attachment' => ['nullable', 'boolean'],
];
}
@@ -57,13 +57,13 @@ class DocumentationAttachment extends Model
}
if ($bytes < 1024) {
return $bytes . ' B';
return $bytes.' B';
}
if ($bytes < 1048576) {
return number_format($bytes / 1024, 1) . ' KB';
return number_format($bytes / 1024, 1).' KB';
}
return number_format($bytes / 1048576, 1) . ' MB';
return number_format($bytes / 1048576, 1).' MB';
}
}
@@ -66,7 +66,7 @@ class DocumentationCategory extends Model
/**
* Active category scope.
*
* @param Builder<DocumentationCategory> $query
* @param Builder<DocumentationCategory> $query
* @return Builder<DocumentationCategory>
*/
public function scopeActive(Builder $query): Builder
@@ -77,7 +77,7 @@ class DocumentationCategory extends Model
/**
* Ordered category scope.
*
* @param Builder<DocumentationCategory> $query
* @param Builder<DocumentationCategory> $query
* @return Builder<DocumentationCategory>
*/
public function scopeOrdered(Builder $query): Builder
@@ -29,7 +29,9 @@ class DocumentationDocument extends Model
use SoftDeletes;
public const STATUS_DRAFT = 'draft';
public const STATUS_PUBLISHED = 'published';
public const STATUS_ARCHIVED = 'archived';
/** @var list<string> */
@@ -99,7 +101,7 @@ class DocumentationDocument extends Model
/**
* Published document scope.
*
* @param Builder<DocumentationDocument> $query
* @param Builder<DocumentationDocument> $query
* @return Builder<DocumentationDocument>
*/
public function scopePublished(Builder $query): Builder
@@ -110,13 +112,14 @@ class DocumentationDocument extends Model
/**
* Featured document scope.
*
* @param Builder<DocumentationDocument> $query
* @param Builder<DocumentationDocument> $query
* @return Builder<DocumentationDocument>
*/
public function scopeFeatured(Builder $query): Builder
{
return $query->where('is_featured', true);
}
/**
* Render the document body as safe Markdown HTML for display.
*/
@@ -135,7 +138,7 @@ class DocumentationDocument extends Model
]);
}
return '<p>' . nl2br(e($body), false) . '</p>';
return '<p>'.nl2br(e($body), false).'</p>';
}
/**
@@ -148,5 +151,4 @@ class DocumentationDocument extends Model
return str_ends_with($name, '.md') || in_array($mime, ['text/markdown', 'text/x-markdown', 'text/plain'], true);
}
}
@@ -2,8 +2,8 @@
namespace Modules\Documentation\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider
{
@@ -2,13 +2,13 @@
namespace Modules\Documentation\Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
use Modules\Documentation\Models\DocumentationCategory;
use Modules\Documentation\Models\DocumentationDocument;
use Modules\Documentation\Models\DocumentationAttachment;
use Tests\TestCase;
class DocumentationModuleTest extends TestCase
{
@@ -17,7 +17,7 @@ class DocumentationModuleTest extends TestCase
/**
* Add a CSRF token for projects that keep web middleware enabled during tests.
*
* @param array<string, mixed> $payload
* @param array<string, mixed> $payload
* @return array<string, mixed>
*/
private function csrfPayload(array $payload): array
@@ -30,7 +30,7 @@ class DocumentationModuleTest extends TestCase
*/
public function test_documentation_dashboard_renders(): void
{
$user = \App\Models\User::factory()->create();
$user = User::factory()->create();
$this->actingAs($user)
->get(route('documentation.documents.index'))
@@ -43,7 +43,7 @@ class DocumentationModuleTest extends TestCase
*/
public function test_document_can_be_created(): void
{
$user = \App\Models\User::factory()->create();
$user = User::factory()->create();
$category = DocumentationCategory::query()->create([
'name' => 'Operations',
'slug' => 'operations',
@@ -72,7 +72,6 @@ class DocumentationModuleTest extends TestCase
]);
}
/**
* Markdown attachments are stored and imported into the document body.
*/
@@ -80,7 +79,7 @@ class DocumentationModuleTest extends TestCase
{
Storage::fake('public');
$user = \App\Models\User::factory()->create();
$user = User::factory()->create();
$file = UploadedFile::fake()->createWithContent('goods-in.md', "# Goods In\n\n- Scan delivery note\n- Confirm quantities");
$response = $this->actingAs($user)->withSession(['_token' => 'test-token'])->post(route('documentation.documents.store'), $this->csrfPayload([
@@ -102,8 +101,6 @@ class DocumentationModuleTest extends TestCase
Storage::disk('public')->assertExists($document->attachment_path);
}
/**
* Multiple supporting attachments can be uploaded, downloaded and removed.
*/
@@ -111,7 +108,7 @@ class DocumentationModuleTest extends TestCase
{
Storage::fake('public');
$user = \App\Models\User::factory()->create();
$user = User::factory()->create();
$response = $this->actingAs($user)->withSession(['_token' => 'test-token'])->post(route('documentation.documents.store'), $this->csrfPayload([
'title' => 'Attachment Pack',
@@ -153,7 +150,7 @@ class DocumentationModuleTest extends TestCase
*/
public function test_document_editor_has_markdown_code_controls(): void
{
$user = \App\Models\User::factory()->create();
$user = User::factory()->create();
$this->actingAs($user)
->get(route('documentation.documents.create'))
@@ -168,7 +165,7 @@ class DocumentationModuleTest extends TestCase
*/
public function test_category_can_be_created(): void
{
$user = \App\Models\User::factory()->create();
$user = User::factory()->create();
$this->actingAs($user)->withSession(['_token' => 'test-token'])->post(route('documentation.categories.store'), $this->csrfPayload([
'name' => 'Policies',