コード例 #1
0
ファイル: TemplateCollection.cs プロジェクト: zyj0021/docfx
        private static Dictionary <string, TemplateBundle> ReadTemplate(ResourceFileReader reader, DocumentBuildContext context, int maxParallelism)
        {
            // type <=> list of template with different extension
            if (reader == null || reader.IsEmpty)
            {
                return(new Dictionary <string, TemplateBundle>(StringComparer.OrdinalIgnoreCase));
            }

            var templates = new TemplatePageLoader(reader, context, maxParallelism).LoadAll();

            return(templates.GroupBy(s => s.Type).ToDictionary(s => s.Key, s => new TemplateBundle(s.Key, s.ToList()), StringComparer.OrdinalIgnoreCase));
        }
コード例 #2
0
        /// <summary>
        /// TemplateName can be either file or folder
        /// 1. If TemplateName is file, it is considered as the default template
        /// 2. If TemplateName is a folder, files inside the folder is considered as the template, each file is named after {DocumentType}.{extension}
        /// </summary>
        /// <param name="templateName"></param>
        /// <param name="resourceProvider"></param>
        public TemplateProcessor(ResourceFileReader resourceProvider, DocumentBuildContext context, int maxParallelism = 0)
        {
            if (maxParallelism <= 0)
            {
                maxParallelism = Environment.ProcessorCount;
            }

            _context            = context;
            _resourceProvider   = resourceProvider;
            _maxParallelism     = maxParallelism;
            _templateCollection = new TemplateCollection(resourceProvider, context, maxParallelism);
            Tokens = LoadTokenJson(resourceProvider) ?? new Dictionary <string, string>();
        }
コード例 #3
0
        private static IDictionary <string, string> LoadTokenJson(ResourceFileReader resource)
        {
            var tokenJson = resource.GetResource("token.json");

            if (string.IsNullOrEmpty(tokenJson))
            {
                // also load `global.json` for backward compatibility
                // TODO: remove this
                tokenJson = resource.GetResource("global.json");
                if (string.IsNullOrEmpty(tokenJson))
                {
                    return(null);
                }
            }

            return(JsonUtility.FromJsonString <Dictionary <string, string> >(tokenJson));
        }
コード例 #4
0
ファイル: TemplateCollection.cs プロジェクト: zyj0021/docfx
 public TemplateCollection(ResourceFileReader provider, DocumentBuildContext context, int maxParallelism) : base(ReadTemplate(provider, context, maxParallelism), StringComparer.OrdinalIgnoreCase)
 {
     Reader         = provider;
     MaxParallelism = maxParallelism;
     base.TryGetValue("default", out _defaultTemplate);
 }