From 2d954961af9df2bd07c92b6f7b9914e837d697c4 Mon Sep 17 00:00:00 2001 From: Max Veytsman Date: Fri, 2 Sep 2022 18:57:26 -0400 Subject: [PATCH] Use relative paths for icons --- lib/heroicons/cache.ex | 4 +++- lib/heroicons/generator.ex | 13 ++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/heroicons/cache.ex b/lib/heroicons/cache.ex index 461682d..c7b85a0 100644 --- a/lib/heroicons/cache.ex +++ b/lib/heroicons/cache.ex @@ -69,7 +69,9 @@ defmodule Heroicons.Cache do end defp read_body(path) do - icon = File.read!(path) + icon = + Path.join(:code.priv_dir(:heroicons), path) + |> File.read!() <<"> = icon diff --git a/lib/heroicons/generator.ex b/lib/heroicons/generator.ex index 33b60b9..d1b5834 100644 --- a/lib/heroicons/generator.ex +++ b/lib/heroicons/generator.ex @@ -9,7 +9,8 @@ defmodule Heroicons.Generator do require Phoenix.Component for path <- icon_paths do - generate(path) + relative_path = Path.relative_to(path, :code.priv_dir(:heroicons)) + generate(relative_path) end end @@ -18,7 +19,7 @@ defmodule Heroicons.Generator do name = Heroicons.Generator.name(path) quote do - @doc Heroicons.Generator.doc(unquote(path)) + @doc Heroicons.Generator.doc(unquote(name), unquote(path)) def unquote(name)(assigns_or_opts \\ []) def unquote(name)(assigns) when is_map(assigns) do @@ -39,18 +40,16 @@ defmodule Heroicons.Generator do end @doc false - def doc(path) do - name = name(path) - + def doc(name, path) do """ - ![](assets/#{Path.relative_to(path, :code.priv_dir(:heroicons))}) {: width=24px} + ![](assets/#{path}) {: width=24px} ## Examples Use as a `Phoenix.Component` <.#{name} /> - <.#{name} class="h-6 w-6 text-gray-500" /> + <.#{name} class="w-6 h-6 text-gray-500" /> or as a function