diff --git a/lib/parser.ex b/lib/parser.ex index dcf37f6..91493e3 100644 --- a/lib/parser.ex +++ b/lib/parser.ex @@ -63,22 +63,23 @@ defmodule MfmParser.Parser do defp get_node(token = %{content: content}) do cond do - content =~ "$[flip" -> %Node.MFM.Flip{} |> fill_props(token) - content =~ "$[font" -> %Node.MFM.Font{} |> fill_props(token) - content =~ "$[x" -> %Node.MFM.X{} |> fill_props(token) - content =~ "$[blur" -> %Node.MFM.Blur{} |> fill_props(token) - content =~ "$[jelly" -> %Node.MFM.Jelly{} |> fill_props(token) - content =~ "$[tada" -> %Node.MFM.Tada{} |> fill_props(token) - content =~ "$[jump" -> %Node.MFM.Jump{} |> fill_props(token) - content =~ "$[bounce" -> %Node.MFM.Bounce{} |> fill_props(token) - content =~ "$[spin" -> %Node.MFM.Spin{} |> fill_props(token) - content =~ "$[shake" -> %Node.MFM.Shake{} |> fill_props(token) - content =~ "$[twitch" -> %Node.MFM.Twitch{} |> fill_props(token) - content =~ "$[rainbow" -> %Node.MFM.Rainbow{} |> fill_props(token) - content =~ "$[sparkle" -> %Node.MFM.Sparkle{} |> fill_props(token) - content =~ "$[rotate" -> %Node.MFM.Rotate{} |> fill_props(token) - true -> %Node.MFM.Undefined{} |> fill_props(token) + content =~ "$[flip" -> %Node.MFM.Flip{} + content =~ "$[font" -> %Node.MFM.Font{} + content =~ "$[x" -> %Node.MFM.X{} + content =~ "$[blur" -> %Node.MFM.Blur{} + content =~ "$[jelly" -> %Node.MFM.Jelly{} + content =~ "$[tada" -> %Node.MFM.Tada{} + content =~ "$[jump" -> %Node.MFM.Jump{} + content =~ "$[bounce" -> %Node.MFM.Bounce{} + content =~ "$[spin" -> %Node.MFM.Spin{} + content =~ "$[shake" -> %Node.MFM.Shake{} + content =~ "$[twitch" -> %Node.MFM.Twitch{} + content =~ "$[rainbow" -> %Node.MFM.Rainbow{} + content =~ "$[sparkle" -> %Node.MFM.Sparkle{} + content =~ "$[rotate" -> %Node.MFM.Rotate{} + true -> %Node.MFM.Undefined{} end + |> fill_props(token) end defp fill_props(node = %{props: props}, %{content: content}) do diff --git a/lib/token/mfm.ex b/lib/token/mfm.ex index 864850e..4e555bd 100644 --- a/lib/token/mfm.ex +++ b/lib/token/mfm.ex @@ -1,45 +1,46 @@ defmodule MfmParser.Token.MFM do def to_props(opts_string) when is_binary(opts_string) do - if opts_string =~ "." do - 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=", "")} + 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 =~ "v" -> + %{v: true} - opt =~ "h" -> - %{h: true} + opt =~ "h" -> + %{h: true} - opt =~ "x" -> - %{keyframes_name: "mfm-spinX"} + opt =~ "x" -> + %{axis: "x"} - opt =~ "y" -> - %{keyframes_name: "mfm-spinY"} + opt =~ "y" -> + %{axis: "y"} - opt =~ "left" -> - %{direction: "reverse"} + opt =~ "left" -> + %{direction: "left"} - opt =~ "alternate" -> - %{direction: "alternate"} + opt =~ "alternate" -> + %{direction: "alternate"} - true -> - if Regex.match?(~r/^\$\[font/, opts_string) do - %{font: opt} - else - %{} - end - end - ) - end) - else - if opts_string =~ "$[x" do + 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 @@ -49,9 +50,9 @@ defmodule MfmParser.Token.MFM do _ -> "100%" end } - else + + true -> %{} - end end end end