From b46ade91f59f150d444854620e687001580dbec7 Mon Sep 17 00:00:00 2001 From: Cristen Jones Date: Thu, 14 Nov 2024 16:20:14 -0500 Subject: [PATCH] fix(Icon): parse icon from file, closes #2 Valid SVG icons could contain other markup beyond the bare ``, so explicitly parse that out. --- lib/mbta_metro/components/icon.ex | 16 +++++++++++----- mix.exs | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/mbta_metro/components/icon.ex b/lib/mbta_metro/components/icon.ex index 87db7e8..f20747c 100644 --- a/lib/mbta_metro/components/icon.ex +++ b/lib/mbta_metro/components/icon.ex @@ -1,6 +1,8 @@ defmodule MbtaMetro.Components.Icon do @moduledoc false + require Logger + use Phoenix.Component alias MbtaMetro.Utils @@ -34,11 +36,15 @@ defmodule MbtaMetro.Components.Icon do for {file, name, type} <- icons do defp icon(unquote(type), unquote(name), opts) do - attrs = opts_to_attrs(opts) - - " rest = unquote(file) - - Phoenix.HTML.raw([" Floki.raw_html() + |> Phoenix.HTML.raw() + else + _ -> + Logger.warning("Could not parse icon #{unquote(name)} #{unquote(type)}") + end end end diff --git a/mix.exs b/mix.exs index f27cb3e..172cac2 100644 --- a/mix.exs +++ b/mix.exs @@ -40,7 +40,7 @@ defmodule MbtaMetro.MixProject do {:esbuild, "0.8.1", only: :dev, optional: true, runtime: Mix.env() == :dev}, {:ex_doc, ">= 0.0.0", only: :dev, runtime: false}, {:faker, "0.18.0", only: :dev, runtime: false}, - {:floki, "0.36.3", only: :test, runtime: false}, + {:floki, "~> 0.36"}, {:jason, "1.4.4"}, {:heroicons, "0.5.6", optional: true}, {:phoenix, "1.7.14"},