public void CanLoadDatedDocuments() { var path = Path.GetFullPath(@"data\dated-documents\"); var command = new LoadDocumentsCommand(); command.Author = new Author(); command.DocumentsPath = path; command.OutputRootPath = Path.GetFullPath("output"); command.RenderedExtensions = new[] { "md" }; command.RootUrl = "http://www.example.com/"; command.ApplicationUrl = "/foo"; command.Execute(); var documents = command.Documents.OrderByDescending(d => d.OutputRelativePath).ToList(); Assert.Equal(4, documents.Count); Assert.Equal(@"parent\index.html", documents[0].OutputRelativePath); Assert.Equal(@"2013-12-18", documents[1].Date.ToString("yyyy-MM-dd")); Assert.Equal(@"parent\2013\12\18\c\index.html", documents[1].OutputRelativePath); Assert.Equal(@"2013-12-17", documents[2].Date.ToString("yyyy-MM-dd")); Assert.Equal(@"parent\2013\12\17\b\index.html", documents[2].OutputRelativePath); Assert.Equal(@"parent\2011\11\5\a\index.html", documents[3].OutputRelativePath); Assert.Equal(@"2011-11-05", documents[3].Date.ToString("yyyy-MM-dd")); }
public void CanLoadComplexMetadata() { var path = Path.GetFullPath(@"data\test-documents\complex-metadata"); var outputPath = Path.GetFullPath("output"); var command = new LoadDocumentsCommand(); command.Author = new Author(); command.DocumentsPath = path; command.OutputRootPath = outputPath; command.RenderedExtensions = new[] { "md" }; command.RootUrl = "http://www.example.com/"; command.ApplicationUrl = "/app/sub"; command.Execute(); var document = command.Documents.Single(); dynamic dynamicDoc = new DynamicDocumentFile(document, document, null); Assert.Equal("Complex Metadata is Fun!", dynamicDoc.Subtitle); Assert.Equal("/item1/", dynamicDoc.ComplexItems[0].Url); Assert.Equal("Item 1", dynamicDoc.ComplexItems[0].Text); Assert.Equal("bar", dynamicDoc.ComplexItems[0].Zzz.Foo); Assert.Equal("/item2/subitem/", dynamicDoc.ComplexItems[1].Url); Assert.Equal("Item 2 Subitem", dynamicDoc.ComplexItems[1].Text); Assert.Equal("g-value", dynamicDoc.ComplexItems[1].Ttt.Ooo.Ggg); }
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")); }
public void CanOrderOrderedDocuments() { var path = Path.GetFullPath(@"data\ordered-documents\"); var command = new LoadDocumentsCommand(); command.Author = new Author(); command.DocumentsPath = path; command.OutputRootPath = Path.GetFullPath("output"); command.RenderedExtensions = new[] { "md" }; command.RootUrl = "http://www.example.com/"; command.ApplicationUrl = "/foo"; command.Execute(); var order = new OrderCommand(); order.Documents = command.Documents; order.Execute(); Assert.Equal(1, order.Books.Count()); var documents = command.Documents.OrderBy(d => d.Order).ToList(); Assert.Equal(0, documents[0].Order); Assert.Equal("parent.txt", documents[0].OutputRelativePath); Assert.Equal(String.Empty, documents[0].ParentId); Assert.Null(documents[0].ParentDocument); Assert.Equal(1, documents[1].Order); Assert.Equal("parent\\first-ordered-document.txt", documents[1].OutputRelativePath); Assert.Equal("parent", documents[1].ParentId); Assert.Equal(documents[0], documents[1].ParentDocument); Assert.Equal(1, documents[2].Order); Assert.Equal("parent\\second-document\\sub-second-document.txt", documents[2].OutputRelativePath); Assert.Equal("parent\\second-document", documents[2].ParentId); Assert.Equal(documents[3], documents[2].ParentDocument); Assert.Equal(2, documents[3].Order); Assert.Equal("parent\\second-document.txt", documents[3].OutputRelativePath); Assert.Equal("parent", documents[3].ParentId); Assert.Equal(documents[0], documents[3].ParentDocument); Assert.Equal(2, documents[4].Order); Assert.Equal("parent\\second-document\\another-sub-second-document.txt", documents[4].OutputRelativePath); Assert.Equal("parent\\second-document", documents[4].ParentId); Assert.Equal(documents[3], documents[4].ParentDocument); Assert.Equal(3, documents[5].Order); Assert.Equal("parent\\third-document-from-metadata.txt", documents[5].OutputRelativePath); Assert.Equal("parent", documents[5].ParentId); Assert.Equal(documents[0], documents[5].ParentDocument); }
public void CanLoadOrderedDocuments() { var path = Path.GetFullPath(@"data\ordered-documents\"); var command = new LoadDocumentsCommand(); command.Author = new Author(); command.DocumentsPath = path; command.OutputRootPath = Path.GetFullPath("output"); command.RenderedExtensions = new[] { "md" }; command.RootUrl = "http://www.example.com/"; command.ApplicationUrl = "/foo"; command.ExecuteAsync().Wait(); var documents = command.Documents.OrderBy(d => d.Order).ToList(); Assert.Equal(0, documents[0].Order); Assert.Equal("parent", documents[0].Metadata.Get<string>("title")); Assert.Equal("parent.txt", documents[0].OutputRelativePath); Assert.Equal(1, documents[1].Order); Assert.Equal("First Ordered Document", documents[1].Metadata.Get<string>("title")); Assert.Equal("parent\\first-ordered-document.txt", documents[1].OutputRelativePath); Assert.Equal("parent", documents[1].ParentId); Assert.Equal(1, documents[2].Order); Assert.Equal("Sub-Second Document", documents[2].Metadata.Get<string>("title")); Assert.Equal("parent\\second-document\\sub-second-document.txt", documents[2].OutputRelativePath); Assert.Equal("parent\\second-document", documents[2].ParentId); Assert.Equal(2, documents[3].Order); Assert.Equal("Second Document", documents[3].Metadata.Get<string>("title")); Assert.Equal("parent\\second-document.txt", documents[3].OutputRelativePath); Assert.Equal("parent", documents[3].ParentId); Assert.Equal(2, documents[4].Order); Assert.Equal("Another Sub-Second Document", documents[4].Metadata.Get<string>("title")); Assert.Equal("parent\\second-document\\another-sub-second-document.txt", documents[4].OutputRelativePath); Assert.Equal("parent\\second-document", documents[4].ParentId); Assert.Equal(3, documents[5].Order); Assert.Equal("Third Document From Metadata", documents[5].Metadata.Get<string>("title")); Assert.Equal("parent\\third-document-from-metadata.txt", documents[5].OutputRelativePath); Assert.Equal("parent", documents[5].ParentId); }
public void CanOrderUnorderedDocuments() { var path = Path.GetFullPath(@"data\dated-documents\"); var command = new LoadDocumentsCommand(); command.Author = new Author(); command.DocumentsPath = path; command.OutputRootPath = Path.GetFullPath("output"); command.RenderedExtensions = new[] { "md" }; command.RootUrl = "http://www.example.com/"; command.ApplicationUrl = "/foo"; command.ExecuteAsync().Wait(); var order = new OrderCommand(); order.Documents = command.Documents; order.Execute(); Assert.Equal(0, order.Books.Count()); }
public void CanSpecifyOutputPath() { var path = Path.GetFullPath(@"data\test-documents\explicit-output"); var outputPath = Path.GetFullPath("output"); var expectedOutput = Path.Combine(outputPath, @"put-that\over\here.txt"); var expectedUrl = "http://www.example.com/app/sub/put-that/over/here.txt"; var command = new LoadDocumentsCommand(); command.Author = new Author(); command.DocumentsPath = path; command.OutputRootPath = outputPath; command.RenderedExtensions = new[] { "md" }; command.RootUrl = "http://www.example.com/"; command.ApplicationUrl = "/app/sub"; command.ExecuteAsync().Wait(); var document = command.Documents.Single(); Assert.Equal(expectedOutput, document.OutputPath); Assert.Equal(expectedUrl, document.Url); }
public void CanLoadWithAdditionalMetadata() { var dataFolder = Path.GetFullPath(@"data\additional-metadata\"); var outputPath = Path.GetFullPath("output"); var loadConfig = new LoadSiteConfigCommand() { ConfigPath = dataFolder + "site.json" }; var config = loadConfig.ExecuteAsync().Result; var loadData = new LoadDataFilesCommand(config.DataPath, config.AdditionalMetadataForFiles, config.IgnoreFiles); loadData.ExecuteAsync().Wait(); var loadDocuments = new LoadDocumentsCommand(); loadDocuments.Author = new Author(); loadDocuments.DocumentsPath = config.DocumentsPath; loadDocuments.OutputRootPath = config.OutputPath; loadDocuments.AdditionalMetadataForFiles = config.AdditionalMetadataForFiles; loadDocuments.IgnoreFiles = config.IgnoreFiles; loadDocuments.RenderedExtensions = new[] { "md" }; loadDocuments.RootUrl = config.RootUrl; loadDocuments.ApplicationUrl = config.Url; loadDocuments.ExecuteAsync().Wait(); var data = loadData.DataFiles.Single(); var document = loadDocuments.Documents.Single(); Assert.Equal("bar", data.Metadata.Get<string>("foo")); Assert.Equal("quux", document.Metadata.Get<string>("baz")); }
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; }