/* Function: GenerateJSON */ public void GenerateJSON(Builders.HTML htmlBuilder, JSMenuData menu) { StringBuilder output = new StringBuilder(); output.Append("[1,\""); string htmlTitle = menuEntry.Title.ToHTML(); output.StringEscapeAndAppend(htmlTitle); output.Append('"'); string hashPath = null; if (menuEntry is MenuEntries.Files.File) { MenuEntries.Files.File fileMenuEntry = (MenuEntries.Files.File)menuEntry; HTMLTopicPages.File fileTopicPage = new HTMLTopicPages.File(htmlBuilder, fileMenuEntry.WrappedFile.ID); hashPath = fileTopicPage.OutputFileNameOnlyHashPath; } else if (menuEntry is MenuEntries.Classes.Class) { MenuEntries.Classes.Class classMenuEntry = (MenuEntries.Classes.Class)menuEntry; HTMLTopicPages.Class classTopicPage = new HTMLTopicPages.Class(htmlBuilder, classString: classMenuEntry.WrappedClassString); hashPath = classTopicPage.OutputFileNameOnlyHashPath; } #if DEBUG else { throw new Exception("Don't know how to generate JSON for target \"" + menuEntry.Title + "\"."); } #endif if (hashPath != htmlTitle) { output.Append(",\""); output.StringEscapeAndAppend(hashPath); output.Append('"'); } output.Append(']'); json = output.ToString(); }
/* Function: GenerateJSON */ public void GenerateJSON(Builders.HTML htmlBuilder, JSMenuData menu) { StringBuilder output = new StringBuilder(); output.Append("[2,"); // Title if (menuEntry.CondensedTitles == null) { if (menuEntry.Title != null) { output.Append('"'); output.StringEscapeAndAppend(menuEntry.Title.ToHTML()); output.Append('"'); } // Otherwise leave an empty space before the comma. We don't have to write out "undefined". } else { output.Append("[\""); output.StringEscapeAndAppend(menuEntry.Title.ToHTML()); output.Append('"'); foreach (string condensedTitle in menuEntry.CondensedTitles) { output.Append(",\""); output.StringEscapeAndAppend(condensedTitle.ToHTML()); output.Append('"'); } output.Append(']'); } // Hash path output.Append(','); if (menuEntry is MenuEntries.Files.FileSource) { MenuEntries.Files.FileSource fileSourceEntry = (MenuEntries.Files.FileSource)menuEntry; hashPath = htmlBuilder.Source_OutputFolderHashPath(fileSourceEntry.WrappedFileSource.Number, fileSourceEntry.CondensedPathFromFileSource); } else if (menuEntry is MenuEntries.Files.Folder) { MenuEntries.Base.Container container = menuEntry.Parent; #if DEBUG if (container == null) { throw new Exception("Parent must be defined when generating JSON for menu folder \"" + menuEntry.Title + "\"."); } #endif while ((container is MenuEntries.Files.FileSource) == false) { container = container.Parent; #if DEBUG if (container == null) { throw new Exception("Couldn't find a file source among the folder \"" + menuEntry.Title + "\"'s parents when generating JSON."); } #endif } MenuEntries.Files.Folder folderEntry = (MenuEntries.Files.Folder)menuEntry; MenuEntries.Files.FileSource fileSourceEntry = (MenuEntries.Files.FileSource)container; hashPath = htmlBuilder.Source_OutputFolderHashPath(fileSourceEntry.WrappedFileSource.Number, folderEntry.PathFromFileSource); } else if (menuEntry is MenuEntries.Classes.Language) { MenuEntries.Classes.Language languageEntry = (MenuEntries.Classes.Language)menuEntry; hashPath = htmlBuilder.Class_OutputFolderHashPath(languageEntry.WrappedLanguage, languageEntry.CondensedScopeString); } else if (menuEntry is MenuEntries.Classes.Scope) { MenuEntries.Base.Container container = menuEntry; #if DEBUG if (container == null) { throw new Exception("Parent must be defined when generating JSON for menu scope \"" + menuEntry.Title + "\"."); } #endif while ((container is MenuEntries.Classes.Language) == false && container != menu.RootDatabaseMenu) { container = container.Parent; #if DEBUG if (container == null) { throw new Exception("Couldn't find a language among the scope \"" + menuEntry.Title + "\"'s parents when generating JSON."); } #endif } MenuEntries.Classes.Scope scopeEntry = (MenuEntries.Classes.Scope)menuEntry; if (container == menu.RootDatabaseMenu) { hashPath = htmlBuilder.Database_OutputFolderHashPath(scopeEntry.WrappedScopeString); } else { MenuEntries.Classes.Language languageEntry = (MenuEntries.Classes.Language)container; hashPath = htmlBuilder.Class_OutputFolderHashPath(languageEntry.WrappedLanguage, scopeEntry.WrappedScopeString); } } else if (menuEntry == menu.RootFileMenu || menuEntry == menu.RootClassMenu) { // If we're at the root file or class menu and the entry is not also a language or file source, it means there are multiple languages and/or // file sources beneath it and thus there is no shared hash path. "CSharpClass:" and "PerlClass:", "Files:" and "Files2:", etc. hashPath = null; } else if (menuEntry == menu.RootDatabaseMenu) { // If we're at the root database menu and the entry is not also a scope, it means there are multiple scopes beneath it. However, unlike // files and classes, there is still the shared "Database:" hash path. hashPath = htmlBuilder.Database_OutputFolderHashPath(); } #if DEBUG else { throw new Exception("Don't know how to generate JSON for container \"" + menuEntry.Title + "\"."); } #endif if (hashPath != null) { output.Append('"'); output.StringEscapeAndAppend(hashPath); output.Append('"'); } // Otherwise leave an empty space before the comma. We don't have to write out "undefined". output.Append(','); jsonBeforeMembers = output.ToString(); jsonAfterMembers = "]"; }