Add importing html and save it to Article

Additionally defines a wizard logic which is partially unused yet.
This commit is contained in:
Thelonius Kort
2022-12-29 16:43:52 +01:00
parent 60a22d011e
commit b7bd9195b6
24 changed files with 452 additions and 25 deletions

View File

@ -0,0 +1,52 @@
defmodule Outlook.Articles.InternalTree do
use Ecto.Type
alias Outlook.InternalTree.InternalNode
alias Outlook.InternalTree.TranslationUnit
def type, do: :string
def cast(tree) when is_list(tree) do
{:ok, tree}
end
def cast(_), do: :error
def load(tree) when is_binary(tree) do
{:ok, Jason.decode!(tree, keys: :atoms!) |> from_json}
end
def dump(tree) when is_list(tree), do: {:ok, Jason.encode!(tree)}
def dump(_), do: :error
defp from_json([%{status: _} = node | rest]) do
[ %TranslationUnit{
status: String.to_atom(node.status),
uuid: node.uuid,
content: node.content
} | from_json(rest) ]
end
defp from_json([%{type: "element"} = node | rest]) do
[ %InternalNode{
name: node.name,
attributes: node.attributes,
type: String.to_atom(node.type),
uuid: node.uuid,
content: from_json(node.content)
} | from_json(rest) ]
end
defp from_json([%{type: _} = node | rest]) do
[ %InternalNode{
name: node.name,
attributes: node.attributes,
type: String.to_atom(node.type),
uuid: node.uuid,
content: node.content
} | from_json(rest) ]
end
defp from_json([]), do: []
end