46 lines
1.2 KiB
Elixir
46 lines
1.2 KiB
Elixir
defmodule OutlookWeb.HtmlTreeComponent do
|
|
|
|
use Phoenix.Component
|
|
# use OutlookWeb, :html
|
|
import OutlookWeb.CoreComponents
|
|
|
|
alias Phoenix.LiveView.JS
|
|
|
|
attr :tree, :list, required: true
|
|
|
|
def render_tree(assigns) do
|
|
~H"""
|
|
<.tnode :for={node <- @tree} node={node} />
|
|
"""
|
|
end
|
|
|
|
def attributes(assigns) do
|
|
~H" <%= @name %>="<%= @value %>""
|
|
end
|
|
|
|
def tnode(%{node: %{status: _}} = assigns), do: ~H"<%= String.slice(@node.content, 0..20) %><%= if String.length(@node.content) > 20 do %>...<% end %><br>"
|
|
|
|
def tnode(assigns) when assigns.node.type == :element do
|
|
~H"""
|
|
<<%= @node.name %><.attributes :for={{k,v} <- @node.attributes} name={k} value={v}
|
|
/>><br>
|
|
<div class="ml-8">
|
|
<.tnode :for={child_node <- @node.content} node={child_node} />
|
|
</div>
|
|
"""
|
|
end
|
|
|
|
def tnode(assigns) when assigns.node.type == :text do
|
|
~H"""
|
|
"<%= String.slice(@node.content, 0..35) %><%= if String.length(@node.content) > 35 do %>..."<% end %><br>
|
|
"""
|
|
end
|
|
|
|
def tnode(assigns) when assigns.node.type == :comment do
|
|
~H"""
|
|
<!--<%= String.slice(@node.content, 0..35) %>
|
|
<%= if String.length(@node.content) > 35 do %>"..."<% end %>-->
|
|
"""
|
|
end
|
|
end
|