From b61d38eaa9bbda0c4084614030fd947cdd2f25b6 Mon Sep 17 00:00:00 2001 From: Max Veytsman Date: Wed, 10 Mar 2021 13:50:55 -0500 Subject: [PATCH] Load icon into function directly --- lib/heroicons.ex | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/heroicons.ex b/lib/heroicons.ex index be21dab..dfc1eb1 100644 --- a/lib/heroicons.ex +++ b/lib/heroicons.ex @@ -31,6 +31,11 @@ defmodule Heroicons do |> String.replace("-", "_") |> String.to_atom() + icon = File.read!(path) + {i, _} = :binary.match(icon, ">") + + {head, tail} = String.split_at(icon, i) + doc = """ ![](assets/#{Path.relative_to(path, :code.priv_dir(:heroicons))}) {: width=24px} @@ -43,16 +48,11 @@ defmodule Heroicons do @doc unquote(doc) @spec unquote(name)(keyword(binary)) :: binary def unquote(name)(opts \\ []) do - icon = File.read!(unquote(path)) - {i, _} = :binary.match(icon, ">") - - {head, tail} = String.split_at(icon, i) - attrs = opts |> Enum.map_join(fn {k, v} -> ~s( #{k}="#{v}") end) - head <> attrs <> tail + unquote(head) <> attrs <> unquote(tail) end end end