From 76289c4ad481685efe75eaa5ceaa444fda2c6a92 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 15 Dec 2023 11:12:57 +0100 Subject: [PATCH] Update documentation article component to support existing variables Allows for them to be passed from a model class, for example. --- .../docs/documentation-article.blade.php | 2 +- .../Feature/Services/HydeSmartDocsTest.php | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/framework/resources/views/components/docs/documentation-article.blade.php b/packages/framework/resources/views/components/docs/documentation-article.blade.php index d2c02ea978a..328f370982d 100644 --- a/packages/framework/resources/views/components/docs/documentation-article.blade.php +++ b/packages/framework/resources/views/components/docs/documentation-article.blade.php @@ -1,5 +1,5 @@ @php - $article = \Hyde\Framework\Features\Documentation\SemanticDocumentationArticle::make($page); + $article ??= \Hyde\Framework\Features\Documentation\SemanticDocumentationArticle::make($page); @endphp
assertStringContainsString('

Hello world.

', $rendered); } + public function test_the_documentation_article_view_with_existing_variable() + { + $rendered = view('hyde::components.docs.documentation-article', [ + 'page' => $page = $this->makePage(), + 'article' => new class($page) extends SemanticDocumentationArticle { + public function __construct(DocumentationPage $page) + { + parent::__construct($page); + } + + public function renderHeader(): HtmlString + { + return new HtmlString('

Custom Header

'); + } + }, + ])->render(); + + $this->assertStringContainsString('

Custom Header

', $rendered); + $this->assertStringContainsString('

Hello world.

', $rendered); + + } + protected function makeArticle(string $sourceFileContents = "# Foo\n\nHello world."): SemanticDocumentationArticle { $this->file('_docs/foo.md', $sourceFileContents);