async Task WriteEvent(ProgrammableBlockApi api, ApiEntry overload, MarkdownWriter writer, EventInfo eventInfo) { await writer.BeginCodeBlockAsync(); await writer.WriteLineAsync(overload.ToString(ApiEntryStringFlags.Modifiers | ApiEntryStringFlags.GenericParameters | ApiEntryStringFlags.ParameterTypes | ApiEntryStringFlags.ParameterNames | ApiEntryStringFlags.ReturnValue | ApiEntryStringFlags.Accessors)); await writer.EndCodeBlockAsync(); if (overload.Documentation?.Summary != null) { await WriteDocumentation(api, overload.Documentation?.Summary, writer); } await writer.WriteHeaderAsync(3, "Returns"); var returnEntry = api.GetEntry(eventInfo.EventHandlerType, true); await writer.BeginParagraphAsync(); await writer.WriteAsync(LinkTo(returnEntry.ToString(ApiEntryStringFlags.ShortDisplayName), returnEntry)); await writer.EndParagraphAsync(); if (overload.Documentation?.Returns != null) { await WriteDocumentation(api, overload.Documentation?.Returns, writer); } if (overload.Documentation?.Example != null) { await writer.WriteHeaderAsync(3, "Example"); await WriteDocumentation(api, overload.Documentation?.Example, writer); } if (overload.Documentation?.Remarks != null) { await writer.WriteHeaderAsync(3, "Remarks"); await WriteDocumentation(api, overload.Documentation?.Remarks, writer); } }
async Task WriteTypeDefinitions(ApiEntry entry, MarkdownWriter writer) { var defs = _typeDefinitions.Definitions.Where(d => d.TypeName == entry.FullName).ToList(); if (!defs.Any()) { return; } await writer.BeginParagraphAsync(); await writer.WriteLineAsync(MarkdownInline.Strong("Type Definitions: ")); var lines = defs.Select(d => d.ToString()) .OrderBy(o => o) .ToList(); foreach (var line in lines) { await writer.WriteUnorderedListItemAsync(line); } await writer.EndParagraphAsync(); }
async Task WriteMethod(ProgrammableBlockApi api, ApiEntry overload, MarkdownWriter writer, MethodInfo methodInfo) { await writer.BeginCodeBlockAsync(); await writer.WriteLineAsync(overload.ToString(ApiEntryStringFlags.Modifiers | ApiEntryStringFlags.GenericParameters | ApiEntryStringFlags.ParameterTypes | ApiEntryStringFlags.ParameterNames | ApiEntryStringFlags.ReturnValue | ApiEntryStringFlags.Accessors)); await writer.EndCodeBlockAsync(); if (overload.Documentation?.Summary != null) { await WriteDocumentation(api, overload.Documentation?.Summary, writer); } else { } if (methodInfo.ReturnType != typeof(void)) { await writer.WriteHeaderAsync(3, "Returns"); var returnEntry = api.GetEntry(methodInfo.ReturnType, true); await writer.BeginParagraphAsync(); await writer.WriteAsync(LinkTo(returnEntry.ToString(ApiEntryStringFlags.ShortDisplayName), returnEntry)); await writer.EndParagraphAsync(); if (overload.Documentation?.Returns != null) { await WriteDocumentation(api, overload.Documentation?.Returns, writer); } } var parameters = methodInfo.GetParameters(); if (parameters.Length > 0) { await writer.WriteHeaderAsync(3, "Parameters"); foreach (var parameter in parameters) { var returnEntry = api.GetEntry(parameter.GetActualParameterType(), true); await writer.WriteAsync("* "); await writer.WriteAsync(LinkTo(returnEntry.ToString(ApiEntryStringFlags.ShortDisplayName), returnEntry)); await writer.WriteAsync(" "); await writer.WriteAsync(parameter.Name); await writer.WriteLineAsync(); } } if (overload.Documentation?.Example != null) { await writer.WriteHeaderAsync(3, "Example"); await WriteDocumentation(api, overload.Documentation?.Example, writer); } if (overload.Documentation?.Remarks != null) { await writer.WriteHeaderAsync(3, "Remarks"); await WriteDocumentation(api, overload.Documentation?.Remarks, writer); } }
async Task GeneratePage(ProgrammableBlockApi api, DirectoryInfo directory, ApiEntry entry) { var fileName = Path.Combine(directory.FullName, entry.SuggestedFileName); Debug.WriteLine(entry.FullName + " " + fileName); using (var file = File.CreateText(fileName)) { var writer = new MarkdownWriter(file); await writer.BeginParagraphAsync(); await writer.WriteAsync($"← {MarkdownInline.HRef("Index", "Api-Index")} ← {MarkdownInline.HRef("Namespace Index", "Namespace-Index")}"); await writer.EndParagraphAsync(); await writer.WriteHeaderAsync(4, $"{WebUtility.HtmlEncode(entry.ToString(ApiEntryStringFlags.GenericParameters))} {ConstructOf(entry)}"); await writer.BeginCodeBlockAsync(); await writer.WriteLineAsync(entry.ToString(ApiEntryStringFlags.Modifiers | ApiEntryStringFlags.GenericParameters | ApiEntryStringFlags.Inheritance)); await writer.EndCodeBlockAsync(); if (entry.Documentation?.Summary != null) { await WriteDocumentation(api, entry.Documentation?.Summary, writer); } await writer.BeginParagraphAsync(); await writer.WriteLineAsync($"{MarkdownInline.Strong("Namespace:")} {MarkdownInline.HRef(entry.NamespaceName, Path.GetFileNameWithoutExtension(ToMdFileName(entry.NamespaceName)))}"); await writer.WriteLineAsync($"{MarkdownInline.Strong("Assembly:")} {entry.AssemblyName}.dll"); await writer.EndParagraphAsync(); if (entry.BaseEntry != null) { await WriteInheritance(entry, writer); } if (entry.InheritedEntries.Count > 0) { await WriteInterfaces(entry, writer); } if (entry.InheritorEntries.Count > 0) { await WriteInheritors(entry, writer); } await WriteTypeDefinitions(entry, writer); var obsoleteAttribute = entry.Member.GetCustomAttribute <ObsoleteAttribute>(false); if (obsoleteAttribute != null) { await writer.WriteHeaderAsync(2, "Obsolete"); await writer.BeginParagraphAsync(); await writer.WriteLineAsync("This type should no longer be used and may be removed in the future. If you're using it, you should replace it as soon as possible. "); await writer.WriteAsync(obsoleteAttribute.Message); await file.WriteLineAsync(); } if (entry.Documentation?.Example != null) { await writer.WriteHeaderAsync(4, "Example"); await WriteDocumentation(api, entry.Documentation?.Example, writer); } if (entry.Documentation?.Remarks != null) { await writer.WriteHeaderAsync(4, "Remarks"); await WriteDocumentation(api, entry.Documentation?.Remarks, writer); } await WriteMembers(api, entry, writer); await writer.FlushAsync(); } }
private async Task GenerateAsync(string path, string output) { var loader = new TextureLoader(); var dir = Path.GetDirectoryName(output) ?? ".\\"; using (var file = File.CreateText(output)) { var writer = new MarkdownWriter(file); await writer.WriteLineAsync("All images are copyright © Keen Software House."); await writer.WriteRulerAsync(); await writer.BeginParagraphAsync(); await writer.WriteAsync("See "); await writer.WriteLinkAsync("Whiplash' nice little tool", "https://gitlab.com/whiplash141/spritebuilder"); await writer.WriteLineAsync(" for visually designing sprites and generating the code to display them."); await writer.EndParagraphAsync(); await writer.BeginTableAsync("Id", "Size", "Thumbnail"); int n = 1; foreach (var sprite in _icons.OrderBy(i => i.Id)) { await writer.BeginTableCellAsync(); await writer.WriteAsync(sprite.Id); await writer.EndTableCellAsync(); var texture = loader.LoadTextureScratch(sprite.Path); if (texture != null) { var image0 = texture.GetImage(0); await writer.BeginTableCellAsync(); await writer.WriteAsync($"{image0.Width}x{image0.Height}"); await writer.EndTableCellAsync(); var hScale = 64.0 / image0.Width; var vScale = 64.0 / image0.Height; var scale = Math.Min(hScale, vScale); if (scale < 1.0) { var width = (int)(image0.Width * scale); var height = (int)(image0.Height * scale); var thumbnail = texture.Resize(width, height, TEX_FILTER_FLAGS.CUBIC); texture.Dispose(); texture = thumbnail; } var thumbnailFile = $@"images\spritethumb_{n}.jpg"; n++; var thumbnailPath = Path.Combine(dir, thumbnailFile); texture.SaveToJPGFile(0, 1, thumbnailPath); await writer.BeginTableCellAsync(); await writer.WriteImageLinkAsync(sprite.Id, thumbnailFile.Replace("\\", "/")); await writer.EndTableCellAsync(); texture.Dispose(); } else { await writer.BeginTableCellAsync(); await writer.WriteAsync("?x?"); await writer.EndTableCellAsync(); await writer.BeginTableCellAsync(); await writer.WriteAsync("Sprite Not Found! Bad Definition?"); await writer.EndTableCellAsync(); } } await writer.EndTableAsync(); } }