private static void Tree(EncodedStringBuilder builder, Content node, string currentId, IReadOnlyList <Content> expanded, int depth) { var active = false; var isExpanded = expanded.Any(x => x.Id == node.Id); if (node.Id == currentId || isExpanded && depth == 0) { active = true; } if (depth == 0) { builder.AppendRaw(active ? @"<li class=""active"">" : @"<li>"); } else { builder.AppendRaw(@"<li class=""list-unstyled"">"); } if (active && depth > 0) { builder.AppendRaw(@"<b>"); } var link = node.GetLink(); if (link == "/index") { link = "/"; } builder.AppendRaw(@"<a href=""{0}"">", link); builder.AppendEncoded(node.MenuTitle); builder.AppendRaw(@"</a>"); if (active && depth > 0) { builder.AppendRaw(@"</b>"); } if (node.Children.Count > 0) { if (isExpanded) { builder.AppendRawLine("<ul>"); depth++; foreach (var child in node.Children) { Tree(builder, child, currentId, expanded, depth); } builder.AppendRawLine("</ul>"); } } builder.AppendRaw(@"</li>"); }
public IEncodedString Tree(Content tree, string currentId) { var node = tree.Find(currentId); var expandedNodes = node.GetParents(); var builder = new EncodedStringBuilder(); builder.AppendRawLine(@"<ul class=""nav nav-sidebar"">"); foreach (var child in tree.Children) { Tree(builder, child, currentId, expandedNodes, 0); } builder.AppendRawLine("</ul>"); return(builder.ForceRaw()); }