47 lines
1.0 KiB
Plaintext
47 lines
1.0 KiB
Plaintext
|
# 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)
|
||
|
```
|