FromModel() public static method

public static FromModel ( ItemViewModel vm ) : ApiReferenceBuildOutput
vm Microsoft.DocAsCode.DataContracts.ManagedReference.ItemViewModel
return ApiReferenceBuildOutput
Example #1
0
        public static ApiBuildOutput FromModel(PageViewModel model)
        {
            if (model == null || model.Items == null || model.Items.Count == 0)
            {
                return(null);
            }

            var metadata   = model.Metadata;
            var references = new Dictionary <string, ApiReferenceBuildOutput>();

            foreach (var item in model.References)
            {
                if (!string.IsNullOrEmpty(item.Uid))
                {
                    references[item.Uid] = ApiReferenceBuildOutput.FromModel(item, model.Items[0].SupportedLanguages);
                }
            }

            // Add other items to reference, override the one in reference with same uid
            foreach (var item in model.Items.Skip(1))
            {
                if (!string.IsNullOrEmpty(item.Uid))
                {
                    references[item.Uid] = ApiReferenceBuildOutput.FromModel(item);
                }
            }

            return(FromModel(model.Items[0], references, metadata));
        }
Example #2
0
        public static ApiBuildOutput FromModel(PageViewModel model)
        {
            if (model == null || model.Items == null || model.Items.Count == 0)
            {
                return(null);
            }

            object displayLangs;

            if (model.Metadata.TryGetValue("_displayLangs", out displayLangs))
            {
                var langsObj = displayLangs as object[];
                if (langsObj != null)
                {
                    var langs = langsObj.Select(x => x?.ToString()).ToArray();
                    model.Items.ForEach(item => item.SupportedLanguages = IntersectLangs(item.SupportedLanguages, langs));
                }
                else
                {
                    Logger.LogWarning("Invalid displayLangs setting in docfx.json. Ignored.");
                }
            }

            var metadata   = model.Metadata;
            var references = new Dictionary <string, ApiReferenceBuildOutput>();

            foreach (var item in model.References)
            {
                if (!string.IsNullOrEmpty(item.Uid))
                {
                    references[item.Uid] = ApiReferenceBuildOutput.FromModel(item, model.Items[0].SupportedLanguages);
                }
            }

            // Add other items to reference, override the one in reference with same uid
            foreach (var item in model.Items.Skip(1))
            {
                if (!string.IsNullOrEmpty(item.Uid))
                {
                    references[item.Uid] = ApiReferenceBuildOutput.FromModel(item);
                }
            }

            return(FromModel(model.Items[0], references, metadata));
        }