mfm-parser/lib/token/mfm.ex
Ilja ecd3f750cb Code review
* <https://ilja.space/notice/ALpd6nux5hT2nsfetM>
    * This commit: `|> fill_props(token) after the cond` in the parser
    * TODO: Don't use intention-specific data in the tokens (e.g. left is reverse, x is mfm-spinX)
* <https://ilja.space/notice/ALpcK6W59UjkIUofU8>
    * TODO: Use less files
* This commit: Change nested if-statement in mfm.ex to `cond do`
2022-07-25 09:18:22 +02:00

59 lines
1.3 KiB
Elixir

defmodule MfmParser.Token.MFM do
def to_props(opts_string) when is_binary(opts_string) do
cond do
opts_string =~ "." ->
Regex.replace(~r/^.*?\./u, opts_string, "")
|> String.trim()
|> String.split(",")
|> Enum.reduce(%{}, fn opt, acc ->
acc
|> Map.merge(
cond do
opt =~ "speed" ->
%{speed: String.replace(opt, "speed=", "")}
opt =~ "v" ->
%{v: true}
opt =~ "h" ->
%{h: true}
opt =~ "x" ->
%{axis: "x"}
opt =~ "y" ->
%{axis: "y"}
opt =~ "left" ->
%{direction: "left"}
opt =~ "alternate" ->
%{direction: "alternate"}
true ->
if Regex.match?(~r/^\$\[font/, opts_string) do
%{font: opt}
else
%{}
end
end
)
end)
opts_string =~ "$[x" ->
%{
size:
case opts_string |> String.replace("$[x", "") |> String.trim() do
"2" -> "200%"
"3" -> "400%"
"4" -> "600%"
_ -> "100%"
end
}
true ->
%{}
end
end
end