Skip to content

Commit

Permalink
Add ability to add dynamic HTML (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jubeki authored Aug 26, 2022
1 parent adf47ca commit 1a8d533
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
4 changes: 4 additions & 0 deletions resources/views/errorPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

<style><?= $viewModel->getAssetContents('ignition.css') ?></style>

<?= $viewModel->customHtmlHead() ?>

</head>
<body class="scrollbar-lg">

Expand Down Expand Up @@ -62,6 +64,8 @@
window.ignite(window.data);
</script>

<?= $viewModel->customHtmlBody() ?>

<!--
<?= $viewModel->throwableString() ?>
-->
Expand Down
14 changes: 13 additions & 1 deletion src/ErrorPage/ErrorPageViewModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public function __construct(
protected IgnitionConfig $ignitionConfig,
protected Report $report,
protected array $solutions,
protected ?string $solutionTransformerClass = null
protected ?string $solutionTransformerClass = null,
protected string $customHtmlHead = '',
protected string $customHtmlBody = ''
) {
$this->solutionTransformerClass ??= SolutionTransformer::class;
}
Expand Down Expand Up @@ -115,4 +117,14 @@ public function updateConfigEndpoint(): string
// TODO: Should be based on Ignition config
return '/_ignition/update-config';
}

public function customHtmlHead(): string
{
return $this->customHtmlHead;
}

public function customHtmlBody(): string
{
return $this->customHtmlBody;
}
}
26 changes: 26 additions & 0 deletions src/Ignition.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class Ignition
/** @var ArrayObject<int, callable(Throwable): mixed> */
protected ArrayObject $documentationLinkResolvers;

protected string $customHtmlHead = '';

protected string $customHtmlBody = '';

public static function make(): self
{
return new self();
Expand Down Expand Up @@ -303,11 +307,33 @@ public function renderException(Throwable $throwable, ?Report $report = null): v
$report,
$this->solutionProviderRepository->getSolutionsForThrowable($throwable),
$this->solutionTransformerClass,
$this->customHtmlHead,
$this->customHtmlBody
);

(new Renderer())->render(['viewModel' => $viewModel]);
}

/**
* Add custom HTML which will be added to the head tag of the error page.
*/
public function addCustomHtmlToHead(string $html): self
{
$this->customHtmlHead .= $html;

return $this;
}

/**
* Add custom HTML which will be added to the body tag of the error page.
*/
public function addCustomHtmlToBody(string $html): self
{
$this->customHtmlBody .= $html;

return $this;
}

protected function setUpFlare(): self
{
if (! $this->flare->apiTokenSet()) {
Expand Down

0 comments on commit 1a8d533

Please sign in to comment.