From 3ec8f970a4145350bd99cb021b1ea8a1833647ce Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Sat, 29 Apr 2017 11:27:41 -0400 Subject: [PATCH] Allow dot notation to render nested icons inline Won't work with spritesheets, BEWARE! --- src/IconFactory.php | 2 +- tests/IconFactoryTest.php | 9 +++++++++ tests/resources/icons/foo/bar/arrow-thick-down.svg | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/resources/icons/foo/bar/arrow-thick-down.svg diff --git a/src/IconFactory.php b/src/IconFactory.php index 31f0e95..5b0b58e 100644 --- a/src/IconFactory.php +++ b/src/IconFactory.php @@ -98,7 +98,7 @@ private function buildClass($class) public function getSvg($name) { return $this->svgCache->get($name, function () use ($name) { - return $this->svgCache[$name] = $this->files->get(sprintf('%s/%s.svg', rtrim($this->iconPath()), $name)); + return $this->svgCache[$name] = trim($this->files->get(sprintf('%s/%s.svg', rtrim($this->iconPath()), str_replace('.', '/', $name)))); }); } } diff --git a/tests/IconFactoryTest.php b/tests/IconFactoryTest.php index 2aa4119..714e06b 100644 --- a/tests/IconFactoryTest.php +++ b/tests/IconFactoryTest.php @@ -156,4 +156,13 @@ public function inline_icons_are_cached() $this->assertEquals($expected, $resultB); $files->shouldHaveReceived('get')->once(); } + + /** @test */ + public function can_render_inline_icons_from_nested_folders_with_dot_notation() + { + $factory = new IconFactory(['inline' => true, 'class' => 'icon', 'icon_path' => __DIR__.'/resources/icons/']); + $result = $factory->icon('foo.bar.arrow-thick-down')->toHtml(); + $expected = ''; + $this->assertEquals($expected, $result); + } } diff --git a/tests/resources/icons/foo/bar/arrow-thick-down.svg b/tests/resources/icons/foo/bar/arrow-thick-down.svg new file mode 100644 index 0000000..4f1c6c7 --- /dev/null +++ b/tests/resources/icons/foo/bar/arrow-thick-down.svg @@ -0,0 +1 @@ +