File Tree Component

Curated ago by @jeremysmithco

Description

This is a view component that renders out the file tree in the editor menu for RailsInspire.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<%= tag.ul(class: "ml-4") do %>
  <% @tree.map do |node| %>
    <%= tag.li do %>
      <% if node.last.is_a?(SampleFile) %>
        <%= link_to [node.last.sample, node.last], class: "flex items-center space-x-1 ml-5 mb-2 hover:text-blue-300" do %>
          <div><%= render "icons/heroicons/outline/document-text" %></div>
          <div><%= node.first %></div>
        <% end %>
      <% else %>
        <div class="flex items-center space-x-1 mb-1">
          <div class="flex items-center">
            <%= render "icons/heroicons/solid/chevron-down" %>
            <%= render "icons/heroicons/solid/folder" %>
          </div>

          <div><%= node.first %></div>
        </div>

        <%= render FileTreeComponent.new(node.last) %>
      <% end %>
    <% end %>
  <% end %>
<% end %>

The view component uses recursion to render children of each node.