From 0f6cf2fc167076a58d0e4af66aced4583ad4c301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Bertrand?= Date: Wed, 18 Feb 2015 07:31:25 +0100 Subject: [PATCH 1/2] Add source and destination parameters --- .../Commands/CommandParameters.cs | 10 ++-- .../CommandParameterOutputTests.cs | 2 + src/Pretzel.Tests/CommandParameterTests.cs | 49 +++++++++++++++++++ 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/Pretzel.Logic/Commands/CommandParameters.cs b/src/Pretzel.Logic/Commands/CommandParameters.cs index b2f9ce9d2..08f207acf 100644 --- a/src/Pretzel.Logic/Commands/CommandParameters.cs +++ b/src/Pretzel.Logic/Commands/CommandParameters.cs @@ -24,13 +24,15 @@ public CommandParameters([ImportMany] IEnumerable commandL Settings = new OptionSet { { "t|template=", "The templating engine to use", v => Template = v }, - { "d|directory=", "The path to site directory", p => Path = p }, + { "d|directory=", "[Obsolete, use --source instead] The path to site directory", p => Path = p }, { "p|port=", "The port to test the site locally", p => decimal.TryParse(p, out port) }, { "i|import=", "The import type", v => ImportType = v }, { "f|file=", "Path to import file", v => ImportPath = v }, + { "s|source=", "The path to the source site (default current directory)", p => Path = p}, + { "destination=", "The path to the destination site (default _site)", d => DestinationPath = d}, { "drafts", "Add the posts in the drafts folder", v => IncludeDrafts = true }, { "nobrowser", "Do not launch a browser", v => LaunchBrowser = false }, - { "withproject", "Includes a layout VS Solution, to give intellisence when editing razor layout files", v => WithProject = (v!=null) }, + { "withproject", "Includes a layout VS Solution, to give intellisense when editing razor layout files", v => WithProject = (v!=null) }, { "wiki", "Creates a wiki instead of a blog (razor template only)", v => Wiki = (v!=null) }, { "cleantarget", "Delete the target directory (_site by default)", v => CleanTarget = true }, { "safe", "Disable custom plugins", v => Safe = true } @@ -57,12 +59,14 @@ public CommandParameters([ImportMany] IEnumerable commandL public bool IncludeDrafts { get; private set; } - public bool CleanTarget { get; set; } + public bool CleanTarget { get; private set; } public bool LaunchBrowser { get; private set; } public bool Safe { get; private set; } + public string DestinationPath { get; private set; } + private decimal port; public decimal Port diff --git a/src/Pretzel.Tests/CommandParameterOutputTests.cs b/src/Pretzel.Tests/CommandParameterOutputTests.cs index fc22deed6..5935cab59 100644 --- a/src/Pretzel.Tests/CommandParameterOutputTests.cs +++ b/src/Pretzel.Tests/CommandParameterOutputTests.cs @@ -36,6 +36,8 @@ public void WriteOptions_WithNoParametersSpecified_DisplaysAll() Assert.True(output.Contains("--file=")); Assert.True(output.Contains("--cleantarget")); Assert.True(output.Contains("--safe")); + Assert.True(output.Contains("--source")); + Assert.True(output.Contains("--destination")); } [Fact] diff --git a/src/Pretzel.Tests/CommandParameterTests.cs b/src/Pretzel.Tests/CommandParameterTests.cs index e11c493a1..12e8de167 100644 --- a/src/Pretzel.Tests/CommandParameterTests.cs +++ b/src/Pretzel.Tests/CommandParameterTests.cs @@ -20,6 +20,7 @@ public class CommandParameterTests private const string ExpectedTemplate = @"jekyll"; private const string ExpectedPort = "8000"; private const decimal ExpectedPortDecimal = 8000; + private const string ExpectedDestinationPath = @"D:\Code\Generated"; public CommandParameterTests() { @@ -465,5 +466,53 @@ public void LaunchBrowser_WhenNotSpecifyingSafe_IsFalse() subject.Parse(args); Assert.False(subject.Safe); } + + [Fact] + public void Parse_WhenSpecifyingSourcePathUsingShortParameter_MapsToPath() + { + var args = new List { "--s", ExpectedPath }; + subject.Parse(args); + Assert.Equal(ExpectedPath, subject.Path); + } + + [Fact] + public void Parse_WhenSpecifyingSourcePathUsingFullParameter_MapsToPath() + { + var args = new List { "--source", ExpectedPath }; + subject.Parse(args); + Assert.Equal(ExpectedPath, subject.Path); + } + + [Fact] + public void Parse_WhenSpecifyingSourcePathUsingShortParameterSingleDash_MapsToPath() + { + var args = new List { "-s", ExpectedPath }; + subject.Parse(args); + Assert.Equal(ExpectedPath, subject.Path); + } + + [Fact] + public void Parse_WhenSpecifyingSourcePathUsingFullParameterSingleDash_MapsToPath() + { + var args = new List { "-source", ExpectedPath }; + subject.Parse(args); + Assert.Equal(ExpectedPath, subject.Path); + } + + [Fact] + public void Parse_WhenSpecifyingDestinationPathUsingFullParameter_MapsToPath() + { + var args = new List { "--destination", ExpectedDestinationPath }; + subject.Parse(args); + Assert.Equal(ExpectedDestinationPath, subject.DestinationPath); + } + + [Fact] + public void Parse_WhenSpecifyingDestinationPathUsingFullParameterSingleDash_MapsToPath() + { + var args = new List { "-destination", ExpectedDestinationPath }; + subject.Parse(args); + Assert.Equal(ExpectedDestinationPath, subject.DestinationPath); + } } } From 5a2ad9ac3638063e39d2051da06b826e1883bb8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Bertrand?= Date: Thu, 19 Feb 2015 07:45:57 +0100 Subject: [PATCH 2/2] Fix default value of DestinationPath Fix all related tests Add some tests Remove the unnecessary ISiteEngine.GetOutputDirectory method --- .../Commands/CommandParameters.cs | 22 ++- .../Context/SiteContextGenerator.cs | 22 +-- src/Pretzel.Logic/Templating/ISiteEngine.cs | 7 +- .../Templating/JekyllEngineBase.cs | 14 +- .../CommandParameterOutputTests.cs | 3 +- src/Pretzel.Tests/CommandParameterTests.cs | 27 ++- .../Context/SiteContextGeneratorTests.cs | 149 +++++++-------- .../Templating/Jekyll/LiquidEngineTests.cs | 180 +++++++++++------- .../Templating/Razor/RazorEngineTests.cs | 4 +- .../Razor/When_Recieving_A_Razor_File.cs | 14 +- src/Pretzel/Commands/BakeCommand.cs | 25 ++- src/Pretzel/Commands/TasteCommand.cs | 24 ++- .../Modules/SimpleFileSystemWatcher.cs | 18 +- 13 files changed, 289 insertions(+), 220 deletions(-) diff --git a/src/Pretzel.Logic/Commands/CommandParameters.cs b/src/Pretzel.Logic/Commands/CommandParameters.cs index 08f207acf..3d1c7f5ad 100644 --- a/src/Pretzel.Logic/Commands/CommandParameters.cs +++ b/src/Pretzel.Logic/Commands/CommandParameters.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.ComponentModel.Composition; using System.IO; +using System.IO.Abstractions; using System.Linq; namespace Pretzel.Logic.Commands @@ -16,8 +17,10 @@ namespace Pretzel.Logic.Commands public class CommandParameters { [ImportingConstructor] - public CommandParameters([ImportMany] IEnumerable commandLineExtensions) + public CommandParameters([ImportMany] IEnumerable commandLineExtensions, IFileSystem fileSystem) { + this.fileSystem = fileSystem; + port = 8080; LaunchBrowser = true; @@ -76,6 +79,8 @@ public decimal Port private OptionSet Settings { get; set; } + private IFileSystem fileSystem; + public void Parse(IEnumerable arguments) { var argumentList = arguments.ToArray(); @@ -86,12 +91,21 @@ public void Parse(IEnumerable arguments) if (firstArgument != null && !firstArgument.StartsWith("-") && !firstArgument.StartsWith("/")) { - Path = System.IO.Path.IsPathRooted(firstArgument) + Path = fileSystem.Path.IsPathRooted(firstArgument) ? firstArgument - : System.IO.Path.Combine(Directory.GetCurrentDirectory(), firstArgument); + : fileSystem.Path.Combine(fileSystem.Directory.GetCurrentDirectory(), firstArgument); } - Path = string.IsNullOrWhiteSpace(Path) ? Directory.GetCurrentDirectory() : System.IO.Path.GetFullPath(Path); + Path = string.IsNullOrWhiteSpace(Path) ? fileSystem.Directory.GetCurrentDirectory() : fileSystem.Path.GetFullPath(Path); + + if (string.IsNullOrEmpty(DestinationPath)) + { + DestinationPath = "_site"; + } + if (!fileSystem.Path.IsPathRooted(DestinationPath)) + { + DestinationPath = fileSystem.Path.Combine(Path, DestinationPath); + } } public void DetectFromDirectory(IDictionary engines, SiteContext context) diff --git a/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs b/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs index 9134936fc..9f33662ca 100644 --- a/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs +++ b/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs @@ -19,11 +19,11 @@ public class SiteContextGenerator private static readonly Regex categoryRegex = new Regex(@":category(\d*)", RegexOptions.Compiled); private static readonly Regex slashesRegex = new Regex(@"/{1,}", RegexOptions.Compiled); - readonly Dictionary pageCache = new Dictionary(); - readonly IFileSystem fileSystem; - readonly IEnumerable contentTransformers; - readonly List includes = new List(); - readonly List excludes = new List(); + private readonly Dictionary pageCache = new Dictionary(); + private readonly IFileSystem fileSystem; + private readonly IEnumerable contentTransformers; + private readonly List includes = new List(); + private readonly List excludes = new List(); [ImportingConstructor] public SiteContextGenerator(IFileSystem fileSystem, [ImportMany]IEnumerable contentTransformers) @@ -32,7 +32,7 @@ public SiteContextGenerator(IFileSystem fileSystem, [ImportMany]IEnumerable(), Pages = new List(), Config = config, @@ -135,7 +135,6 @@ private IEnumerable BuildPosts(Dictionary config, SiteCont ); } - return posts; } @@ -175,7 +174,6 @@ private static void BuildTagsAndCategories(SiteContext context) } } } - } context.Tags = tags.Select(x => new Tag { Name = x.Key, Posts = x.Value }).OrderBy(x => x.Name).ToList(); @@ -240,7 +238,7 @@ private Page CreatePage(SiteContext context, IDictionary config, if (isPost) { if (header.ContainsKey("categories") && header["categories"] is IEnumerable) - page.Categories = (IEnumerable) header["categories"]; + page.Categories = (IEnumerable)header["categories"]; else if (header.ContainsKey("category")) page.Categories = new[] { header["category"].ToString() }; @@ -468,11 +466,13 @@ private string GetPathWithTimestamp(string outputDirectory, string file) return Path.Combine(outputDirectory, timestamp, title); } - static readonly Regex TimestampAndTitleFromPathRegex = new Regex(@"\\(?:(?\d+-\d+-\d+)-)?(?[^\\]*)\.[^\.]+$"); + private static readonly Regex TimestampAndTitleFromPathRegex = new Regex(@"\\(?:(?<timestamp>\d+-\d+-\d+)-)?(?<title>[^\\]*)\.[^\.]+$"); + public static string GetTitle(string file) { return TimestampAndTitleFromPathRegex.Match(file).Groups["title"].Value; } + private string GetPageTitle(string file) { return Path.GetFileNameWithoutExtension(file); diff --git a/src/Pretzel.Logic/Templating/ISiteEngine.cs b/src/Pretzel.Logic/Templating/ISiteEngine.cs index 316102207..a06935ad3 100644 --- a/src/Pretzel.Logic/Templating/ISiteEngine.cs +++ b/src/Pretzel.Logic/Templating/ISiteEngine.cs @@ -1,5 +1,5 @@ -using System.ComponentModel.Composition; using Pretzel.Logic.Templating.Context; +using System.ComponentModel.Composition; namespace Pretzel.Logic.Templating { @@ -7,8 +7,9 @@ namespace Pretzel.Logic.Templating public interface ISiteEngine { void Initialize(); + bool CanProcess(SiteContext context); + void Process(SiteContext context, bool skipFileOnError = false); - string GetOutputDirectory(string path); } -} \ No newline at end of file +} diff --git a/src/Pretzel.Logic/Templating/JekyllEngineBase.cs b/src/Pretzel.Logic/Templating/JekyllEngineBase.cs index 85e37e39b..c8a1ae074 100644 --- a/src/Pretzel.Logic/Templating/JekyllEngineBase.cs +++ b/src/Pretzel.Logic/Templating/JekyllEngineBase.cs @@ -38,14 +38,12 @@ public void Process(SiteContext siteContext, bool skipFileOnError = false) Context = siteContext; PreProcess(); - var outputDirectory = Path.Combine(Context.SourceFolder, "_site"); - for (int index = 0; index < siteContext.Posts.Count; index++) { var p = siteContext.Posts[index]; var previous = GetPrevious(siteContext.Posts, index); var next = GetNext(siteContext.Posts, index); - ProcessFile(outputDirectory, p, previous, next, skipFileOnError, p.Filepath); + ProcessFile(siteContext.OutputFolder, p, previous, next, skipFileOnError, p.Filepath); } for (int index = 0; index < siteContext.Pages.Count; index++) @@ -53,7 +51,7 @@ public void Process(SiteContext siteContext, bool skipFileOnError = false) var p = siteContext.Pages[index]; var previous = GetPrevious(siteContext.Pages, index); var next = GetNext(siteContext.Pages, index); - ProcessFile(outputDirectory, p, previous, next, skipFileOnError); + ProcessFile(siteContext.OutputFolder, p, previous, next, skipFileOnError); } } @@ -67,12 +65,6 @@ private static Page GetPrevious(IList<Page> pages, int index) return index >= 1 ? pages[index - 1] : null; } - // TODO factorize with outputDirectory in Process(...)? - public virtual string GetOutputDirectory(string path) - { - return Path.Combine(path, "_site"); - } - private void ProcessFile(string outputDirectory, Page page, Page previous, Page next, bool skipFileOnError, string relativePath = "") { if (string.IsNullOrWhiteSpace(relativePath)) @@ -247,6 +239,7 @@ private void CreateOutputDirectory(string outputFile) } private static readonly string[] layoutExtensions = { ".html", ".htm" }; + protected virtual string[] LayoutExtensions { get { return layoutExtensions; } @@ -274,7 +267,6 @@ public bool CanProcess(SiteContext context) return context.Engine == engineInfo.Engine; } - private string FindLayoutPath(string layout) { foreach (var extension in LayoutExtensions) diff --git a/src/Pretzel.Tests/CommandParameterOutputTests.cs b/src/Pretzel.Tests/CommandParameterOutputTests.cs index 5935cab59..d2686b2c1 100644 --- a/src/Pretzel.Tests/CommandParameterOutputTests.cs +++ b/src/Pretzel.Tests/CommandParameterOutputTests.cs @@ -1,6 +1,7 @@ using Pretzel.Logic.Commands; using Pretzel.Logic.Extensibility; using System.IO; +using System.IO.Abstractions.TestingHelpers; using System.Linq; using Xunit; @@ -13,7 +14,7 @@ public class CommandParameterOutputTests public CommandParameterOutputTests() { - subject = new CommandParameters(Enumerable.Empty<IHaveCommandLineArgs>()); + subject = new CommandParameters(Enumerable.Empty<IHaveCommandLineArgs>(), new MockFileSystem()); writer = new StringWriter(); } diff --git a/src/Pretzel.Tests/CommandParameterTests.cs b/src/Pretzel.Tests/CommandParameterTests.cs index 12e8de167..9f54bcaf0 100644 --- a/src/Pretzel.Tests/CommandParameterTests.cs +++ b/src/Pretzel.Tests/CommandParameterTests.cs @@ -5,7 +5,8 @@ using Pretzel.Logic.Templating; using Pretzel.Logic.Templating.Context; using System.Collections.Generic; -using System.IO; +using System.IO.Abstractions; +using System.IO.Abstractions.TestingHelpers; using System.Linq; using Xunit; @@ -22,9 +23,11 @@ public class CommandParameterTests private const decimal ExpectedPortDecimal = 8000; private const string ExpectedDestinationPath = @"D:\Code\Generated"; + private readonly IFileSystem FileSystem = new MockFileSystem(); + public CommandParameterTests() { - subject = new CommandParameters(Enumerable.Empty<IHaveCommandLineArgs>()); + subject = new CommandParameters(Enumerable.Empty<IHaveCommandLineArgs>(), FileSystem); } [Fact] @@ -32,7 +35,8 @@ public void Parse_WhenNoParametersSet_MapsPathToCurrentDirectory() { var args = new List<string>(); subject.Parse(args); - Assert.Equal(Directory.GetCurrentDirectory(), subject.Path); + Assert.Equal(FileSystem.Directory.GetCurrentDirectory(), subject.Path); + Assert.Equal(FileSystem.Path.Combine(subject.Path, "_site"), subject.DestinationPath); } [Fact] @@ -299,6 +303,7 @@ public void CommandParameters_WhenSpecifyingAllParameters_ResultIsCorrect() Assert.True(subject.Wiki); Assert.True(subject.CleanTarget); Assert.True(subject.Safe); + Assert.Equal(@"c:\mysite\_site", subject.DestinationPath); } [Fact] @@ -311,13 +316,14 @@ public void CommandParameters_WhenSpecifyingNoParameters_DefaultVeluesResultIsCo Assert.Equal(8080, subject.Port); Assert.True(subject.LaunchBrowser); Assert.Null(subject.Template); - Assert.Equal(Directory.GetCurrentDirectory(), subject.Path); + Assert.Equal(FileSystem.Directory.GetCurrentDirectory(), subject.Path); Assert.Null(subject.ImportType); Assert.Null(subject.ImportPath); Assert.False(subject.IncludeDrafts); Assert.False(subject.WithProject); Assert.False(subject.Wiki); Assert.False(subject.CleanTarget); + Assert.Equal(FileSystem.Path.Combine(subject.Path, "_site"), subject.DestinationPath); } [Fact] @@ -332,7 +338,7 @@ public void CommandParameters_WhenSpecifyingCommandExtension_ExtensionParameterI options.Add<string>("newOption=", "description", v => NewOption = v); }); - var subject = new CommandParameters(new List<IHaveCommandLineArgs> { extension }); + var subject = new CommandParameters(new List<IHaveCommandLineArgs> { extension }, new MockFileSystem()); var args = new List<string> { "-newOption=test" }; subject.Parse(args); @@ -349,7 +355,8 @@ public void Parse_WhenOneParameterSet_MapsToPath_RelativePath() subject.Parse(args); - Assert.Equal(Path.Combine(Directory.GetCurrentDirectory(), "mySite"), subject.Path); + Assert.Equal(FileSystem.Path.Combine(FileSystem.Directory.GetCurrentDirectory(), "mySite"), subject.Path); + Assert.Equal(FileSystem.Path.Combine(subject.Path, "_site"), subject.DestinationPath); } [Fact] @@ -514,5 +521,13 @@ public void Parse_WhenSpecifyingDestinationPathUsingFullParameterSingleDash_Maps subject.Parse(args); Assert.Equal(ExpectedDestinationPath, subject.DestinationPath); } + + [Fact] + public void Parse_WhenNoParametersSet_MapsDestinationPathTo_siteInCurrentDirectory() + { + var args = new List<string>(); + subject.Parse(args); + Assert.Equal(FileSystem.Path.Combine(FileSystem.Directory.GetCurrentDirectory(), "_site"), subject.DestinationPath); + } } } diff --git a/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs b/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs index 02e509814..72e5eaaa1 100644 --- a/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs +++ b/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs @@ -1,20 +1,19 @@ -using System; +using NSubstitute; +using Pretzel.Logic.Extensibility; +using Pretzel.Logic.Extensions; +using Pretzel.Logic.Templating.Context; +using Pretzel.Tests.Templating.Jekyll; +using System; using System.Collections.Generic; using System.Globalization; +using System.IO; +using System.IO.Abstractions; using System.IO.Abstractions.TestingHelpers; using System.Linq; -using Pretzel.Logic.Extensibility; -using Pretzel.Logic.Templating.Context; -using Xunit; -using Xunit.Extensions; -using NSubstitute; -using DotLiquid.FileSystems; -using System.IO.Abstractions; -using System.IO; -using Pretzel.Logic.Extensions; using System.Text; using System.Threading; -using Pretzel.Tests.Templating.Jekyll; +using Xunit; +using Xunit.Extensions; namespace Pretzel.Tests.Templating.Context { @@ -36,7 +35,7 @@ public void site_context_generator_finds_posts() fileSystem.AddFile(@"C:\TestSite\_posts\2012-01-01-SomeFile.md", new MockFileData(ToPageContent("# Title"))); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.Equal(1, siteContext.Posts.Count); @@ -49,7 +48,7 @@ public void site_context_generator_processes_page_markdown() fileSystem.AddFile(@"C:\TestSite\_posts\2012-01-01-SomeFile.md", new MockFileData(ToPageContent("# Title"))); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.Equal("<h1>Title</h1>", siteContext.Posts[0].Content.Trim()); @@ -62,7 +61,7 @@ public void posts_do_not_include_pages() fileSystem.AddFile(@"C:\TestSite\SubFolder\SomeFile.md", new MockFileData(ToPageContent("# Title"))); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.Equal(0, siteContext.Posts.Count); @@ -71,12 +70,11 @@ public void posts_do_not_include_pages() [Fact] public void posts_without_front_matter_get_processed() { - // arrange fileSystem.AddFile(@"C:\TestSite\_posts\SomeFile.md", new MockFileData("# Title")); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.Equal(1, siteContext.Posts.Count); @@ -90,7 +88,7 @@ public void posts_without_front_matter_uses_convention_to_render_folder() var outputPath = string.Format("/{0}/{1}", DateTime.Now.ToString("yyyy'/'MM'/'dd"), "SomeFile.html"); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); var firstPost = siteContext.Posts.First(); @@ -106,7 +104,7 @@ public void posts_without_front_matter_and_override_config_renders_folder() var outputPath = string.Format("/blog/{0}/{1}", DateTime.Now.ToString("yyyy'/'MM'/'dd"), "SomeFile.html"); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); var firstPost = siteContext.Posts.First(); @@ -120,7 +118,7 @@ public void pages_without_front_matter_do_not_get_processed() fileSystem.AddFile(@"C:\TestSite\SubFolder\SomeFile.md", new MockFileData("# Title")); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.Equal(1, siteContext.Pages.Count); @@ -134,7 +132,7 @@ public void pages_with_front_matter_get_processed() fileSystem.AddFile(@"C:\TestSite\SubFolder\SomeFile.md", new MockFileData(ToPageContent("# Title"))); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.Equal(1, siteContext.Pages.Count); @@ -149,7 +147,7 @@ public void site_context_includes_pages_in_same_folder() fileSystem.AddFile(@"C:\TestSite\SubFolder\SomeFile2.md", new MockFileData(ToPageContent("# Title"))); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.Equal(2, siteContext.Pages[0].DirectoryPages.ToArray().Length); @@ -163,25 +161,24 @@ public void site_context_pages_have_correct_url() fileSystem.AddFile(@"C:\TestSite\SubFolder\SomeFile.md", new MockFileData(ToPageContent("# Title"))); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.Equal("/Index.html", siteContext.Pages[0].Url); Assert.Equal("/SubFolder/SomeFile.html", siteContext.Pages[1].Url); } - [Fact] public void site_context_does_not_cache_page() { // arrange fileSystem.AddFile(@"C:\TestSite\SubFolder\SomeFile.md", new MockFileData(ToPageContent("# Title"))); - generator.BuildContext(@"C:\TestSite", false); + generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); fileSystem.RemoveFile(@"C:\TestSite\SubFolder\SomeFile.md"); fileSystem.AddFile(@"C:\TestSite\SubFolder\SomeFile.md", new MockFileData(ToPageContent("# AnotherTitle"))); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.True(siteContext.Pages[0].Content.Contains("AnotherTitle"), "Site context should not cache output"); @@ -202,7 +199,7 @@ public void Generator_Extracts_Tags_From_Posts() fileSystem.AddFile(@"C:\TestSite\_posts\2012-01-03-File3.md", new MockFileData("---\n\r tags: [\"tag4\"]\n\r categories: [\"cat1\"]\n\r---\n\r Test")); fileSystem.AddFile(@"C:\TestSite\page.md", new MockFileData("---\n\r tags: [\"tag2\",\"tag3\"]\n\r categories: [\"cat1\"]\n\r---\n\r Test")); - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); Assert.Equal(4, siteContext.Tags.Count()); Assert.Equal(1, siteContext.Categories.Count()); @@ -235,7 +232,7 @@ public void Generator_Extracts_Categories_From_Posts() fileSystem.AddFile(@"C:\TestSite\_posts\2012-01-03-File3.md", new MockFileData("---\n\r categories: [\"cat4\"]\n\r tags: [\"tag1\"]\n\r---\n\r Test")); fileSystem.AddFile(@"C:\TestSite\page.md", new MockFileData("---\n\r categories: [\"cat2\",\"cat3\"]\n\r tags: [\"tag1\"]\n\r---\n\r Test")); - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); Assert.Equal(4, siteContext.Categories.Count()); Assert.Equal(1, siteContext.Tags.Count()); @@ -311,7 +308,7 @@ public void site_context_generator_finds_posts_and_drafts() fileSystem.AddFile(@"C:\TestSite\_drafts\SomeFile.md", new MockFileData(ToPageContent("# Draft"))); // act - var siteContext = generator.BuildContext(@"C:\TestSite", true); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", true); // assert Assert.Equal(2, siteContext.Posts.Count); @@ -322,7 +319,6 @@ public void site_context_generator_finds_posts_and_drafts() [InlineData(@"C:\TestSite\UsingDefault.md", true)] public void site_context_pages_have_date_in_bag(string fileName, bool useDefault) { - // note - this test does not include the time component. // arrange @@ -333,9 +329,9 @@ public void site_context_pages_have_date_in_bag(string fileName, bool useDefault fileSystem.AddFile(fileName, new MockFileData(ToPageContent("# Title"))); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); - // assert + // assert Assert.True(siteContext.Pages[0].Bag.ContainsKey("date")); Assert.IsType<DateTime>(siteContext.Pages[0].Bag["date"]); @@ -351,7 +347,7 @@ public void site_context_generator_processes_page_markdown_mkd() fileSystem.AddFile(@"C:\TestSite\_posts\2012-01-01-SomeFile.mkd", new MockFileData(ToPageContent("# Title"))); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.Equal("<h1>Title</h1>", siteContext.Posts[0].Content.Trim()); @@ -364,7 +360,7 @@ public void site_context_generator_processes_page_markdown_mkdn() fileSystem.AddFile(@"C:\TestSite\_posts\2012-01-01-SomeFile.mkdn", new MockFileData(ToPageContent("# Title"))); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.Equal("<h1>Title</h1>", siteContext.Posts[0].Content.Trim()); @@ -377,7 +373,7 @@ public void site_context_generator_processes_page_markdown_mdown() fileSystem.AddFile(@"C:\TestSite\_posts\2012-01-01-SomeFile.mdown", new MockFileData(ToPageContent("# Title"))); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.Equal("<h1>Title</h1>", siteContext.Posts[0].Content.Trim()); @@ -390,7 +386,7 @@ public void site_context_generator_processes_page_markdown_markdown() fileSystem.AddFile(@"C:\TestSite\_posts\2012-01-01-SomeFile.markdown", new MockFileData(ToPageContent("# Title"))); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.Equal("<h1>Title</h1>", siteContext.Posts[0].Content.Trim()); @@ -424,11 +420,11 @@ public void CanBeIncluded_Scenarios_Include() // arrange Func<string, bool> function = generator.CanBeIncluded; fileSystem.AddFile(@"C:\TestSite\_config.yml", new MockFileData(@"--- -pretzel: +pretzel: include: [_folder, .something-else, some-file.tmp, test\somefile.txt, subfolder\childfolder, anotherfolder\tempfile.tmp] ---")); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.True(function("folder")); @@ -454,11 +450,11 @@ public void CanBeIncluded_Scenarios_Exclude() // arrange Func<string, bool> function = generator.CanBeIncluded; fileSystem.AddFile(@"C:\TestSite\_config.yml", new MockFileData(@"--- -pretzel: +pretzel: exclude: [folder, .htaccess, some-file.tmp, test\somefile.txt, subfolder\childfolder, anotherfolder\tempfile.tmp] ---")); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.False(function("folder")); @@ -484,12 +480,12 @@ public void CanBeIncluded_Scenarios_IncludeExclude() // arrange Func<string, bool> function = generator.CanBeIncluded; fileSystem.AddFile(@"C:\TestSite\_config.yml", new MockFileData(@"--- -pretzel: +pretzel: include: [_folder, .something-else] exclude: [folder, test\somefile.txt] ---")); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // underscores are ignored Assert.False(function("folder")); @@ -527,7 +523,7 @@ public void permalink_with_numbered_category() var outputPath = "/blog/cat2/cat1/index.html"; // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); var firstPost = siteContext.Posts.First(); @@ -544,7 +540,7 @@ public void permalink_with_numbered_category_without_categories() var outputPath = "/blog/index.html"; // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); var firstPost = siteContext.Posts.First(); @@ -562,7 +558,7 @@ public void permalink_with_unnumbered_category() var outputPath = "/blog/cat/index.html"; // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); var firstPost = siteContext.Posts.First(); @@ -579,7 +575,7 @@ public void permalink_with_unnumbered_category_without_categories() var outputPath = "/blog/index.html"; // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); var firstPost = siteContext.Posts.First(); @@ -593,7 +589,7 @@ public void site_context_generator_processes_page_id_for_post() fileSystem.AddFile(@"C:\TestSite\_posts\2012-01-01-SomeFile.markdown", new MockFileData(ToPageContent("# Title"))); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.Equal("/2012/01/01/SomeFile", siteContext.Posts[0].Id); @@ -609,7 +605,7 @@ public void site_context_generator_processes_page_id_for_post_with_categories() # Title")); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.Equal("/2012/01/01/SomeFile", siteContext.Posts[0].Id); @@ -626,7 +622,7 @@ public void site_context_generator_processes_page_id_for_post_with_categories_an # Title")); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.Equal("/blog/cat1-cat2/2012/01/01/SomeFile/", siteContext.Posts[0].Id); @@ -639,7 +635,7 @@ public void site_context_generator_processes_page_id_for_page() fileSystem.AddFile(@"C:\TestSite\about.md", new MockFileData(ToPageContent("# Title"))); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.Equal("/about", siteContext.Pages[0].Id); @@ -655,7 +651,7 @@ public void site_context_generator_processes_page_id_for_page_with_permalink() # Title")); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.Equal("/about/", siteContext.Pages[0].Id); @@ -671,7 +667,7 @@ public void site_context_generator_processes_page_id_for_page_with_override() # Title")); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.Equal("/about", siteContext.Pages[0].Id); @@ -688,7 +684,7 @@ public void permalink_with_false_numbered_category() var outputPath = "/blog/cat1a/index.html"; // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); var firstPost = siteContext.Posts.First(); @@ -701,8 +697,7 @@ public void empty_file_is_processed_and_have_no_metadata() fileSystem.AddFile(@"C:\TestSite\SomeFile.md", MockFileData.NullObject); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); - + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); Assert.Equal(1, siteContext.Pages.Count); Assert.Equal(0, siteContext.Pages[0].Bag.Count); @@ -716,8 +711,7 @@ public void file_with_published_false_is_not_processed() ---# Title")); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); - + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); Assert.Equal(0, siteContext.Pages.Count); } @@ -730,7 +724,7 @@ public void page_default_values() ---# Title")); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); Assert.Equal(1, siteContext.Pages.Count); Assert.Equal("this is a post", siteContext.Pages[0].Title); @@ -754,7 +748,7 @@ public void page_metadata_values() currentDate))); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); Assert.Equal(1, siteContext.Pages.Count); Assert.Equal("my title", siteContext.Pages[0].Title); @@ -780,7 +774,7 @@ public void page_with_date_in_title() currentDate))); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); Assert.Equal(1, siteContext.Pages.Count); Assert.Equal("this is a post", siteContext.Pages[0].Title); @@ -803,7 +797,7 @@ public void page_with_false_date_in_title() currentDate))); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); Assert.Equal(1, siteContext.Pages.Count); Assert.Equal("this is a post", siteContext.Pages[0].Title); @@ -823,7 +817,7 @@ public void post_default_values() ---# Title")); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); Assert.Equal(1, siteContext.Posts.Count); Assert.Equal("this is a post", siteContext.Posts[0].Title); @@ -847,7 +841,7 @@ public void post_metadata_values() currentDate))); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); Assert.Equal(1, siteContext.Posts.Count); Assert.Equal("my title", siteContext.Posts[0].Title); @@ -873,7 +867,7 @@ public void post_with_date_in_title() currentDate))); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); Assert.Equal(1, siteContext.Posts.Count); Assert.Equal("this is a post", siteContext.Posts[0].Title); @@ -897,7 +891,7 @@ public void post_with_false_date_in_title() currentDate))); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); Assert.Equal(1, siteContext.Posts.Count); Assert.Equal("this is a post", siteContext.Posts[0].Title); @@ -944,13 +938,10 @@ public void file_with_1_ioexception_is_processed_and_have_no_metadata() fileSystemSubstitute.Directory.Returns(directorySubstitute); fileSystemSubstitute.FileInfo.Returns(fileInfoFactorySubstitute); - var generator = new SiteContextGenerator(fileSystemSubstitute, Enumerable.Empty<IContentTransform>()); - // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); - + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.Equal(1, siteContext.Pages.Count); @@ -987,9 +978,8 @@ public void file_with_2_ioexception_is_not_processed_and_throw_ioexception() var generator = new SiteContextGenerator(fileSystemSubstitute, Enumerable.Empty<IContentTransform>()); - // act & assert - Assert.Throws<IOException>(() => generator.BuildContext(@"C:\TestSite", false)); + Assert.Throws<IOException>(() => generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false)); // Check if the temp file have been deleted fileSubstitute.Received().Delete(filePath); } @@ -1009,8 +999,7 @@ public void page_with_false_date_is_not_processed() Tracing.Logger.AddCategory("debug"); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); - + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); Assert.Equal(0, siteContext.Pages.Count); Assert.Contains(@"Failed to build post from File: C:\TestSite\SomeFile.md", sb.ToString()); @@ -1030,8 +1019,7 @@ public void render_with_ContentTransformer_should_transform_content() var generator = new SiteContextGenerator(fileSystem, new[] { contentTransformer }); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); - + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); Assert.Equal(1, siteContext.Pages.Count); Assert.Equal("<h1>Title</h1><p>bar</p>", siteContext.Pages[0].Content.RemoveWhiteSpace()); @@ -1053,8 +1041,7 @@ public void render_with_ContentTransformer_exception_should_trace_the_error() var generator = new SiteContextGenerator(fileSystem, new[] { contentTransformer }); // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); - + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); Assert.Equal(1, siteContext.Pages.Count); Assert.Equal("<p><b>Error converting markdown</b></p><pre>---\r\n---# Title\r\n[foo]</pre>", siteContext.Pages[0].Content); @@ -1098,13 +1085,10 @@ public void file_with_1_ioexception_on_ReadAllText_is_processed() fileSystemSubstitute.Directory.Returns(directorySubstitute); fileSystemSubstitute.FileInfo.Returns(fileInfoFactorySubstitute); - var generator = new SiteContextGenerator(fileSystemSubstitute, Enumerable.Empty<IContentTransform>()); - // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); - + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.Equal(1, siteContext.Pages.Count); @@ -1150,9 +1134,8 @@ public void file_with_2_ioexception_on_ReadAllText_is_not_processed_and_exceptio var generator = new SiteContextGenerator(fileSystemSubstitute, Enumerable.Empty<IContentTransform>()); - // act - var siteContext = generator.BuildContext(@"C:\TestSite", false); + var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.Equal(0, siteContext.Pages.Count); @@ -1175,4 +1158,4 @@ public void RemoveDiacritics_should_return_null_if_input_null() Assert.Equal(null, SiteContextGenerator.RemoveDiacritics(null)); } } -} \ No newline at end of file +} diff --git a/src/Pretzel.Tests/Templating/Jekyll/LiquidEngineTests.cs b/src/Pretzel.Tests/Templating/Jekyll/LiquidEngineTests.cs index d1e3b0efe..51b38e3d1 100644 --- a/src/Pretzel.Tests/Templating/Jekyll/LiquidEngineTests.cs +++ b/src/Pretzel.Tests/Templating/Jekyll/LiquidEngineTests.cs @@ -20,7 +20,8 @@ public class When_Recieving_A_Folder_Containing_One_File : BakingEnvironment<Liq { private const string FileContents = "<html><head></head><body></body></html>"; private const string Folder = @"C:\website\"; - private readonly SiteContext context = new SiteContext { SourceFolder = Folder }; + private const string OutputFolder = @"C:\website\_site"; + private readonly SiteContext context = new SiteContext { SourceFolder = Folder, OutputFolder = OutputFolder }; public override LiquidEngine Given() { @@ -63,7 +64,8 @@ public class When_Recieving_A_Folder_Without_A_Trailing_Slash : BakingEnvironmen { private const string FileContents = "<html><head></head><body></body></html>"; private const string Folder = @"C:\website"; - private readonly SiteContext context = new SiteContext { SourceFolder = Folder }; + private const string OutputFolder = @"C:\website\_site"; + private readonly SiteContext context = new SiteContext { SourceFolder = Folder, OutputFolder = OutputFolder }; public override LiquidEngine Given() { @@ -93,7 +95,8 @@ public class When_Recieving_A_Folder_Containing_One_File_In_A_Subfolder : Baking { private const string FileContents = "<html><head></head><body></body></html>"; private const string Folder = @"C:\website"; - private readonly SiteContext context = new SiteContext { SourceFolder = Folder }; + private const string OutputFolder = @"C:\website\_site"; + private readonly SiteContext context = new SiteContext { SourceFolder = Folder, OutputFolder = OutputFolder }; public override LiquidEngine Given() { @@ -136,7 +139,8 @@ public class When_Recieving_A_File_With_Metadata : BakingEnvironment<LiquidEngin private const string FileContents = "<html><head><title>{{ page.title }}"; private const string OutputContents = ""; private const string Folder = @"C:\website"; - private readonly SiteContext context = new SiteContext { SourceFolder = Folder }; + private const string OutputFolder = @"C:\website\_site"; + private readonly SiteContext context = new SiteContext { SourceFolder = Folder, OutputFolder = OutputFolder }; public override LiquidEngine Given() { @@ -204,7 +208,7 @@ public override void When() FileSystem.AddFile(@"C:\website\index.md", new MockFileData(IndexContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -247,7 +251,7 @@ public override void When() } var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -300,7 +304,7 @@ public override void When() } var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -325,9 +329,10 @@ public void Page1_Is_Not_Generated() public class When_SiteContext_Specifies_Title : BakingEnvironment { private const string PageContents = "{{ page.title }}

Hello World!

"; - private readonly SiteContext context = new SiteContext { SourceFolder = Folder, Title = "My Web Site" }; + private readonly SiteContext context = new SiteContext { SourceFolder = Folder, OutputFolder = OutputFolder, Title = "My Web Site" }; private readonly string expectedfileContents = PageContents.Replace(@"{{ page.title }}", "My Web Site"); private const string Folder = @"C:\website"; + private const string OutputFolder = @"C:\website\_site"; public override LiquidEngine Given() { @@ -372,7 +377,7 @@ public override void When() FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); context.Title = "My Web Site"; Subject.FileSystem = FileSystem; Subject.Process(context); @@ -405,7 +410,7 @@ public override void When() { FileSystem.AddFile(@"C:\website\file.txt", new MockFileData(PageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); context.Title = "My Web Site"; Subject.FileSystem = FileSystem; Subject.Process(context); @@ -431,7 +436,7 @@ public override void When() { FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); context.Title = "My Web Site"; Subject.FileSystem = FileSystem; Subject.Process(context); @@ -460,7 +465,7 @@ public override void When() FileSystem.AddFile(@"C:\website\_layouts\default.html", new MockFileData(TemplateContents)); FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); context.Title = "My Web Site"; Subject.FileSystem = FileSystem; Subject.Process(context); @@ -490,7 +495,7 @@ public override void When() FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -524,7 +529,7 @@ public override void When() FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContents_1)); FileSystem.AddFile(@"C:\website\index2.md", new MockFileData(PageContents_2)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); context.Title = "My Web Site"; Subject.FileSystem = FileSystem; Subject.Process(context); @@ -561,7 +566,7 @@ public override void When() FileSystem.AddFile(@"C:\website\_layouts\default.html", new MockFileData(TemplateContents)); FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -599,7 +604,7 @@ public override void When() FileSystem.AddFile(@"C:\website\image.png", new MockFileData("png image")); FileSystem.AddFile(@"C:\website\image.gif", new MockFileData("gif image")); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -653,7 +658,7 @@ public override void When() FileSystem.AddFile(@"C:\website\_layouts\default.html", new MockFileData(TemplateContents)); FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - Context = generator.BuildContext(@"C:\website\", false); + Context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; } @@ -683,7 +688,7 @@ public override void When() FileSystem.AddFile(@"C:\website\_layouts\default.html", new MockFileData(TemplateContents)); FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - Context = generator.BuildContext(@"C:\website\", false); + Context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; } @@ -716,7 +721,7 @@ public override void When() { FileSystem.AddFile(@"C:\website\BadFormat.md", new MockFileData(BadFormatPageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - Context = generator.BuildContext(@"C:\website\", false); + Context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; } @@ -744,7 +749,7 @@ public override void When() { FileSystem.AddFile(@"C:\website\BadFormat.md", new MockFileData(BadFormatPageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - Context = generator.BuildContext(@"C:\website\", false); + Context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; } @@ -779,7 +784,7 @@ public override void When() FileSystem.AddFile(@"C:\website\BadFormat.md", new MockFileData(PageContents) { LastWriteTime = new DateTime(2010, 01, 3) }); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -807,7 +812,7 @@ public override void When() FileSystem.AddFile(@"C:\website\BadFormat.md", new MockFileData(PageContents) { LastWriteTime = new DateTime(2010, 01, 3) }); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -819,29 +824,6 @@ public void Existing_File_Should_Be_Not_Replaced() } } - public class Given_GetOutputDirectory_Method : BakingEnvironment - { - public override LiquidEngine Given() - { - return new LiquidEngine(); - } - - public override void When() - { - FileSystem.AddDirectory(@"C:\website\"); - var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); - Subject.FileSystem = FileSystem; - Subject.Process(context); - } - - [Fact] - public void Output_Directory_Should_Comport_site() - { - Assert.Equal(@"C:\mysite\_site", Subject.GetOutputDirectory(@"C:\mysite")); - } - } - public class Given_Site_Engine_Is_Liquid : BakingEnvironment { private SiteContext context; @@ -901,7 +883,7 @@ public override void When() FileSystem.AddFile(@"C:\website\index.html", new MockFileData(PageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -927,7 +909,7 @@ public override void When() { FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -954,7 +936,7 @@ public override void When() { FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -984,7 +966,7 @@ public override void When() FileSystem.AddFile(@"C:\website\index.md", new MockFileData(IndexContents)); FileSystem.AddFile(@"C:\website\_posts\2015-02-03-post.md", new MockFileData(PostContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -1016,7 +998,7 @@ public override void When() FileSystem.AddFile(@"C:\website\index.md", new MockFileData(IndexContents)); FileSystem.AddFile(@"C:\website\_posts\2015-02-03-post.md", new MockFileData(PostContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -1048,7 +1030,7 @@ public override void When() FileSystem.AddFile(@"C:\website\index.md", new MockFileData(IndexContents)); FileSystem.AddFile(@"C:\website\_posts\2015-02-03-post.md", new MockFileData(PostContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -1078,7 +1060,7 @@ public override void When() FileSystem.AddFile(@"C:\website\index.md", new MockFileData(IndexContents)); FileSystem.AddFile(@"C:\website\_posts\2015-02-03-post.md", new MockFileData(PostContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -1108,7 +1090,7 @@ public override void When() FileSystem.AddFile(@"C:\website\index.md", new MockFileData(IndexContents)); FileSystem.AddFile(@"C:\website\_posts\2015-02-03-post.md", new MockFileData(PostContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -1138,7 +1120,7 @@ public override void When() FileSystem.AddFile(@"C:\website\index.md", new MockFileData(IndexContents)); FileSystem.AddFile(@"C:\website\_posts\2015-02-03-post.md", new MockFileData(PostContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -1168,7 +1150,7 @@ public override void When() FileSystem.AddFile(@"C:\website\index.md", new MockFileData(IndexContents)); FileSystem.AddFile(@"C:\website\_posts\2015-02-03-post.md", new MockFileData(PostContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -1195,7 +1177,7 @@ public override void When() { FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -1222,7 +1204,7 @@ public override void When() { FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -1265,7 +1247,7 @@ public override void When() FileSystem.AddFile(@"C:\website\NumberOfWords.md", new MockFileData(NumberOfWordsPageContents)); FileSystem.AddFile(@"C:\website\XmlEscape.md", new MockFileData(XmlEscapePageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -1323,7 +1305,7 @@ public override void When() FileSystem.AddFile(@"C:\website\_layouts\default.html", new MockFileData(TemplateContents)); FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); context.Title = "My Web Site"; Subject.FileSystem = FileSystem; Subject.Process(context); @@ -1352,7 +1334,7 @@ public override void When() FileSystem.AddFile(@"C:\website\_layouts\default.html", new MockFileData(TemplateContents)); FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -1380,7 +1362,7 @@ public override void When() FileSystem.AddFile(@"C:\website\_layouts\default.htm", new MockFileData(TemplateContents)); FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -1408,7 +1390,7 @@ public override void When() FileSystem.AddFile(@"C:\website\_layouts\default.html", new MockFileData(TemplateContents)); FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -1437,7 +1419,7 @@ public override void When() FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); context.Title = "My Web Site"; Subject.FileSystem = FileSystem; Subject.Process(context); @@ -1471,7 +1453,7 @@ public override void When() FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); context.Title = "My Web Site"; Subject.FileSystem = FileSystem; Subject.Process(context); @@ -1499,7 +1481,7 @@ public override void When() FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); context.Title = "My Web Site"; Subject.FileSystem = FileSystem; Subject.Process(context); @@ -1529,7 +1511,7 @@ public override void When() { FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -1565,7 +1547,7 @@ public override void When() FileSystem.AddFile(@"C:\website\_posts\2015-02-02-post1.md", new MockFileData(Post1Contents)); FileSystem.AddFile(@"C:\website\_posts\2015-02-03-post2.md", new MockFileData(Post2Contents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -1593,7 +1575,7 @@ public override void When() { FileSystem.AddFile(@"C:\website\_posts\2015-02-02-post.md", new MockFileData(ContentWithCategory)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - Context = generator.BuildContext(@"C:\website\", false); + Context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(Context); } @@ -1627,7 +1609,7 @@ public override void When() { FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContent)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Tags = new List { new CustomTag() }; @@ -1666,7 +1648,7 @@ public override void When() { FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -1694,7 +1676,7 @@ public override void When() { FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContents)); var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } @@ -1705,5 +1687,61 @@ public void The_Filter_And_Block_Have_Been_Correctly_Interpreted() Assert.Equal(ExpectedfileContents, FileSystem.File.ReadAllText(@"C:\website\_site\index.html").RemoveWhiteSpace()); } } + + public class Given_OutputFolder_Is_Custom_Relative : BakingEnvironment + { + private const string PageContents = "---\r\n layout: nil \r\n---\r\n\r\n# title"; + private const string ExpectedfileContents = "

title

"; + + public override LiquidEngine Given() + { + var engine = new LiquidEngine(); + engine.Initialize(); + return engine; + } + + public override void When() + { + FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContents)); + var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_mysite", false); + Subject.FileSystem = FileSystem; + Subject.Process(context); + } + + [Fact] + public void The_File_Is_In_The_Right_Folder() + { + Assert.Equal(ExpectedfileContents, FileSystem.File.ReadAllText(@"C:\website\_mysite\index.html").RemoveWhiteSpace()); + } + } + + public class Given_OutputFolder_Is_Custom_Absolute : BakingEnvironment + { + private const string PageContents = "---\r\n layout: nil \r\n---\r\n\r\n# title"; + private const string ExpectedfileContents = "

title

"; + + public override LiquidEngine Given() + { + var engine = new LiquidEngine(); + engine.Initialize(); + return engine; + } + + public override void When() + { + FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContents)); + var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); + var context = generator.BuildContext(@"C:\website\", @"D:\Result\_site", false); + Subject.FileSystem = FileSystem; + Subject.Process(context); + } + + [Fact] + public void The_File_Is_In_The_Right_Folder() + { + Assert.Equal(ExpectedfileContents, FileSystem.File.ReadAllText(@"D:\Result\_site\index.html").RemoveWhiteSpace()); + } + } } } diff --git a/src/Pretzel.Tests/Templating/Razor/RazorEngineTests.cs b/src/Pretzel.Tests/Templating/Razor/RazorEngineTests.cs index 6daee64f0..2bce1e8aa 100644 --- a/src/Pretzel.Tests/Templating/Razor/RazorEngineTests.cs +++ b/src/Pretzel.Tests/Templating/Razor/RazorEngineTests.cs @@ -27,7 +27,7 @@ public override void When() private void ProcessContents(string layout, string content, Dictionary bag) { FileSystem.AddFile(@"C:\website\_layouts\Test.cshtml", new MockFileData(layout)); - var context = new SiteContext { SourceFolder = @"C:\website\", Title = "My Web Site" }; + var context = new SiteContext { SourceFolder = @"C:\website\", OutputFolder = @"C:\website\_site", Title = "My Web Site" }; bag.Add("layout", "Test"); context.Posts.Add(new Page { File = "index.cshtml", Content = content, OutputFile = @"C:\website\_site\index.html", Bag = bag }); FileSystem.AddFile(@"C:\website\index.cshtml", new MockFileData(layout)); @@ -239,7 +239,7 @@ public override void When() } var generator = new SiteContextGenerator(FileSystem, Enumerable.Empty()); - var context = generator.BuildContext(@"C:\website\", false); + var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false); Subject.FileSystem = FileSystem; Subject.Process(context); } diff --git a/src/Pretzel.Tests/Templating/Razor/When_Recieving_A_Razor_File.cs b/src/Pretzel.Tests/Templating/Razor/When_Recieving_A_Razor_File.cs index 8a0aa6a1b..7d5e9a3b4 100644 --- a/src/Pretzel.Tests/Templating/Razor/When_Recieving_A_Razor_File.cs +++ b/src/Pretzel.Tests/Templating/Razor/When_Recieving_A_Razor_File.cs @@ -1,17 +1,17 @@ -using System.Collections.Generic; -using System.IO.Abstractions.TestingHelpers; using Pretzel.Logic.Templating.Context; using Pretzel.Logic.Templating.Razor; using Pretzel.Tests.Templating.Jekyll; +using System.Collections.Generic; +using System.IO.Abstractions.TestingHelpers; using Xunit; namespace Pretzel.Tests.Templating.Razor { public class When_Recieving_A_Razor_File : BakingEnvironment { - const string TemplateContents = "@Model.Title@Raw(Model.Content)"; - const string PageContents = "

Hello World!

"; - const string ExpectedfileContents = "My Web Site

Hello World!

"; + private const string TemplateContents = "@Model.Title@Raw(Model.Content)"; + private const string PageContents = "

Hello World!

"; + private const string ExpectedfileContents = "My Web Site

Hello World!

"; public override RazorSiteEngine Given() { @@ -22,7 +22,7 @@ public override void When() { FileSystem.AddFile(@"C:\website\_layouts\default.cshtml", new MockFileData(TemplateContents)); FileSystem.AddFile(@"C:\website\index.cshtml", new MockFileData(PageContents)); - var context = new SiteContext { SourceFolder = @"C:\website\", Title = "My Web Site" }; + var context = new SiteContext { SourceFolder = @"C:\website\", OutputFolder = @"C:\website\_site", Title = "My Web Site" }; var dictionary = new Dictionary { {"layout", "default"} @@ -44,4 +44,4 @@ public void Does_Not_Copy_Template_To_Output() Assert.False(FileSystem.File.Exists(@"C:\website\_site\_layouts\default.html")); } } -} \ No newline at end of file +} diff --git a/src/Pretzel/Commands/BakeCommand.cs b/src/Pretzel/Commands/BakeCommand.cs index c2cdd1da8..88f4e0c86 100644 --- a/src/Pretzel/Commands/BakeCommand.cs +++ b/src/Pretzel/Commands/BakeCommand.cs @@ -16,11 +16,22 @@ namespace Pretzel.Commands public sealed class BakeCommand : ICommand { #pragma warning disable 649 - [Import] TemplateEngineCollection templateEngines; - [Import] SiteContextGenerator Generator { get; set; } - [Import] CommandParameters parameters; - [ImportMany] private IEnumerable transforms; - [Import] IFileSystem FileSystem; + + [Import] + private TemplateEngineCollection templateEngines; + + [Import] + private SiteContextGenerator Generator { get; set; } + + [Import] + private CommandParameters parameters; + + [ImportMany] + private IEnumerable transforms; + + [Import] + private IFileSystem FileSystem; + #pragma warning restore 649 public void Execute(IEnumerable arguments) @@ -29,7 +40,7 @@ public void Execute(IEnumerable arguments) parameters.Parse(arguments); - var siteContext = Generator.BuildContext(parameters.Path, parameters.IncludeDrafts); + var siteContext = Generator.BuildContext(parameters.Path, parameters.DestinationPath, parameters.IncludeDrafts); if (parameters.CleanTarget && FileSystem.Directory.Exists(siteContext.OutputFolder)) { @@ -52,7 +63,7 @@ public void Execute(IEnumerable arguments) t.Transform(siteContext); engine.CompressSitemap(siteContext, FileSystem); - + watch.Stop(); Tracing.Info(string.Format("done - took {0}ms", watch.ElapsedMilliseconds)); } diff --git a/src/Pretzel/Commands/TasteCommand.cs b/src/Pretzel/Commands/TasteCommand.cs index 3ce16cd11..8dcddb1cc 100644 --- a/src/Pretzel/Commands/TasteCommand.cs +++ b/src/Pretzel/Commands/TasteCommand.cs @@ -19,16 +19,22 @@ public sealed class TasteCommand : ICommand { private ISiteEngine engine; #pragma warning disable 649 + [Import] - TemplateEngineCollection templateEngines; + private TemplateEngineCollection templateEngines; + [Import] - SiteContextGenerator Generator { get; set; } + private SiteContextGenerator Generator { get; set; } + [Import] - CommandParameters parameters; + private CommandParameters parameters; + [ImportMany] private IEnumerable transforms; + [Import] - IFileSystem FileSystem; + private IFileSystem FileSystem; + #pragma warning restore 649 public void Execute(IEnumerable arguments) @@ -37,7 +43,7 @@ public void Execute(IEnumerable arguments) parameters.Parse(arguments); - var context = Generator.BuildContext(parameters.Path, parameters.IncludeDrafts); + var context = Generator.BuildContext(parameters.Path, parameters.DestinationPath, parameters.IncludeDrafts); if (parameters.CleanTarget && FileSystem.Directory.Exists(context.OutputFolder)) { @@ -64,11 +70,11 @@ public void Execute(IEnumerable arguments) foreach (var t in transforms) t.Transform(context); - using (var watcher = new SimpleFileSystemWatcher()) + using (var watcher = new SimpleFileSystemWatcher(parameters.DestinationPath)) { watcher.OnChange(parameters.Path, WatcherOnChanged); - // TODO see to replace engine.GetOutputDirectory by context.OutputFolder - using (var w = new WebHost(engine.GetOutputDirectory(parameters.Path), new FileContentProvider(), Convert.ToInt32(parameters.Port))) + + using (var w = new WebHost(parameters.DestinationPath, new FileContentProvider(), Convert.ToInt32(parameters.Port))) { try { @@ -114,7 +120,7 @@ private void WatcherOnChanged(string file) { Tracing.Info(string.Format("File change: {0}", file)); - var context = Generator.BuildContext(parameters.Path, parameters.IncludeDrafts); + var context = Generator.BuildContext(parameters.Path, parameters.DestinationPath, parameters.IncludeDrafts); if (parameters.CleanTarget && FileSystem.Directory.Exists(context.OutputFolder)) { FileSystem.Directory.Delete(context.OutputFolder, true); diff --git a/src/Pretzel/Modules/SimpleFileSystemWatcher.cs b/src/Pretzel/Modules/SimpleFileSystemWatcher.cs index c70740c7a..14bba706a 100644 --- a/src/Pretzel/Modules/SimpleFileSystemWatcher.cs +++ b/src/Pretzel/Modules/SimpleFileSystemWatcher.cs @@ -5,8 +5,15 @@ namespace Pretzel.Modules { public class SimpleFileSystemWatcher : IFileSystemWatcher, IDisposable { - readonly FileSystemWatcher watcher = new FileSystemWatcher(); - Action callback; + private readonly FileSystemWatcher watcher; + private readonly string destinationPath; + private Action callback; + + public SimpleFileSystemWatcher(string destinationPath) + { + watcher = new FileSystemWatcher(); + this.destinationPath = destinationPath; + } public void OnChange(string path, Action fileChangedCallback) { @@ -27,10 +34,11 @@ public void Dispose() watcher.Created -= WatcherOnChanged; } - string lastFile; + private string lastFile; + private void WatcherOnChanged(object sender, FileSystemEventArgs args) { - if (args.FullPath.Contains("_site")) + if (args.FullPath.Contains(destinationPath)) return; if (args.FullPath == lastFile) @@ -43,4 +51,4 @@ private void WatcherOnChanged(object sender, FileSystemEventArgs args) lastFile = args.FullPath; } } -} \ No newline at end of file +}