From f0d1abf4772b42664d78c9eea9dd4cc94f9e2f28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Diedrich?= Date: Mon, 27 Jun 2022 10:59:01 +0200 Subject: [PATCH] init --- .gitignore | 1 + livebook.livemd | 46 +++++++++++++++++++++++++++++++++++++++++++++ systemuicons_ex.exs | 3 +++ 3 files changed, 50 insertions(+) create mode 100644 .gitignore create mode 100644 livebook.livemd create mode 100644 systemuicons_ex.exs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ab7bacf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/priv diff --git a/livebook.livemd b/livebook.livemd new file mode 100644 index 0000000..95a50d1 --- /dev/null +++ b/livebook.livemd @@ -0,0 +1,46 @@ +# Function components from systemuicons + +```elixir +Mix.install([ + {:jason, "~> 1.3"} +]) +``` + +## Clone git repo + +```elixir +System.cmd("git", ["clone", "--depth=1", "https://github.com/CoreyGinnivan/system-uicons.git"], + cd: "./priv" +) + +{output, _} = System.cmd("ls", ["./priv/system-uicons/src/images/icons"]) +IO.puts(output) +``` + +## Get icon data + +```elixir +path = "./priv/system-uicons/src/js/data.js" +source_data = File.read!(path) +cl = String.to_charlist(source_data) + +<<"var sourceData = "::utf8, rest::binary>> = source_data +# remove trailing semicolon +sslice = String.slice(rest, 0..-3//1) +# quote object keys +quote_keys = Regex.replace(~r/([\w_]+):/, sslice, "\"\\1\":") +# remove trailing commas +rm_trailing_commas = Regex.replace(~r/,\s+(}|])/, quote_keys, "\\1") + +icon_data = Jason.decode!(rm_trailing_commas) +``` + +## fetch svg contents + +```elixir +icon_map = + Enum.map(icon_data, fn %{"icon_path" => path} = icon -> + svg = File.read!("./priv/system-uicons/src/images/icons/#{path}.svg") + Map.put_new(icon, "icon_svg", svg) + end) +``` diff --git a/systemuicons_ex.exs b/systemuicons_ex.exs new file mode 100644 index 0000000..fc9e8be --- /dev/null +++ b/systemuicons_ex.exs @@ -0,0 +1,3 @@ +Mix.install([ + +])