// Group: Support Functions // __________________________________________________________________________ /* Function: AppendPrototype * Covers both prototypes and class prototypes. */ protected void AppendPrototype(StringBuilder output) { var commentType = EngineInstance.CommentTypes.FromID(context.Topic.CommentTypeID); bool builtPrototype = false; if (commentType.Flags.ClassHierarchy) { ParsedClassPrototype parsedClassPrototype = context.Topic.ParsedClassPrototype; if (parsedClassPrototype != null) { if (classPrototypeBuilder == null) { classPrototypeBuilder = new HTML.Components.ClassPrototype(context); } classPrototypeBuilder.AppendClassPrototype(parsedClassPrototype, context, true, output); builtPrototype = true; } } if (builtPrototype == false) { if (prototypeBuilder == null) { prototypeBuilder = new HTML.Components.Prototype(context); } prototypeBuilder.AppendPrototype(context.Topic.ParsedPrototype, context, output); } }
/* Function: BuildClassPrototype * * Builds the HTML for the passed prototype. * * In order to have an inheritance diagram, links must contain the all the ClassParent links from the prototype's class * to its parents, and all the ClassParent links from child classes to the prototype's class. * * Requirements: * * - The <Context>'s topic and topic page must be set. */ public string BuildClassPrototype(ParsedClassPrototype parsedPrototype, Context context, bool isToolTip, IList <Link> links = null, IList <Topics.Topic> linkTargets = null) { StringBuilder output = new StringBuilder(); AppendClassPrototype(parsedPrototype, context, isToolTip, output, links, linkTargets); return(output.ToString()); }
/* Function: BuildPrototype */ protected void BuildPrototype() { bool builtPrototype = false; if (EngineInstance.CommentTypes.FromID(topic.CommentTypeID).Flags.ClassHierarchy) { ParsedClassPrototype parsedClassPrototype = topic.ParsedClassPrototype; if (parsedClassPrototype != null) { if (cachedHTMLClassPrototypeBuilder == null) { cachedHTMLClassPrototypeBuilder = new HTMLClassPrototype(topicPage); } if (isToolTip) { cachedHTMLClassPrototypeBuilder.Build(topic, true, null, null, htmlOutput); } else { cachedHTMLClassPrototypeBuilder.Build(topic, false, links, linkTargets, htmlOutput); } builtPrototype = true; } } if (builtPrototype == false) { if (cachedHTMLPrototypeBuilder == null) { cachedHTMLPrototypeBuilder = new HTMLPrototype(topicPage); } if (isToolTip) { cachedHTMLPrototypeBuilder.Build(topic, null, null, htmlOutput); } else { cachedHTMLPrototypeBuilder.Build(topic, links, linkTargets, htmlOutput); } } }
/* Function: ParseClassPrototype * Converts a raw text prototype into a <ParsedClassPrototype>. Will return null if it is not an appropriate prototype. */ override public ParsedClassPrototype ParseClassPrototype(string stringPrototype, int commentTypeID) { if (EngineInstance.CommentTypes.FromID(commentTypeID).Flags.ClassHierarchy == false) { return(null); } Tokenizer tokenizedPrototype = new Tokenizer(stringPrototype, tabWidth: EngineInstance.Config.TabWidth); TokenIterator startOfPrototype = tokenizedPrototype.FirstToken; ParsedClassPrototype parsedPrototype = new ParsedClassPrototype(tokenizedPrototype); bool success = false; success = TryToSkipClassDeclarationLine(ref startOfPrototype, ParseMode.ParseClassPrototype); if (success) { return(parsedPrototype); } else { return(base.ParseClassPrototype(stringPrototype, commentTypeID)); } }
/* Function: AppendClassPrototype * * Builds the HTML for the passed prototype and appends it to the passed StringBuilder. * * In order to have an inheritance diagram, links must contain the all the ClassParent links from the prototype's class * to its parents, and all the ClassParent links from child classes to the prototype's class. * * Requirements: * * - The <Context>'s topic and topic page must be set. */ public void AppendClassPrototype(ParsedClassPrototype parsedPrototype, Context context, bool isToolTip, StringBuilder output, IList <Link> links = null, IList <Topics.Topic> linkTargets = null) { this.parsedClassPrototype = parsedPrototype; this.context = context; this.language = EngineInstance.Languages.FromID(context.Topic.LanguageID); this.links = links; this.linkTargets = linkTargets; this.isToolTip = isToolTip; if (parsedPrototype.Tokenizer.HasSyntaxHighlighting == false) { language.SyntaxHighlight(parsedPrototype); } if (isToolTip) { output.Append("<div class=\"NDClassPrototype\" id=\"NDClassPrototype" + context.Topic.TopicID + "\">"); AppendCurrentClassPrototype(output); output.Append("</div>"); } else { List <Parent> parents = GetParentList(); List <Topics.Topic> children = GetChildList(); // Main div output.Append("<div class=\"NDClassPrototype"); if (parents != null && parents.Count > 0) { output.Append(" HasParents"); } if (children != null && children.Count > 0) { output.Append(" HasChildren"); } output.Append("\" id=\"NDClassPrototype" + context.Topic.TopicID + "\">"); // Parents if (parents != null) { foreach (var parent in parents) { AppendParentClassPrototype(parent, output); } } // Current class AppendCurrentClassPrototype(output); // Children if (children != null) { // +1 so we never have to see "and 1 other child" which would take up the same amount of space. if (children.Count <= MaxExpandedChildren + 1) { foreach (var child in children) { AppendChildClassPrototype(child, output); } } else { for (int i = 0; i < MaxExpandedChildren; i++) { AppendChildClassPrototype(children[i], output); } output.Append("<a href=\"javascript:NDContentPage.ShowAdditionalChildren('NDClassPrototype" + context.Topic.TopicID + "')\" " + "class=\"CPAdditionalChildrenNotice\">"); output.EntityEncodeAndAppend( Locale.Get("NaturalDocs.Engine", "HTML.AdditionalChildren(number)", children.Count - MaxExpandedChildren) ); output.Append("</a><div class=\"CPAdditionalChildren\">"); for (int i = MaxExpandedChildren; i < children.Count; i++) { AppendChildClassPrototype(children[i], output); } output.Append("</div>"); } } output.Append("</div>"); } }