diff --git a/src/BreadcrumbsComponent.php b/src/BreadcrumbsComponent.php
index 1d2ddae..30ebf6e 100644
--- a/src/BreadcrumbsComponent.php
+++ b/src/BreadcrumbsComponent.php
@@ -9,66 +9,30 @@
class BreadcrumbsComponent extends Component
{
- /**
- * @var Manager
- */
- public $breadcrumbs;
-
- /**
- * @var string|null
- */
- public $route;
-
- /**
- * @var mixed|null
- */
- public $parameters;
-
- /**
- * @var string|null
- */
- public $class;
-
- /**
- * @var string|null
- */
- public $active;
-
/**
* Create a new component instance.
- *
- * @param Manager $manager
- * @param string|null $route
- * @param mixed|null $parameters
- * @param string|null $class
- * @param string|null $active
*/
public function __construct(
- Manager $manager,
- string $route = null,
- $parameters = null,
- string $class = null,
- string $active = null
- )
- {
- $this->breadcrumbs = $manager;
- $this->route = $route;
- $this->parameters = $parameters;
- $this->class = $class;
- $this->active = $active;
- }
+ public Manager $manager,
+ public ?string $route = null,
+ public $parameters = null,
+ public ?string $class = null,
+ public ?string $active = null,
+ public bool $escape = true,
+ ) {}
/**
- * @return Collection
* @throws \Throwable
+ *
+ * @return Collection
*/
public function generate(): Collection
{
if ($this->route !== null) {
- return $this->breadcrumbs->generate($this->route, $this->parameters);
+ return $this->manager->generate($this->route, $this->parameters);
}
- return $this->breadcrumbs->current($this->parameters);
+ return $this->manager->current($this->parameters);
}
/**
@@ -78,7 +42,7 @@ public function generate(): Collection
*/
public function shouldRender(): bool
{
- return $this->breadcrumbs->has($this->route);
+ return $this->manager->has($this->route);
}
/**
@@ -90,4 +54,16 @@ public function render()
{
return view('breadcrumbs::breadcrumbs');
}
+
+ /**
+ * @param Crumb $crumb
+ *
+ * @return string|null
+ */
+ public function title(Crumb $crumb): ?string
+ {
+ $title = $crumb->title();
+
+ return $this->escape ? e($title) : $title;
+ }
}
diff --git a/tests/ComponentTest.php b/tests/ComponentTest.php
index 8fd06ed..8d189ef 100644
--- a/tests/ComponentTest.php
+++ b/tests/ComponentTest.php
@@ -37,6 +37,19 @@ public function testParameters(): void
->assertSee('value 3');
}
+ public function testEscapedHtmlIsRenderedAsText(): void
+ {
+ $this->getComponent('escaped')
+ ->assertSee('Important Notice')
+ ->assertDontSee('Important Notice', false);
+ }
+
+ public function testUnescapedHtmlIsRenderedAsHtml(): void
+ {
+ $this->getComponent('unescaped')
+ ->assertSee('Important Notice', false);
+ }
+
/**
* @param string $template
*
@@ -59,7 +72,8 @@ protected function getComponent(string $template): TestResponse
return $trail
->push('Home')
->push('Arguments', $value)
- ->push('Arguments2', $value2);
+ ->push('Arguments2', $value2)
+ ->push('Important Notice');
});
return $this->get("component/$template");
diff --git a/tests/views/escaped.blade.php b/tests/views/escaped.blade.php
new file mode 100644
index 0000000..7393e4d
--- /dev/null
+++ b/tests/views/escaped.blade.php
@@ -0,0 +1,3 @@
+