Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9,187 changed files
with
15,842 additions
and
148 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
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
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
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,26 @@ | ||
defmodule Mix.Tasks.PhxWc.GenIcons do | ||
# Generate Material Design Icons | ||
# try to define with macro, it's too slow | ||
|
||
@moduledoc """ | ||
Generate Phoenix.WebComponent.MaterialDesignIcons fron 7000+ svg files | ||
""" | ||
use Mix.Task | ||
|
||
@shortdoc "Generate Phoenix.WebComponent.MaterialDesignIcons.ex file" | ||
def run(_) do | ||
Mix.Task.run("app.start") | ||
|
||
icons = | ||
File.ls!(Application.app_dir(:phoenix_webcomponent, "priv/mdi/svg")) | ||
|> Enum.filter(&String.ends_with?(&1, ".svg")) | ||
|> Enum.map(&String.trim(&1, ".svg")) | ||
|
||
quoted = EEx.compile_file("#{__DIR__}/material_design_icons.eex") | ||
{result, _bindings} = Code.eval_quoted(quoted, icons: icons) | ||
|
||
fl = Path.expand("../../phoenix_webcomponent/material_design_icons.ex", __DIR__) | ||
|
||
File.write!(fl, result) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
defmodule Mix.Tasks.PhxWc.GenRsIcons do | ||
# Generate Material Design Icons and Bootstrap Icons to yew components | ||
|
||
@moduledoc """ | ||
Generate mdi.rs or bsi.rs fron svg files. | ||
""" | ||
use Mix.Task | ||
|
||
@shortdoc "Generate mdi.rs or bsi.rs file" | ||
def run(["mdi"]) do | ||
Mix.Task.run("app.start") | ||
|
||
ns = "MD" | ||
|
||
icons = | ||
File.ls!(Application.app_dir(:phoenix_webcomponent, "priv/mdi/svg")) | ||
|> Enum.filter(&String.ends_with?(&1, ".svg")) | ||
|> Enum.map(&String.trim(&1, ".svg")) | ||
|
||
icon_names = | ||
icons | ||
|> Enum.map(fn name -> | ||
name |> String.split("-") |> Enum.map(&String.capitalize/1) |> Enum.join("") | ||
end) | ||
|
||
wd = Path.expand("../../../mdi", __DIR__) | ||
File.mkdir_p!(wd) | ||
|
||
quoted = EEx.compile_file("#{__DIR__}/yew_icon_mod.eex") | ||
{result, _bindings} = Code.eval_quoted(quoted, icons: icons, icon_names: icon_names, ns: ns) | ||
fl = "#{wd}/mod.rs" | ||
File.write!(fl, result) | ||
|
||
quoted = EEx.compile_file("#{__DIR__}/yew_icon_props.eex") | ||
{result, _bindings} = Code.eval_quoted(quoted, ns: ns) | ||
fl = "#{wd}/props.rs" | ||
File.write!(fl, result) | ||
|
||
icons | ||
|> Enum.each(fn name -> | ||
inner = | ||
File.read!(Application.app_dir(:phoenix_webcomponent, "priv/mdi/svg/#{name}.svg")) | ||
|> String.replace(~r/<svg[^>]+>/, "") | ||
|> String.replace("</svg>", "") | ||
|> String.trim() | ||
|
||
quoted = EEx.compile_file("#{__DIR__}/yew_icon_item.eex") | ||
|
||
{result, _bindings} = | ||
Code.eval_quoted(quoted, ns: ns, name: name, inner: inner, vb: "0 0 24 24") | ||
|
||
fl = "#{wd}/icon_#{name |> String.replace("-", "_")}.rs" | ||
File.write!(fl, result) | ||
end) | ||
|
||
quoted = EEx.compile_file("#{__DIR__}/yew_icon_names.eex") | ||
|
||
{result, _bindings} = | ||
Code.eval_quoted(quoted, icons: icons, icon_names: icon_names, ns: ns, mod_name: "mdi") | ||
|
||
fl = "#{wd}/mdi_names.rs" | ||
File.write!(fl, result) | ||
end | ||
|
||
def run(["bsi"]) do | ||
Mix.Task.run("app.start") | ||
|
||
ns = "BS" | ||
|
||
icons = | ||
File.ls!(Application.app_dir(:phoenix_webcomponent, "priv/bsi/svg")) | ||
|> Enum.filter(&String.ends_with?(&1, ".svg")) | ||
|> Enum.map(&String.trim(&1, ".svg")) | ||
|
||
icon_names = | ||
icons | ||
|> Enum.map(fn name -> | ||
name |> String.split("-") |> Enum.map(&String.capitalize/1) |> Enum.join("") | ||
end) | ||
|
||
wd = Path.expand("../../../bsi", __DIR__) | ||
File.mkdir_p!(wd) | ||
|
||
quoted = EEx.compile_file("#{__DIR__}/yew_icon_mod.eex") | ||
{result, _bindings} = Code.eval_quoted(quoted, icons: icons, icon_names: icon_names, ns: ns) | ||
fl = "#{wd}/mod.rs" | ||
File.write!(fl, result) | ||
|
||
quoted = EEx.compile_file("#{__DIR__}/yew_icon_props.eex") | ||
{result, _bindings} = Code.eval_quoted(quoted, ns: ns) | ||
fl = "#{wd}/props.rs" | ||
File.write!(fl, result) | ||
|
||
icons | ||
|> Enum.each(fn name -> | ||
inner = | ||
File.read!(Application.app_dir(:phoenix_webcomponent, "priv/bsi/svg/#{name}.svg")) | ||
|> String.replace(~r/<svg[^>]+>/, "") | ||
|> String.replace("</svg>", "") | ||
|> String.trim() | ||
|
||
quoted = EEx.compile_file("#{__DIR__}/yew_icon_item.eex") | ||
|
||
{result, _bindings} = | ||
Code.eval_quoted(quoted, ns: ns, name: name, inner: inner, vb: "0 0 16 16") | ||
|
||
fl = "#{wd}/icon_#{name |> String.replace("-", "_")}.rs" | ||
File.write!(fl, result) | ||
end) | ||
|
||
quoted = EEx.compile_file("#{__DIR__}/yew_icon_names.eex") | ||
|
||
{result, _bindings} = | ||
Code.eval_quoted(quoted, icons: icons, icon_names: icon_names, ns: ns, mod_name: "bsi") | ||
|
||
fl = "#{wd}/bsi_names.rs" | ||
File.write!(fl, result) | ||
end | ||
|
||
def run(_) do | ||
IO.puts("Use `mix phx_wc.gen_rs_icons bsi` or `mix phx_wc.gen_rs_icons mdi`") | ||
end | ||
end |
28 changes: 28 additions & 0 deletions
28
apps/phoenix_webcomponent/lib/mix/tasks/material_design_icons.eex
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,28 @@ | ||
defmodule Phoenix.WebComponent.MaterialDesignIcons do | ||
@moduledoc """ | ||
Render 7000+ Material Design Icons | ||
""" | ||
use Phoenix.WebComponent, :html | ||
|
||
# alias Phoenix.LiveView.JS | ||
|
||
@icons ~W(<%= icons |> Enum.join(" ") %>) | ||
|
||
@spec icons() :: [String.t()] | ||
def icons(), do: @icons | ||
|
||
<%= for name <- icons do %> | ||
def <%= String.replace(name, "-", "_") %>(assigns) do | ||
assigns = | ||
assigns | ||
|> assign_new(:id, fn -> false end) | ||
|> assign_new(:class, fn -> false end) | ||
|
||
~H""" | ||
<svg xmlns="http://www.w3.org/2000/svg" id={@id} class={@class} viewBox="0 0 24 24"> | ||
<%= File.read!(Application.app_dir(:phoenix_webcomponent, "priv/mdi/svg/#{name}.svg")) |> String.replace(~r/<svg[^>]+>/, "") |> String.replace("</svg>", "") %> | ||
</svg> | ||
""" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#![allow(non_camel_case_types)] | ||
|
||
use yew::prelude::*; | ||
use super::props::IconProps; | ||
|
||
#[function_component(<%= ns %>_<%= name |> String.split("-") |> Enum.map(&String.capitalize/1) |> Enum.join("") %>)] | ||
pub fn r#icon_<%= String.replace(name, "-", "_") %>(props: &IconProps) -> Html { | ||
let owned_props = props.clone(); | ||
|
||
html! { | ||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="<%= vb %>" id={owned_props.id} class={owned_props.class} width={owned_props.size} fill={owned_props.color} style={owned_props.style}> | ||
<%= inner %> | ||
</svg> | ||
} | ||
} |
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,6 @@ | ||
pub mod props; | ||
pub use self::props::IconProps; | ||
|
||
<%= for {name, idx} <- Enum.with_index(icons) do %>pub mod icon_<%= name |> String.replace("-", "_") %>; | ||
pub use self::icon_<%= name |> String.replace("-", "_") %>::<%= ns %>_<%= Enum.at(icon_names, idx) %>; | ||
<% end %> |
22 changes: 22 additions & 0 deletions
22
apps/phoenix_webcomponent/lib/mix/tasks/yew_icon_names.eex
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,22 @@ | ||
use yew::prelude::*; | ||
|
||
use super::<%= mod_name %>::IconProps; | ||
|
||
<%= for name <- icon_names do %>use super::<%= mod_name %>::<%= ns %>_<%= name %>; | ||
<% end %> | ||
|
||
pub const NAMES: [&str; <%= icon_names |> length() %>] = [ | ||
<%= for name <- icon_names do %> "<%= name %>", | ||
<% end %> | ||
]; | ||
|
||
#[function_component(<%= ns %>Icon)] | ||
pub fn icon(props: &IconProps) -> Html { | ||
let owned_props = props.clone(); | ||
match owned_props.name { | ||
<%= for name <- icon_names do %> implicit_clone::unsync::IString::Static("<%= name %>") => html! { | ||
<<%= ns %>_<%= name %> ..owned_props /> | ||
}, | ||
<% end %> _ => html! {}, | ||
} | ||
} |
Oops, something went wrong.