diff --git a/README.md b/README.md
index 3efea44..886635f 100644
--- a/README.md
+++ b/README.md
@@ -2,9 +2,13 @@
[Heroicons](https://github.com/tailwindlabs/heroicons) are "a set of free MIT-licensed high-quality SVG icons for you to use in your web projects". This package gives you Elixir functions to drop Heroicons into your HTML, styled with arbitrary classes.
+This library provides optimized svgs for each Heroicon packaged as a Phoenix Component (and as a function for backwards-compatibility).
+
+In order to provide the best balance of fast compilation times and run-time performance, Phoenix Components are just-in-time compiled on first use and then cached in an ETS-backed cache.
+
Heroicons are designed by [Steve Schoger](https://twitter.com/steveschoger)
-Current Heroicons Version: **2.0.0**
+Current Heroicons Version: **2.0.10**. It's possible to configure a different Heroicon version locally, see [mix heroicons.update](https://hexdocs.pm/heroicons/Mix.Tasks.Heroicons.Update.html)
## Installation
@@ -31,7 +35,7 @@ The components are in `Heroicons.Solid`, `Heroicons.Outline`, and `Heroicons.Min
and style it with some classes
```eex
-
+
```
There are also function versions of each component:
diff --git a/lib/heroicons.ex b/lib/heroicons.ex
index 0033d7b..5d63584 100644
--- a/lib/heroicons.ex
+++ b/lib/heroicons.ex
@@ -1,26 +1,34 @@
defmodule Heroicons do
+ @latest_version "2.0.10"
+
@moduledoc """
This library provides Phoenix Components for every [Heroicon](https://github.com/tailwindlabs/heroicons).
- See `Heroicons.Outline` and `Heroicons.Solid` for the two styles of icon.
+ See `Heroicons.Outline`, `Heroicons.Solid` and `Heroicons.Mini` for the three styles of icon.
## Examples
-
+
-
+
+
+
Can also be used as a function
- <%= Heroicons.Outline.adjustments() %>
+ <%= Heroicons.Outline.adjustments_vertical() %>
- <%= Heroicons.Solid.arrow_circle_right(class: "w-6 h-6") />
+ <%= Heroicons.Solid.arrow_right_circle(class: "w-6 h-6") />
+
+ <%= Heroicons.Mini.bell(class: "w-4 h-4") />
+
+
+ This library comes pre-packaged with the icons from Heroicons version `#{@latest_version}`,
+ but can be locally configured and updated. See `Mix.Tasks.Heroicons.Update` for details
Heroicons are designed by [Steve Schoger](https://twitter.com/steveschoger)
"""
# https://github.com/tailwindlabs/heroicons/releases
- @latest_version "2.0.10"
-
@tmp_dir_name "heroicons-elixir"
use Application
require Logger
@@ -28,7 +36,7 @@ defmodule Heroicons do
@doc false
def start(_type, _args) do
children = [
- {Heroicons.IconCache, []}
+ {Heroicons.Cache, []}
]
opts = [strategy: :one_for_one, name: Heroicons.Supervisor]
diff --git a/lib/heroicons/icon_cache.ex b/lib/heroicons/cache.ex
similarity index 77%
rename from lib/heroicons/icon_cache.ex
rename to lib/heroicons/cache.ex
index a887846..461682d 100644
--- a/lib/heroicons/icon_cache.ex
+++ b/lib/heroicons/cache.ex
@@ -1,11 +1,18 @@
-defmodule Heroicons.IconCache do
- @doc "Get's an icon's body from the filesystem"
+defmodule Heroicons.Cache do
+ @moduledoc """
+ An ETS-backed cache for icons. We cache both pre-compiled Phoenix Components and icon bodies as strings.
+
+ Uses the icon's path on disk as a key.
+ """
+
use GenServer
@name __MODULE__
+ @doc false
def start_link(_), do: GenServer.start_link(__MODULE__, [], name: @name)
+ @doc "Fetch a pre-compiled Phoenix Component from the cache or disk, given a `path`"
def fetch_component(path) do
case :ets.lookup(@name.Components, path) do
[{^path, component}] ->
@@ -16,6 +23,7 @@ defmodule Heroicons.IconCache do
end
end
+ @doc "Fetch a icon's body from the cache or disk, given a `path`"
def fetch_body(path) do
case :ets.lookup(@name, path) do
[{^path, body}] ->
@@ -26,6 +34,7 @@ defmodule Heroicons.IconCache do
end
end
+ @impl true
def init(_) do
:ets.new(@name, [:set, :protected, :named_table])
:ets.new(@name.Components, [:set, :protected, :named_table])
@@ -33,6 +42,7 @@ defmodule Heroicons.IconCache do
{:ok, []}
end
+ @impl true
def handle_call({:cache_body, path}, _ref, state) do
body = read_body(path)
diff --git a/lib/heroicons/generator.ex b/lib/heroicons/generator.ex
index 4b67e98..33b60b9 100644
--- a/lib/heroicons/generator.ex
+++ b/lib/heroicons/generator.ex
@@ -1,4 +1,5 @@
defmodule Heroicons.Generator do
+ @moduledoc false
defmacro __using__(icon_dir: icon_dir) do
icon_paths =
Path.absname(icon_dir, :code.priv_dir(:heroicons))
@@ -73,7 +74,7 @@ defmodule Heroicons.Generator do
{component, _binding} =
Code.eval_quoted(
- Heroicons.IconCache.fetch_component(path),
+ Heroicons.Cache.fetch_component(path),
assigns: assigns
)
@@ -97,7 +98,7 @@ defmodule Heroicons.Generator do
"