Пример #1
0
        public async Task TestBuild()
        {
            MockFileSystem.File.Exists(Path.Combine(ExitDirectory, "index.html")).ShouldBeFalse();

            var siteBuilder = new SiteBuilder(MockFileSystem, Mapper.GetMapper());

            siteBuilder.Build(RootDirectory, ExitDirectory);

            var indexFile = Path.Combine(ExitDirectory, "index.html");

            MockFileSystem.File.Exists(indexFile).ShouldBeTrue();
            var indexDocument = await OpenDocument(indexFile);

            var sections = indexDocument.All.Where(node => node.LocalName == "section");

            sections.Count().ShouldBe(2);

            var titleContainer = indexDocument.All.First(node => node.LocalName == "div" && node.ClassName == "main");

            titleContainer.TextContent.Trim().ShouldBe("Your new blog!");

            var subTitleContainer = indexDocument.All.First(node => node.LocalName == "div" && node.ClassName == "site-description");

            subTitleContainer.TextContent.Trim().ShouldBe("Edit this subtitle in the site.yml file");

            var secondPostFile = Path.Combine(ExitDirectory, "posts", "second-post.html");

            MockFileSystem.File.Exists(secondPostFile).ShouldBeTrue();
            var secondPost = await OpenDocument(secondPostFile);

            var title = secondPost.All.First(node => node.LocalName == "h1");

            title.TextContent.ShouldBe("My second post!");

            var pageFile = Path.Combine(ExitDirectory, "pages", "about.html");

            MockFileSystem.File.Exists(pageFile).ShouldBeTrue();
            var page = await OpenDocument(pageFile);

            var pageTitle = page.All.First(node => node.LocalName == "h1");

            pageTitle.TextContent.ShouldBe("About");

            var tagseFile = Path.Combine(ExitDirectory, "tags.html");

            MockFileSystem.File.Exists(tagseFile).ShouldBeTrue();
            var tagsPage = await OpenDocument(tagseFile);

            var tags = tagsPage.All.Where(node => node.LocalName == "li").Select(tag => tag.TextContent).ToArray();

            tags.ShouldBe(new string[] { "lockdown", "blog" });

            var lockdownTagsFile = Path.Combine(ExitDirectory, "tags", "lockdown.html");

            MockFileSystem.File.Exists(Path.Combine(ExitDirectory, "tags", "lockdown.html")).ShouldBeTrue();
            var lockdownPostsPage = await OpenDocument(lockdownTagsFile);

            var pageTitles = lockdownPostsPage.All.Where(node => node.LocalName == "h1" && node.ClassName == "title").Select(h1 => h1.TextContent).ToArray();

            pageTitles.ShouldBe(new string[] { "My first post!", "My second post!" });
        }
Пример #2
0
    private static async Task MainLoop(Arguments arguments)
    {
        try
        {
            await ProgramLoop();
        }
        catch (Exception e)
        {
            LogExitException(e, "Operation failed!");
        }

        async Task ProgramLoop()
        {
            while (true)
            {
                Console.WriteLine("Press key to proceed:");
                Console.WriteLine("  B - Build site");
                Console.WriteLine("  C - Content build only");
                Console.WriteLine("  U - Log external URLs");
#if WINDOWS
                Console.WriteLine("  R - Create rich-text embed from clipboard");
#endif
                Console.WriteLine("  Esc - Exit");
Read:
                var key = Console.ReadKey().Key;
                Console.WriteLine();
                Console.Clear();
                switch (key)
                {
                case ConsoleKey.B:
                    // Build Site
                    if (SiteBuilder.Build(arguments))
                    {
                        Console.WriteLine("Successful build, generating search index.");
                        await SearchIndex.Generate(arguments);

                        Console.WriteLine("Search index generated.");
                    }
                    else
                    {
                        Console.WriteLine("Build failed! Press key to continue.");
                        Console.ReadKey();
                        Console.Clear();
                    }
                    break;

                case ConsoleKey.C:
                    // Content Build
                    SiteBuilder.ContentBuild(arguments);
                    Console.WriteLine("Successful Content Build.");
                    break;

                case ConsoleKey.U:
                    SiteLogging.LogAllExternalUrls(arguments);
                    break;

#if WINDOWS
                case ConsoleKey.R:
                    RtfClip.CreateRtfFile(arguments);
                    break;
#endif
                case ConsoleKey.Escape:
                    return;

                default:
                    goto Read;
                }
            }
        }
    }
Пример #3
0
        // wolf howling
        private static void Main(string[] args)
        {
            SiteBuilder e = new SiteBuilder();

            e.Build();
        }