public void CanLoadLayouts()
        {
            var path = Path.GetFullPath(@"data\layouts\");

            var command = new LoadLayoutsCommand(path, null, null);
            var layouts = command.ExecuteAsync().Result;

            Assert.NotEmpty(command.Layouts);
            Assert.NotEmpty(layouts);
        }
예제 #2
0
        public void CanLoadNoLayouts()
        {
            var path = Path.GetFullPath(@"data\doesnotexist\");

            var command = new LoadLayoutsCommand(path, null, null);
            var layouts = command.Execute();

            Assert.Empty(command.Layouts);
            Assert.Empty(layouts);
        }
        public void CanRenderDocument()
        {
            var tinySiteAssembly = typeof(RazorRenderer).Assembly;

            var basePath = Path.GetFullPath(@"data\RenderDocumentsCommand\");

            var outputPath = Path.Combine(Path.GetTempPath(), @"tinysite\");

            var loadLayouts = new LoadLayoutsCommand(Path.Combine(basePath, @"layouts\"), null, null);
            var layouts = loadLayouts.Execute();
            var collection = new LayoutFileCollection(layouts);

            var loadDocuments = new LoadDocumentsCommand();
            loadDocuments.Author = new Author();
            loadDocuments.DocumentsPath = Path.Combine(basePath, @"documents\");
            loadDocuments.Layouts = collection;
            loadDocuments.OutputRootPath = outputPath;
            loadDocuments.RenderedExtensions = new[] { "md", "cshtml" };
            loadDocuments.RootUrl = "http://www.example.com/";
            loadDocuments.ApplicationUrl = "/app/sub";
            var documents = loadDocuments.Execute().OrderBy(d => d.Name).ToList();

            var config = new SiteConfig() { OutputPath = outputPath, Url = "http://example.com", RootUrl = String.Empty, };

            var site = new Site(config, Enumerable.Empty<DataFile>(), documents, Enumerable.Empty<StaticFile>(), collection);

            var engines = RenderingEngine.Load(tinySiteAssembly);

            Statistics.Current = new Statistics();

            var command = new RenderDocumentsCommand(engines, site);
            command.Execute();

            var description = "This is the summary of the document with a link to example.com.";
            var content = "<p>This is the summary of the document with a link to <a href=\"http://example.com\">example.com</a>.</p>\n<p>This is additional content in the document.</p>";
            var summary = "<p>This is the summary of the document with a link to <a href=\"http://example.com\">example.com</a>.</p>";
            var title = "test";

            Assert.Equal(0, command.RenderedData);
            Assert.Equal(3, command.RenderedDocuments);
            Assert.Equal(String.Empty, documents[0].RenderedContent.Trim());

            Assert.Equal("This is the summary of the document with a link to [example.com](http://example.com).\n\nThis is additional content in the document.", documents[2].SourceContent.Replace("\r\n", "\n"));
            Assert.Equal(content, documents[2].Content);
            Assert.Equal(description, documents[2].Description);
            Assert.Equal(summary, documents[2].Summary);
            Assert.Equal(title, documents[2].Metadata.Get<string>("title"));

            Assert.Equal(
                $"<title>{title}</title>\n" +
                $"<description>{description}</description>\n" +
                $"<summary>{summary}</summary>\n" +
                $"<content>{content}</content>",
                documents[2].RenderedContent.Replace("\r\n", "\n"));
        }
예제 #4
0
        private Site LoadSite(SiteConfig config, IEnumerable<LastRunDocument> lastRunState, IEnumerable<string> renderedExtensions)
        {
            Site site;

            using (var capture = Statistics.Current.Start(StatisticTiming.LoadedSite))
            {
                // Load layouts.
                LayoutFileCollection layouts;
                {
                    var load = new LoadLayoutsCommand(config.LayoutsPath, config.AdditionalMetadataForFiles, config.IgnoreFiles);
                    var loaded = load.Execute();

                    layouts = new LayoutFileCollection(loaded);
                }

                // Load data files.
                IEnumerable<DataFile> data;
                {
                    var load = new LoadDataFilesCommand(config.DataPath, config.AdditionalMetadataForFiles, config.IgnoreFiles);
                    data = load.Execute();
                }

                // Load documents.
                IEnumerable<DocumentFile> documents;
                {
                    var load = new LoadDocumentsCommand();
                    load.Author = config.Author;
                    load.OutputRootPath = config.OutputPath;
                    load.Layouts = layouts;
                    load.RenderedExtensions = renderedExtensions;
                    load.DefaultLayoutForExtension = config.DefaultLayoutForExtension;
                    load.DocumentsPath = config.DocumentsPath;
                    load.RootUrl = config.RootUrl;
                    load.ApplicationUrl = config.Url;
                    load.AdditionalMetadataForFiles = config.AdditionalMetadataForFiles;
                    load.IgnoreFiles = config.IgnoreFiles;
                    documents = load.Execute();
                }

                // Load files.
                IEnumerable<StaticFile> files;
                {
                    var load = new LoadFilesCommand();
                    load.OutputPath = config.OutputPath;
                    load.FilesPath = config.FilesPath;
                    load.RootUrl = config.RootUrl;
                    load.Url = config.Url;
                    files = load.Execute();
                }

                // Calculate unmodified state.
                {
                    var unmodified = new SetUnmodifiedCommand(config.SitePath, documents, files, this.InitialLastRunState);
                    unmodified.Execute();
                }

                site = new Site(config, data, documents, files, layouts);
            }

            Statistics.Current.SiteFiles = site.Documents.Count + site.Files.Count + site.Layouts.Count;

            return site;
        }