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 %>
" def tnode(assigns) when assigns.node.type == :element do ~H""" <<%= @node.name %><.attributes :for={{k,v} <- @node.attributes} name={k} value={v} />>
<.tnode :for={child_node <- @node.content} node={child_node} />
""" 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 %>
""" 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