Files
phoenix-ausblick/lib/outlook_web/components/html_tree_component.ex
2023-05-03 22:37:43 +02:00

51 lines
1.2 KiB
Elixir

defmodule OutlookWeb.HtmlTreeComponent do
use Phoenix.Component
# use OutlookWeb, :html
import OutlookWeb.CoreComponents
import OutlookWeb.ViewHelpers
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"&nbsp; <%= @name %>=&quot;<%= elipsed_text(@value, 16) %>&quot;"
end
def tnode(%{node: %{status: _}} = assigns) do
~H"""
<span title={@node.content} {@node.eph.attributes}><%= elipsed_text(@node.content, 30) %></span><br>
"""
end
def tnode(assigns) when assigns.node.type == :element do
~H"""
&lt;<%= @node.name %><.attributes :for={{k,v} <- @node.attributes} name={k} value={v}
/>&gt;<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"""
"<%= elipsed_text(@node.content, 30) %><br>
"""
end
def tnode(assigns) when assigns.node.type == :comment do
~H"""
&lt;!--<%= String.slice(@node.content, 0..35) %>
<%= if String.length(@node.content) > 35 do %>"..."<% end %>--&gt;
"""
end
end