Div cmdGetMain(ModuleInfo module) { var main = new Div(cls: "markdown-11q6EU"); if (module == null) { main.Children.Add(msgBox("error", "There is no module by that name.")); return(main); } main.Children.Add(linkHeader(1, module.Name)); if (module.Summary != null) { main.Children.Add(docParagraph().WithRawText(module.Summary)); } if (module.Preconditions.Count > 0) { main.Children.Add(explainPreconditions(true, module.Preconditions.ToArray())); } foreach (var x in module.Commands) { var req = new HttpReqUrl(x.Aliases.First(), x.Name); foreach (var param in x.Parameters) { req.AddParam(param); } main.Children.Add(req.ToHtml()); if (x.Summary != null) { main.Children.Add(docParagraph().WithRawText(x.Summary)); } if (x.Preconditions.Count > 0) { main.Children.Add(explainPreconditions(false, x.Preconditions.ToArray())); } } return(main); }
Div getSidebarAPI(string selected) { var section = new Div(cls: "section-X9hK_F"); section.Children.Add(new Paragraph("API routes", cls: "heading-10iJKV marginBottom8-1wldKw small-29zrCQ size12-DS9Pyp" + " height16-3r2Q2W primary200-1Ayq8L weightSemiBold-tctXJ7 uppercase-1K74Lz")); var list = new UnorderedList(cls: "mainList-otExiM"); section.Children.Add(list); var modules = new Dictionary <string, List <APIEndpoint> >(); foreach (var ep in Handler.Endpoints.Values) { foreach (var cmd in ep) { var name = cmd.Module.Name; if (modules.TryGetValue(name, out var epLs)) { epLs.Add(cmd); } else { modules[name] = new List <APIEndpoint>() { cmd } }; } } foreach (var keypair in modules) { var href = $"/docs/api/{escapeForUrl(keypair.Key)}"; var anchor = new Anchor(href, text: keypair.Key, cls: "navLink-1Neui4 navLinkSmall-34Tbhm"); list.Children.Add(new ListItem(null) { Children = { anchor } }); if (escapeForUrl(keypair.Key) == selected) { anchor.ClassList.Add("activeLink-22b0_I"); var spy = new Div(cls: "ScrollSpy"); list.Children.Add(spy); foreach (var cmd in keypair.Value) { var name = cmd.Name; list.Children.Add(new Anchor($"{href}#{escapeForUrl(name)}", name, cls: "anchor-3Z-8Bb subLink-3M1J2_")); } } } return(section); } string getRegexPattern(System.Reflection.ParameterInfo info) { var attr = info.GetCustomAttribute <RegexAttribute>(); if (attr != null) { return(attr.Regex); } var attrs = info.Member.GetCustomAttributes <RegexAttribute>(); return(attrs.FirstOrDefault(x => x.Name == info.Name)?.Regex); } Table getTableOfParams(System.Reflection.ParameterInfo[] parameters) { var table = new Table(); table.Children.Add(new TableRow() { Children = { new TableHeader("Field").WithTag("scope", "col"), new TableHeader("Type").WithTag("scope", "col"), new TableHeader("Description").WithTag("scope", "col"), } }); foreach (var p in parameters) { var typeName = Program.GetTypeName(p.ParameterType, out var isNullable); var typeText = (isNullable ? "?" : "") + typeName; var summary = p.GetCustomAttribute <SummaryAttribute>()?.Text; var regex = getRegexPattern(p); if (regex != null) { summary = summary == null ? $"Must match regex: <code>{regex}</code>" : summary + $"<hr/>Must match regex: <code>{regex}</code>"; } if (string.IsNullOrWhiteSpace(summary)) { summary = "None"; } table.Children.Add(new TableRow() { Children = { new TableData(p.Name + (p.IsOptional ? "?" : "")), new TableData(typeText), new TableData(summary) } }); } return(table); } Div apiGetMain(APIModule module) { var main = new Div(cls: "markdown-11q6EU"); if (module == null) { main.Children.Add(msgBox("error", "There is no module by that name.")); return(main); } main.Children.Add(linkHeader(1, module.Name)); if (module.Summary != null) { main.Children.Add(docParagraph().WithRawText(module.Summary)); } if (module.Preconditions.Count > 0) { main.Children.Add(explainPreconditions(true, module.Preconditions.ToArray())); } foreach (var x in module.Endpoints) { var paramaters = x.Function.GetParameters(); var link = Handler.RelativeLink(x.Function, paramaters.Select(x => x.Name).ToArray()); var req = new HttpReqUrl(x.Method, x.Name, link: link); var path = x.GetNicePath().Split('/', StringSplitOptions.RemoveEmptyEntries); var pathParams = new List <string>(); foreach (var section in path) { req.AddPath("/"); if (section.StartsWith("{")) { var name = section[1..^ 1]; var p = paramaters.FirstOrDefault(x => x.Name == name); pathParams.Add(name); req.AddParam(p, withSpace: false); }