defmodule Feathericons.Compiler do @default_attrs [ xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", stroke_width: "2", stroke_linecap: "round", stroke_linejoin: "round" ] @doc false defmacro __before_compile__(%Macro.Env{}) do icon_paths = Path.absname("icons", :code.priv_dir(:feathericons)) |> Path.join("*.svg") |> Path.wildcard() for path <- icon_paths do generate_function(path, @default_attrs) end end @doc false def generate_function(path, default_attrs) do name = Path.basename(path, ".svg") |> String.replace("-", "_") |> String.to_atom() icon = File.read!(path) {i, _} = :binary.match(icon, ">") {_, body} = String.split_at(icon, i + 1) doc = """ )}) {: width=24px} ## Examples iex> #{name}() iex> #{name}(class: "h-6 w-6 text-gray-500") """ quote do @doc unquote(doc) @spec unquote(name)(keyword()) :: {:safe, list()} def unquote(name)(opts \\ []) do title = Keyword.get(opts, :title, "") opts = Keyword.delete(opts, :title) opts = Keyword.merge(unquote(default_attrs), opts) title = if title == "" do "" else ["