Exemple #1
0
        private void ParseClassHtml(TypeScriptContext tsc, string fullName, string desc, HtmlNode section)
        {
            var cl = tsc.FindType(fullName) as ClassDeclaration;

            if (cl == null)
            {
                var i  = fullName.LastIndexOf('.');
                var md = tsc.GetModule(fullName.Substring(0, i));

                cl = new ClassDeclaration()
                {
                    Name     = fullName.Substring(i + 1),
                    IsExport = true
                };

                md.Statements.Add(cl);
            }

            if (cl.Documentation == null && desc != null)
            {
                cl.Documentation = new Documentation()
                {
                    Summary = desc
                };
            }

            var e = new TypeEventArgs(cl);

            TypeParsing?.Invoke(this, e);

            var headers = section.SelectNodes("//h2|//h3[@class='symbol-name']");

            if (headers != null)
            {
                var t = H2.None;
                foreach (var h in headers)
                {
                    if (h.Name.Equals("h2", StringComparison.InvariantCultureIgnoreCase))
                    {
                        switch (h.InnerText.Trim().ToLowerInvariant())
                        {
                        case "constructor":
                            t = H2.Constructor;
                            break;

                        case "enumerations":
                        case "enumeration":
                            t = H2.Enum;
                            break;

                        case "properties":
                        case "property":
                            t = H2.Property;
                            break;

                        case "methods":
                        case "method":
                            t = H2.Method;
                            break;

                        case "namespaces":
                        case "namespace":
                            t = H2.Namespace;
                            break;

                        default:
                            t = H2.None;
                            Debugger.Break();
                            break;
                        }
                    }
                    else
                    {
                        var sn = h.InnerText.Trim();
                        switch (t)
                        {
                        case H2.Constructor:
                            ProcessConstructor(tsc, cl, h, sn);
                            break;

                        case H2.Property:
                            ProcessProperty(tsc, cl, h, sn);
                            break;

                        case H2.Method:
                            ProcessMethod(tsc, cl, h, sn);
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
            TypeParsed?.Invoke(this, e);
        }
Exemple #2
0
        private void ParseNamespaceHtml(TypeScriptContext tsc, string fullName, string desc, HtmlNode section)
        {
            var md = new ModuleDeclaration()
            {
                Name = fullName
            };

            if (desc != null)
            {
                md.Documentation = new Documentation()
                {
                    Summary = desc
                };
            }
            tsc.Statements.Add(md);

            var e = new ModuleEventArgs(md);

            ModuleParsing?.Invoke(this, e);

            var headers = section.SelectNodes("//h2|//h3[@class='symbol-name']");

            if (headers != null)
            {
                var t = H2.None;
                foreach (var h in headers)
                {
                    if (h.Name.Equals("h2", StringComparison.InvariantCultureIgnoreCase))
                    {
                        switch (h.InnerText.Trim().ToLowerInvariant())
                        {
                        case "classes":
                        case "class":
                            t = H2.Class;
                            break;

                        case "enumerations":
                        case "enumeration":
                            t = H2.Enum;
                            break;

                        case "properties":
                        case "property":
                            t = H2.Property;
                            break;

                        case "methods":
                        case "method":
                            t = H2.Method;
                            break;

                        case "namespaces":
                        case "namespace":
                            t = H2.Namespace;
                            break;

                        case "abstract types":
                        case "abstract type":
                            t = H2.AbstractType;
                            break;

                        default:
                            t = H2.None;
                            break;
                        }
                    }
                    else
                    {
                        var sn = h.InnerText.Trim();
                        switch (t)
                        {
                        case H2.Class:
                        case H2.AbstractType:

                            if (tsc.FindType(sn) == null)
                            {
                                var cl = new ClassDeclaration()
                                {
                                    Name       = sn.Split('.').Last(),
                                    IsExport   = true,
                                    IsAbstract = t == H2.AbstractType
                                };
                                var dsc = h.ParentNode.SelectNodes("p[not(@class)]").SanitizeDocumentation();
                                if (dsc != null)
                                {
                                    cl.Documentation = new Documentation()
                                    {
                                        Summary = dsc
                                    };
                                }
                                md.Statements.Add(cl);
                            }

                            break;

                        case H2.Enum:
                            ProcessEnum(tsc, md, h, sn);
                            break;

                        case H2.Property:
                            ProcessModuleProperty(tsc, md, h, sn);
                            break;

                        case H2.Method:
                            ProcessModuleMethod(tsc, md, h, sn);
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
            ModuleParsed?.Invoke(this, e);
        }