コード例 #1
0
        string GetParams(DocItem DocItem)
        {
            List <FuncParam> List = DocItem.Params;
            StringBuilder    SB   = null;

            if (List != null && List.Count > 0)
            {
                string Title = "Parameters";

                StringBuilder sbItems = new StringBuilder();
                StringBuilder sbItem;
                StringBuilder sb;
                string        Repeatable;
                string        Optional;
                string        DefaultValue;


                foreach (var Item in List)
                {
                    sbItem = new StringBuilder(Templates["FuncParam"]);
                    sbItem.Replace("__ITEM_NAME__", Item.Name);
                    sbItem.Replace("__DATA_TYPE__", GetDataType(string.IsNullOrWhiteSpace(Item.Type) ? "Any" : Item.Type));
                    sbItem.Replace("__DESCRIPTION__", GetDescription(Item.Description));

                    // repeatable
                    Repeatable = string.Empty;
                    if (Item.IsRepeatable)
                    {
                        sb         = new StringBuilder(Templates["FuncParamRepeatable"]);
                        Repeatable = sb.ToString();
                    }
                    sbItem.Replace("__REPEATABLE__", Repeatable);

                    // optional
                    Optional = string.Empty;
                    if (Item.IsOptional)
                    {
                        sb       = new StringBuilder(Templates["FuncParamOptional"]);
                        Optional = sb.ToString();
                    }
                    sbItem.Replace("__OPTIONAL__", Optional);

                    // default value
                    DefaultValue = string.Empty;
                    if (!string.IsNullOrWhiteSpace(Item.Default))
                    {
                        sb = new StringBuilder(Templates["DefaultValue"]);
                        sb.Replace("__ITEM_VALUE__", Item.Default);
                        DefaultValue = sb.ToString();
                    }
                    sbItem.Replace("__DEFAULT_VALUE__", DefaultValue);

                    sbItems.AppendLine(sbItem.ToString());
                }

                if (sbItems.Length > 0)
                {
                    SB = StarSubList(Title, Title);
                    SB.Replace("__LIST_ITEMS__", sbItems.ToString());
                }
            }

            return(SB != null?SB.ToString() : string.Empty);
        }
コード例 #2
0
 string GetLink(DocItem Item)
 {
     return(GetLink(Item.HRef, Item.Name));
 }
コード例 #3
0
ファイル: FuncParam.cs プロジェクト: zhongshuiyuan/JSDocNet
        /// <summary>
        /// Constructor
        /// </summary>
        public FuncParam(DocItem Parent, string Text)
        {
            //this.Parent = Parent;

            if (!string.IsNullOrWhiteSpace(Text))
            {
                //@param {String|Element} Selector - A selector or an element
                string S;


                var S2 = Sys.ExtractBracketedString(Text, out S);

                Type = S;
                if (!string.IsNullOrWhiteSpace(Type))
                {
                    if (Type.StartsWith("..."))
                    {
                        IsRepeatable = true;
                        Type         = Type.Remove(0, 3);
                    }
                }


                if (!string.IsNullOrWhiteSpace(S2))
                {
                    S2 = S2.Trim();
                    int Index = S2.IndexOf(' ');
                    if (Index == -1)
                    {
                        Name = S2;
                    }
                    else
                    {
                        Name        = S2.Substring(0, Index);
                        Description = S2.Substring(Index);
                        Description = Description.TrimStart(new char[] { ' ', '-' });
                    }

                    if (!string.IsNullOrWhiteSpace(Name))
                    {
                        Name = Name.Trim();
                        if (Name.StartsWith("["))
                        {
                            IsOptional = true;

                            Name = Name.Remove(0, 1).TrimStart();


                            if (Name.EndsWith("]"))
                            {
                                Name = Name.Remove(Name.Length - 1, 1);
                            }

                            string[] Parts = Name.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                            if (Parts.Length == 2)
                            {
                                Name    = Parts[0];
                                Default = Parts[1];
                            }
                        }

                        if (Name.StartsWith("..."))
                        {
                            IsRepeatable = true;
                            Name         = Name.Remove(0, 3).TrimStart();
                        }
                    }
                }
            }
        }
コード例 #4
0
        string Sidebar_GetList(DocItem ParentItem, List <DocItem> List, string Title)
        {
            if (List.Count > 0)
            {
                string        sLink         = GetLink(ParentItem.HRef + "#" + Title, Title);
                StringBuilder sbNode        = Sidebar_NewNode(sLink, Title);
                StringBuilder sbNodeContent = new StringBuilder();

                StringBuilder  sbCategory, sbCategoryContent;
                string         Category = string.Empty;
                List <DocItem> ItemList = List;
                string         S;


                Action AddItems = () =>
                {
                    if (string.IsNullOrWhiteSpace(Category))
                    {
                        foreach (DocItem Item in ItemList)
                        {
                            sLink = GetLink(Item.HRef, Item.Name);
                            S     = Sidebar_GetLeaf(sLink, "");
                            sbNodeContent.AppendLine(S);
                        }
                    }
                    else
                    {
                        sbCategory        = Sidebar_NewNode(Category, "Category");
                        sbCategoryContent = new StringBuilder();

                        foreach (DocItem Item in ItemList)
                        {
                            sLink = GetLink(Item.HRef, Item.Name);
                            S     = Sidebar_GetLeaf(sLink, "");
                            sbCategoryContent.AppendLine(S);
                        }

                        sbCategory.Replace("__CONTENT__", sbCategoryContent.ToString());
                        sbNodeContent.AppendLine(sbCategory.ToString());
                    }
                };

                bool CategoriesExist = List.Any(item => !string.IsNullOrWhiteSpace(item.Category));

                if (CategoriesExist)
                {
                    // IOrderedEnumerable<IGrouping<string, Tutorial>> = groups
                    var groups = from item in List
                                 group item by item.Category into g
                                 orderby g.Key
                                 select g;


                    foreach (var Group in groups)
                    {
                        Category = Group.Key;
                        ItemList = Group.ToList();
                        AddItems();
                    }
                }
                else
                {
                    AddItems();
                }


                sbNode.Replace("__CONTENT__", sbNodeContent.ToString());
                return(sbNode.ToString());
            }

            return(string.Empty);
        }
コード例 #5
0
 /// <summary>
 /// True if an item is a top item, i.e. namespace, class, enum or interface
 /// </summary>
 public bool IsTopItem(DocItem Item)
 {
     return(IsTopItem(Item.ItemType));
 }