-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor file structure, add octicon
- Loading branch information
1 parent
6b02112
commit 79a2568
Showing
14 changed files
with
5,577 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
defmodule PrimerLive.Helpers.Octicons do | ||
@moduledoc false | ||
|
||
require EEx | ||
|
||
@priv_path "priv/octicon_builder" | ||
@module_path "lib/octicons.ex" | ||
|
||
EEx.function_from_file( | ||
:defp, | ||
:module_wrapper, | ||
"#{@priv_path}/PrimerLive.Octicons.template.eex", | ||
[:icons] | ||
) | ||
|
||
def build() do | ||
with {:ok, filenames} <- File.ls("#{@priv_path}/icons") do | ||
with true <- Enum.count(filenames) > 0 do | ||
else | ||
_ -> | ||
IO.inspect("Could not proceed: directory '#{@priv_path}/icons' is empty.") | ||
end | ||
|
||
icons = | ||
filenames | ||
|> Enum.map( | ||
&%{ | ||
svg: | ||
File.read!("#{@priv_path}/icons/#{&1}") | ||
|> String.replace(~r/\<svg/, "<svg class={@class} {@extra}"), | ||
name: &1 |> String.replace(".svg", ""), | ||
function_name: &1 |> String.replace(".svg", "") |> String.replace("-", "_") | ||
} | ||
) | ||
|
||
result = module_wrapper(icons) | ||
|
||
with :ok <- File.write(@module_path, result) do | ||
IO.puts("PrimerLive.Octicons module written") | ||
else | ||
error -> | ||
IO.puts("Error writing PrimerLive.Octicons module") | ||
error | ||
end | ||
else | ||
_error -> | ||
IO.inspect("Could not read directory '#{@priv_path}/icons'. Does this directory exist?") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.