Beispiel #1
0
        void ProcessFile(string sourceFile, MarkdownProcessor markdownProcessor)
        {
            log($"Processing {sourceFile}");
            var target = GetTargetFile(sourceFile, targetDirectory);

            FileEx.ClearReadOnly(target);

            var(lines, newLine) = ReadLines(sourceFile);

            var relativeSource = sourceFile
                                 .Substring(targetDirectory.Length)
                                 .Replace('\\', '/');
            var result = markdownProcessor.Apply(lines, newLine, relativeSource);

            var missingSnippets = result.MissingSnippets;

            if (missingSnippets.Any())
            {
                // If the config value is set to treat missing snippets as warnings, then don't throw
                if (treatMissingSnippetAsWarning)
                {
                    foreach (var missing in missingSnippets)
                    {
                        log($"WARN: The source file:{missing.File} includes a key {missing.Key}, however the snippet is missing. Make sure that the snippet is defined.");
                    }
                }
                else
                {
                    throw new MissingSnippetsException(missingSnippets);
                }
            }

            var missingIncludes = result.MissingIncludes;

            if (missingIncludes.Any())
            {
                // If the config value is set to treat missing include as warnings, then don't throw
                if (treatMissingIncludeAsWarning)
                {
                    foreach (var missing in missingIncludes)
                    {
                        log($"WARN: The source file:{missing.File} includes a key {missing.Key}, however the include is missing. Make sure that the include is defined.");
                    }
                }
                else
                {
                    throw new MissingIncludesException(missingIncludes);
                }
            }

            WriteLines(target, lines);

            if (readOnly)
            {
                FileEx.MakeReadOnly(target);
            }
        }
        public void Run()
        {
            Guard.AgainstNull(snippets, nameof(snippets));
            Guard.AgainstNull(snippetSourceFiles, nameof(snippetSourceFiles));
            var processor = new MarkdownProcessor(snippets, appendSnippetGroup, snippetSourceFiles);

            foreach (var sourceFile in sourceMdFiles)
            {
                ProcessFile(sourceFile, processor);
            }
        }
Beispiel #3
0
        public void Run()
        {
            Guard.AgainstNull(Snippets, nameof(snippets));
            Guard.AgainstNull(snippetSourceFiles, nameof(snippetSourceFiles));
            var processor = new MarkdownProcessor(
                Snippets.ToDictionary(),
                includes,
                appendSnippetGroup,
                snippetSourceFiles,
                tocLevel,
                writeHeader,
                targetDirectory,
                header,
                tocExcludes);

            foreach (var sourceFile in sourceMdFiles)
            {
                ProcessFile(sourceFile, processor);
            }
        }
        void ProcessFile(string sourceFile, MarkdownProcessor markdownProcessor)
        {
            log($"Processing {sourceFile}");
            var target = GetTargetFile(sourceFile, targetDirectory);

            using (var reader = File.OpenText(sourceFile))
                using (var writer = File.CreateText(target))
                {
                    if (writeHeader)
                    {
                        HeaderWriter.WriteHeader(sourceFile, targetDirectory, writer);
                    }

                    var result  = markdownProcessor.Apply(reader, writer);
                    var missing = result.MissingSnippets;
                    if (missing.Any())
                    {
                        throw new MissingSnippetsException(missing);
                    }
                }
        }
        public void Run()
        {
            Guard.AgainstNull(Snippets, nameof(snippets));
            Guard.AgainstNull(snippetSourceFiles, nameof(snippetSourceFiles));
            var processor = new MarkdownProcessor(
                convention,
                Snippets.ToDictionary(),
                includes,
                appendSnippets,
                snippetSourceFiles,
                tocLevel,
                writeHeader,
                targetDirectory,
                validateContent,
                header: header,
                tocExcludes: tocExcludes,
                newLine: newLine);

            foreach (var sourceFile in mdFiles)
            {
                ProcessFile(sourceFile, processor);
            }
        }
        void ProcessFile(string sourceFile, MarkdownProcessor markdownProcessor)
        {
            log($"Processing {sourceFile}");
            string targetFile;

            if (convention == DocumentConvention.SourceTransform)
            {
                targetFile = TargetFileForSourceTransform(sourceFile, targetDirectory);
            }
            else
            {
                targetFile = sourceFile;
            }

            var lines = ReadLines(sourceFile);

            FileEx.ClearReadOnly(targetFile);

            var relativeSource = sourceFile
                                 .Substring(targetDirectory.Length)
                                 .Replace('\\', '/');
            var result = markdownProcessor.Apply(lines, newLine, relativeSource);

            var missingSnippets = result.MissingSnippets;

            if (missingSnippets.Any())
            {
                // If the config value is set to treat missing snippets as warnings, then don't throw
                if (treatMissingAsWarning)
                {
                    foreach (var missing in missingSnippets)
                    {
                        log($"WARN: The source file:{missing.File} includes a key {missing.Key}, however the snippet is missing. Make sure that the snippet is defined.");
                    }
                }
                else
                {
                    throw new MissingSnippetsException(missingSnippets);
                }
            }

            var missingIncludes = result.MissingIncludes;

            if (missingIncludes.Any())
            {
                // If the config value is set to treat missing include as warnings, then don't throw
                if (treatMissingAsWarning)
                {
                    foreach (var missing in missingIncludes)
                    {
                        log($"WARN: The source file:{missing.File} includes a key {missing.Key}, however the include is missing. Make sure that the include is defined.");
                    }
                }
                else
                {
                    throw new MissingIncludesException(missingIncludes);
                }
            }

            var errors = result.ValidationErrors;

            if (errors.Any())
            {
                throw new ContentValidationException(errors);
            }

            WriteLines(targetFile, lines);

            if (readOnly)
            {
                FileEx.MakeReadOnly(targetFile);
            }
        }