Beispiel #1
0
        public void Apply(string path, ValidationResult result)
        {
            if (String.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentException($"'{nameof(path)}' cannot be null or whitespace", nameof(path));
            }

            if (!IO.HasExtension(path, IO.FileExtensions.Scriban))
            {
                return;
            }

            var outputPath = IO.GetTemplateOutputPath(path);

            if (File.Exists(outputPath))
            {
                var expectedContent = DocsRenderer.RenderTemplate(path);
                var actualContent   = File.ReadAllText(outputPath);

                if (!StringComparer.Ordinal.Equals(expectedContent, actualContent))
                {
                    result.AddError(s_RuleId, "Contents of output file are not up-to-date with respect to the template file");
                }
            }
            else
            {
                result.AddError(s_RuleId, $"Template output file does not exists (expected at '{outputPath}')");
            }
        }
Beispiel #2
0
        private static int GenerateDocs(GenerateCommandLineParameters parameters)
        {
            if (!ValidateParameters(parameters))
            {
                return(1);
            }

            Console.WriteLine($"Generating documentation from templates");

            var inputFiles = GetAllInputFiles(parameters).Where(x => IO.HasExtension(x, IO.FileExtensions.Scriban));

            foreach (var inputPath in inputFiles)
            {
                Console.WriteLine($"  Processing '{inputPath}'");
                var outputPath = IO.GetTemplateOutputPath(inputPath);

                var output = DocsRenderer.RenderTemplate(inputPath);

                Console.WriteLine($"    Saving output to '{outputPath}'");
                File.WriteAllText(outputPath, output);
            }

            return(0);
        }