Пример #1
0
        public static List <TemplateManifestItem> Transform(TemplateProcessor processor, List <ManifestItem> manifest, DocumentBuildContext context, ApplyTemplateSettings settings)
        {
            if (settings.Options == ApplyTemplateOptions.ExportRawModel || processor == null)
            {
                ExportRawModel(manifest, settings);
                return(null);
            }

            using (new LoggerPhaseScope("Apply Templates"))
            {
                Logger.LogInfo($"Applying templates to {manifest.Count} model(s)...");

                processor.ProcessDependencies(settings.OutputFolder);
                if (processor.IsEmpty)
                {
                    Logger.LogWarning("No template is found.");
                    ExportRawModel(manifest, settings);
                    return(null);
                }

                Logger.LogVerbose("Start applying template...");

                var outputDirectory = context.BuildOutputFolder;

                var templateManifest = processor.Transform(manifest, context, settings);

                if (!settings.Options.HasFlag(ApplyTemplateOptions.TransformDocument))
                {
                    Logger.LogInfo("Dryrun, no template will be applied to the documents.");
                }

                if (templateManifest.Count > 0)
                {
                    // Save manifest from template
                    var manifestPath = Path.Combine(outputDirectory ?? string.Empty, ManifestFileName);
                    JsonUtility.Serialize(manifestPath, templateManifest);
                    Logger.LogInfo($"Manifest file saved to {manifestPath}.");
                }
                return(templateManifest);
            }
        }
Пример #2
0
        public TemplateManager(Assembly assembly, string rootNamespace, List <string> templates, List <string> themes, string baseDirectory)
        {
            var resourceFinder = new ResourceFinder(assembly, rootNamespace, baseDirectory);

            if (templates == null || templates.Count == 0)
            {
                Logger.Log(LogLevel.Info, "Template is not specified, files will not be transformed.");
            }
            else
            {
                var templateResources = templates.Select(s => resourceFinder.Find(s)).Where(s => s != null).ToArray();
                if (templateResources.Length == 0)
                {
                    Logger.Log(LogLevel.Warning, $"No template resource found for [{templates.ToDelimitedString()}].");
                }
                else
                {
                    _templateProcessor = new TemplateProcessor(new CompositeResourceCollectionWithOverridden(templateResources));
                }
            }

            if (themes == null || themes.Count == 0)
            {
                Logger.Log(LogLevel.Info, "Theme is not specified, no additional theme will be applied to the documentation.");
            }
            else
            {
                var themeResources = themes.Select(s => resourceFinder.Find(s)).Where(s => s != null).ToArray();
                if (themeResources.Length == 0)
                {
                    Logger.Log(LogLevel.Warning, $"No theme resource found for [{themes.ToDelimitedString()}].");
                }
                else
                {
                    _themeResource = new CompositeResourceCollectionWithOverridden(themeResources);
                }
            }
        }
Пример #3
0
 public TemplateManager(Assembly assembly, string rootNamespace, List<string> templates, List<string> themes, string baseDirectory)
 {
     var resourceFinder = new ResourceFinder(assembly, rootNamespace, baseDirectory);
     if (templates == null || templates.Count == 0)
     {
         Logger.Log(LogLevel.Info, "Template is not specified, files will not be transformed.");
     }
     else
     {
         var templateResources = templates.Select(s => resourceFinder.Find(s)).Where(s => s != null).ToArray();
         if (templateResources.Length == 0)
         {
             Logger.Log(LogLevel.Warning, $"No template resource found for [{templates.ToDelimitedString()}].");
         }
         else
         {
             _templateProcessor = new TemplateProcessor(new CompositeResourceCollectionWithOverridden(templateResources));
         }
     }
     
     if (themes == null || themes.Count == 0)
     {
         Logger.Log(LogLevel.Info, "Theme is not specified, no additional theme will be applied to the documentation.");
     }
     else
     {
         var themeResources = themes.Select(s => resourceFinder.Find(s)).Where(s => s != null).ToArray();
         if (themeResources.Length == 0)
         {
             Logger.Log(LogLevel.Warning, $"No theme resource found for [{themes.ToDelimitedString()}].");
         }
         else
         {
             _themeResource = new CompositeResourceCollectionWithOverridden(themeResources);
         }
     }
 }
Пример #4
0
        private void ProcessTemplate(DocumentBuildContext context, string outputDirectory)
        {
            if (_templates == null || _templates.Count == 0)
            {
                Logger.Log(LogLevel.Info, "Template is not specified, files will not be transformed.");
                return;
            }

            using (var templateResource = new CompositeResourceCollectionWithOverridden(_templates.Select(s => _finder.Find(s)).Where(s => s != null)))
            {
                if (templateResource.IsEmpty)
                {
                    Logger.Log(LogLevel.Warning, $"No template resource found for [{_templates.ToDelimitedString()}].");
                }
                else
                {
                    Logger.Log(LogLevel.Verbose, "Template resource found, starting applying template.");
                    using (var processor = new TemplateProcessor(templateResource))
                    {
                        processor.Process(context, outputDirectory);
                    }
                }
            }
        }
Пример #5
0
        private void ProcessTemplate(DocumentBuildContext context, string outputDirectory)
        {
            if (_templates == null || _templates.Count == 0)
            {
                Logger.Log(LogLevel.Info, "Template is not specified, files will not be transformed.");
                return;
            }

            using (var templateResource = new CompositeResourceCollectionWithOverridden(_templates.Select(s => _finder.Find(s)).Where(s => s != null)))
            {
                if (templateResource.IsEmpty)
                {
                    Logger.Log(LogLevel.Warning, $"No template resource found for [{_templates.ToDelimitedString()}].");
                }
                else
                {
                    Logger.Log(LogLevel.Verbose, "Template resource found, starting applying template.");
                    using (var processor = new TemplateProcessor(templateResource))
                    {
                        processor.Process(context, outputDirectory);
                    }
                }
            }
        }