Example #1
0
        public static TocViewModel Convert(MetadataItem item)
        {
            Debug.Assert(item.Type == MemberType.Toc);
            if (item.Type != MemberType.Toc)
            {
                return(null);
            }
            var tocList = new TocViewModel();

            foreach (var namespaceItem in item.Items)
            {
                var namespaceTocViewModel = ItemViewModel.Convert(namespaceItem, TocMetadataList);
                if (namespaceItem.Items != null)
                {
                    var tocSubList = new TocViewModel();
                    foreach (var classItem in namespaceItem.Items)
                    {
                        var classTocViewModel = ItemViewModel.Convert(classItem, TocMetadataList);
                        tocSubList.Add(classTocViewModel);
                    }
                    namespaceTocViewModel["items"] = tocSubList;
                }

                tocList.Add(namespaceTocViewModel);
            }

            return(tocList);
        }
Example #2
0
        private static ParseResult ResolveAndExportYamlMetadata(Dictionary <string, MetadataItem> allMembers, string folder, string indexFileName, string tocFileName, string apiFolder)
        {
            var model = YamlMetadataResolver.ResolveMetadata(allMembers, apiFolder);

            // 1. generate toc.yml
            model.TocYamlViewModel.Href = tocFileName;
            model.TocYamlViewModel.Type = MemberType.Toc;

            // TOC do not change
            var    tocViewModel = TocViewModel.Convert(model.TocYamlViewModel);
            string tocFilePath  = Path.Combine(folder, tocFileName);

            using (StreamWriter sw = new StreamWriter(tocFilePath))
            {
                YamlUtility.Serialize(sw, tocViewModel);
            }

            // 2. generate api.yml
            string indexFilePath = Path.Combine(folder, indexFileName);

            using (StreamWriter sw = new StreamWriter(indexFilePath))
            {
                YamlUtility.Serialize(sw, model.Indexer);
            }

            // 3. generate each item's yaml
            var members = model.Members;

            foreach (var memberModel in members)
            {
                string itemFilepath = Path.Combine(folder, apiFolder, memberModel.Href);
                Directory.CreateDirectory(Path.GetDirectoryName(itemFilepath));
                using (StreamWriter sw = new StreamWriter(itemFilepath))
                {
                    var memberViewModel = OnePageViewModel.Convert(memberModel);
                    YamlUtility.Serialize(sw, memberViewModel);
                    ParseResult.WriteToConsole(ResultLevel.Success, "Metadata file for {0} is saved to {1}", memberModel.Name, itemFilepath);
                }
            }

            return(new ParseResult(ResultLevel.Success));
        }