Skip to content

Commit

Permalink
Allow dot notation to render nested icons inline
Browse files Browse the repository at this point in the history
Won't work with spritesheets, BEWARE!
  • Loading branch information
adamwathan committed Apr 29, 2017
1 parent 79e34df commit 3ec8f97
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/IconFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))));
});
}
}
9 changes: 9 additions & 0 deletions tests/IconFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<svg class="icon" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M13 10V2H7v8H2l8 8 8-8h-5z" fill-rule="evenodd"/></svg>';
$this->assertEquals($expected, $result);
}
}
1 change: 1 addition & 0 deletions tests/resources/icons/foo/bar/arrow-thick-down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3ec8f97

Please sign in to comment.