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")); }
private void Render(Site site, IDictionary<string, RenderingEngine> engines) { using (var rendering = Statistics.Current.Start(StatisticTiming.Rendered)) { using (var capture = Statistics.Current.Start(StatisticTiming.RenderDocuments)) { var render = new RenderDocumentsCommand(engines, site); render.Execute(); Statistics.Current.RenderedData = render.RenderedData; Statistics.Current.RenderedDocuments = render.RenderedDocuments; } using (var capture = Statistics.Current.Start(StatisticTiming.WriteDocuments)) { var write = new WriteDocumentsCommand(site.Documents); write.Execute(); Statistics.Current.WroteDocuments = write.WroteDocuments; } using (var capture = Statistics.Current.Start(StatisticTiming.CopyStaticFiles)) { var copy = new CopyStaticFilesCommand(site.Files); copy.Execute(); Statistics.Current.CopiedFiles = copy.CopiedFiles; } } }