Add HtmlDocComponent to render the InternalTree
Very basic but promising.
This commit is contained in:
45
lib/outlook_web/components/html_doc_component.ex
Normal file
45
lib/outlook_web/components/html_doc_component.ex
Normal file
@ -0,0 +1,45 @@
|
||||
defmodule OutlookWeb.HtmlDocComponent do
|
||||
|
||||
use Phoenix.Component
|
||||
# use OutlookWeb, :html
|
||||
import OutlookWeb.CoreComponents
|
||||
import Phoenix.HTML
|
||||
|
||||
alias Phoenix.LiveView.JS
|
||||
|
||||
attr :tree, :list, required: true
|
||||
|
||||
def render_doc(assigns) do
|
||||
~H"""
|
||||
<%= for node <- @tree do %>
|
||||
<.dnode node={node} />
|
||||
<% end %>
|
||||
"""
|
||||
end
|
||||
|
||||
def dnode(%{node: %{status: status}} = assigns) do
|
||||
~H"""
|
||||
<span class="tunit" uuid={@node.uuid}>
|
||||
<%= @node.content |> raw %>
|
||||
</span>
|
||||
"""
|
||||
end
|
||||
|
||||
def dnode(assigns) when assigns.node.type == :element do
|
||||
~H"""
|
||||
<.dynamic_tag name={@node.name} uuid={@node.uuid}>
|
||||
<%= for child_node <- @node.content do %>
|
||||
<.dnode node={child_node} />
|
||||
<% end %>
|
||||
</.dynamic_tag>
|
||||
"""
|
||||
end
|
||||
|
||||
def dnode(assigns) when assigns.node.type == :text do
|
||||
~H"<%= @node.content %>"
|
||||
end
|
||||
|
||||
def dnode(assigns) when assigns.node.type == :comment do
|
||||
~H"<!--<%= @node.content |> raw %>-->"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user