Skip to content

Commit

Permalink
Update documentation article component to support existing variables
Browse files Browse the repository at this point in the history
Allows for them to be passed from a model class, for example.
  • Loading branch information
caendesilva committed Dec 23, 2023
1 parent c165a18 commit 76289c4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@php
$article = \Hyde\Framework\Features\Documentation\SemanticDocumentationArticle::make($page);
$article ??= \Hyde\Framework\Features\Documentation\SemanticDocumentationArticle::make($page);
@endphp

<article id="document" itemscope itemtype="https://schema.org/Article" @class([
Expand Down
22 changes: 22 additions & 0 deletions packages/framework/tests/Feature/Services/HydeSmartDocsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,28 @@ public function test_the_documentation_article_view()
$this->assertStringContainsString('<p>Hello world.</p>', $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('<h1>Custom Header</h1>');
}
},
])->render();

$this->assertStringContainsString('<h1>Custom Header</h1>', $rendered);
$this->assertStringContainsString('<p>Hello world.</p>', $rendered);

}

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

0 comments on commit 76289c4

Please sign in to comment.