Sha256: 2cebc526d274283db3344e1ba323f31b565d0ba395dd06264d42963a4b81f7d5

Contents?: true

Size: 998 Bytes

Versions: 1

Compression:

Stored size: 998 Bytes

Contents

<%
  # Props
  title = local_assigns.fetch(:title, nil)
  root = local_assigns.fetch(:root, nil)
  current = local_assigns.fetch(:current, nil)
  depth = local_assigns.fetch(:depth, 1)
  base_class = local_assigns.fetch(:base_class, nil)

  # Methods
  def tree(root_taxon, current_taxon, base_class, max_level = 1)
    return '' if max_level < 1 || root_taxon.children.empty?
    content_tag :ul, class: base_class do
      taxons = root_taxon.children.map do |taxon|
        css_class = (current_taxon && current_taxon.self_and_ancestors.include?(taxon)) ? 'current' : nil
        content_tag :li, class: css_class do
         link_to(taxon.name, seo_url(taxon)) +
           tree(taxon, current_taxon, nil, max_level - 1)
        end
      end
      safe_join(taxons, "\n")
    end
  end
%>

<% taxons_list = tree(root, current, "#{base_class}__list", depth) %>
<% if taxons_list.present? %>
  <%= content_tag :h6, title, class: "#{base_class}__title" if title %>
  <%= taxons_list %>
<% end %>

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
solidus_starter_frontend-0.1.0 app/views/spree/components/navigation/_taxons_tree.html.erb