diff --git a/src/Pretzel.Logic/Templating/JekyllEngineBase.cs b/src/Pretzel.Logic/Templating/JekyllEngineBase.cs index 4e9361405..85e37e39b 100644 --- a/src/Pretzel.Logic/Templating/JekyllEngineBase.cs +++ b/src/Pretzel.Logic/Templating/JekyllEngineBase.cs @@ -161,9 +161,9 @@ private void ProcessFile(string outputDirectory, Page page, Page previous, Page if ((string)layout == "nil" || layout == null) break; - var path = Path.Combine(Context.SourceFolder, "_layouts", layout + LayoutExtension); + var path = FindLayoutPath(layout.ToString()); - if (!FileSystem.File.Exists(path)) + if (path == null) break; try @@ -246,9 +246,10 @@ private void CreateOutputDirectory(string outputFile) FileSystem.Directory.CreateDirectory(directory); } - protected virtual string LayoutExtension + private static readonly string[] layoutExtensions = { ".html", ".htm" }; + protected virtual string[] LayoutExtensions { - get { return ".html"; } + get { return layoutExtensions; } } private IDictionary ProcessTemplate(PageContext pageContext, string path) @@ -272,5 +273,18 @@ public bool CanProcess(SiteContext context) if (engineInfo == null) return false; return context.Engine == engineInfo.Engine; } + + + private string FindLayoutPath(string layout) + { + foreach (var extension in LayoutExtensions) + { + var path = Path.Combine(Context.SourceFolder, "_layouts", layout + extension); + if (FileSystem.File.Exists(path)) + return path; + } + + return null; + } } } diff --git a/src/Pretzel.Logic/Templating/Razor/RazorSiteEngine.cs b/src/Pretzel.Logic/Templating/Razor/RazorSiteEngine.cs index 77eee4ec2..6325e6d6c 100644 --- a/src/Pretzel.Logic/Templating/Razor/RazorSiteEngine.cs +++ b/src/Pretzel.Logic/Templating/Razor/RazorSiteEngine.cs @@ -20,9 +20,10 @@ protected override void PreProcess() { } - protected override string LayoutExtension + private static readonly string[] layoutExtensions = { ".cshtml" }; + protected override string[] LayoutExtensions { - get { return ".cshtml"; } + get { return layoutExtensions; } } protected override string RenderTemplate(string content, PageContext pageData) diff --git a/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs b/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs index 6acca8563..2431aff1f 100644 --- a/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs +++ b/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs @@ -887,6 +887,7 @@ public void post_with_date_in_title() [Fact] public void post_with_false_date_in_title() { + Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; var currentDate = new DateTime(2015, 1, 26).ToShortDateString(); var filePath = string.Format(@"C:\TestSite\_posts\{0}SomeFile.md", currentDate.Replace("/", "-")); fileSystem.AddFile(filePath, new MockFileData(string.Format(@"--- diff --git a/src/Pretzel.Tests/Templating/Jekyll/LiquidEngineTests.cs b/src/Pretzel.Tests/Templating/Jekyll/LiquidEngineTests.cs index 6b41f0dbe..e787bae7c 100644 --- a/src/Pretzel.Tests/Templating/Jekyll/LiquidEngineTests.cs +++ b/src/Pretzel.Tests/Templating/Jekyll/LiquidEngineTests.cs @@ -1337,6 +1337,34 @@ public void The_Output_Should_Have_The_Page_Layout() } } + public class Given_Page_Has_A_Layout_With_An_Alternative_Extension : BakingEnvironment + { + private const string TemplateContents = "{{ content }}"; + private const string PageContents = "---\r\n layout: default \r\n---\r\n\r\n## Hello World!\r\n{{ page.layout }}"; + private const string ExpectedfileContents = "

Hello World!

default

"; + + public override LiquidEngine Given() + { + return new LiquidEngine(); + } + + 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); + Subject.FileSystem = FileSystem; + Subject.Process(context); + } + + [Fact] + public void The_Output_Should_Have_The_Page_Layout() + { + Assert.Equal(ExpectedfileContents, FileSystem.File.ReadAllText(@"C:\website\_site\index.html").RemoveWhiteSpace()); + } + } + public class Given_Page_Has_Comments_Metadata : BakingEnvironment { private const string TemplateContents = "{{ content }}";