Commit ce7b754f authored by Tobias Schmidt's avatar Tobias Schmidt

Clean up navigation helper

parent 2efaf1a0
......@@ -5,7 +5,7 @@
<div class="col-md-3 side-nav-col">
<ul class="nav navbar-nav side-nav">
<% @items['/docs/'].children.sort_by { |i| i[:sort_rank] || 0 }.each do |i| %>
<%= nav(i, @item) %>
<%= nav(i) %>
<% end %>
</ul>
</div>
......
def nav_title_of(i)
i[:nav_title] || i[:title] || ''
end
def nav(root_item, focused_item, buffer='', layer=0)
# Skip non-written or hidden items
def nav(root_item, buffer='', layer=0)
return buffer if root_item.nil? || root_item.path.nil? || root_item[:is_hidden]
# Open list element
is_active = @item_rep && @item_rep.path == root_item.path
if is_active
if nav_active?(root_item)
buffer << "<li class=\"active\">"
else
buffer << "<li>"
......@@ -16,29 +9,36 @@ def nav(root_item, focused_item, buffer='', layer=0)
title = nav_title_of(root_item)
if layer == 0
# Add section header.
buffer << "<span class=\"nav-header\"><i class=\"fa fa-#{root_item[:nav_icon]}\"></i> #{title}</span>"
else
# Add link.
buffer << link_to(title, root_item.path)
end
# Add children to sitemap, recursively
visible_children = root_item.children.select { |child| !child[:is_hidden] && child.path }
visible_children = visible_children.sort_by { |child| child[:sort_rank] || 0 }
if visible_children.size > 0
children = nav_children(root_item)
if children.any?
buffer << '<ul class="nav">'
visible_children.each do |child|
nav(child, focused_item, buffer, layer + 1)
children.each do |child|
nav(child, buffer, layer + 1)
end
buffer << '</ul>'
end
# Close list element
buffer << '</li>'
# Return sitemap
buffer
end
def nav_active?(item)
@item_rep.respond_to?(:path) && @item_rep.path == item.path
end
def nav_title_of(i)
i[:nav_title] || i[:title] || ''
end
def nav_children(item)
item.children
.select { |child| !child[:is_hidden] && child.path }
.sort_by { |child| child[:sort_rank] || 0 }
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment