Pretzel.Logic.Templating.Context.SiteContextGenerator.BuildContext C# (CSharp) Method

BuildContext() public method

public BuildContext ( string path, string destinationPath, bool includeDrafts ) : Pretzel.Logic.Templating.Context.SiteContext
path string
destinationPath string
includeDrafts bool
return Pretzel.Logic.Templating.Context.SiteContext
        public SiteContext BuildContext(string path, string destinationPath, bool includeDrafts)
        {
            try
            {
                var context = new SiteContext
                {
                    SourceFolder = path,
                    OutputFolder = destinationPath,
                    Posts = new List<Page>(),
                    Pages = new List<Page>(),
                    Config = _config,
                    Time = DateTime.Now,
                    UseDrafts = includeDrafts
                };

                context.Posts = BuildPosts(_config, context).OrderByDescending(p => p.Date).ToList();
                BuildTagsAndCategories(context);

                context.Pages = BuildPages(_config, context).ToList();

                if (BeforeProcessingTransforms != null)
                {
                    foreach (var transform in BeforeProcessingTransforms)
                    {
                        transform.Transform(context);
                    }
                }

                return context;
            }
            finally
            {
                pageCache.Clear();
            }
        }

Usage Example

Ejemplo n.º 1
0
        public void file_with_1_ioexception_on_ReadAllText_is_processed()
        {
            // arrange
            string filePath = Path.Combine(Path.GetTempPath(), "SomeFile.md");
            bool alreadyOccured = false;
            var fileSubstitute = Substitute.For<FileBase>();
            fileSubstitute.OpenText(Arg.Any<string>()).Returns(new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes("---"))));
            fileSubstitute.ReadAllText(Arg.Any<string>()).Returns(x =>
                {
                    if (alreadyOccured)
                    {
                        return "---\r\n---# Title";
                    }
                    else
                    {
                        alreadyOccured = true;
                        throw new IOException();
                    }
                });
            fileSubstitute.Exists(filePath).Returns(true);

            var directorySubstitute = Substitute.For<DirectoryBase>();
            directorySubstitute.GetFiles(Arg.Any<string>(), "*.*", SearchOption.AllDirectories).Returns(new[] { @"C:\TestSite\SomeFile.md" });

            var fileInfoSubstitute = Substitute.For<FileInfoBase>();
            fileInfoSubstitute.Name.Returns("SomeFile.md");

            var fileInfoFactorySubstitute = Substitute.For<IFileInfoFactory>();
            fileInfoFactorySubstitute.FromFileName(Arg.Any<string>()).Returns(fileInfoSubstitute);

            var fileSystemSubstitute = Substitute.For<IFileSystem>();
            fileSystemSubstitute.File.Returns(fileSubstitute);
            fileSystemSubstitute.Directory.Returns(directorySubstitute);
            fileSystemSubstitute.FileInfo.Returns(fileInfoFactorySubstitute);

            var generator = new SiteContextGenerator(fileSystemSubstitute, new LinkHelper());

            // act
            var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false);

            // assert
            Assert.Equal(1, siteContext.Pages.Count);
            Assert.Equal("---\r\n---# Title", siteContext.Pages[0].Content);
            // Check if the temp file have been deleted
            fileSubstitute.Received().Delete(filePath);
        }
All Usage Examples Of Pretzel.Logic.Templating.Context.SiteContextGenerator::BuildContext