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 Link(Content link) { var stack = new Stack <string>(); stack.Push(link.UrlPart); var current = link.Parent; while (current != null && current.Id != "root") { stack.Push(current.UrlPart); current = current.Parent; } var url = string.Concat("/", string.Join("/", stack), "/"); var builder = new EncodedStringBuilder(); builder.AppendRaw(@"<a href=""{0}"">", url); builder.AppendEncoded(link.MenuTitle); builder.AppendRaw("</a>"); return(builder.ForceRaw()); }