Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

Commit

Permalink
Merge pull request #213 from wesleyalcoforado/master
Browse files Browse the repository at this point in the history
Adds .htm extension for layouts
  • Loading branch information
Jérémie Bertrand committed Feb 15, 2015
2 parents 090b8d2 + e211979 commit b74b604
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
22 changes: 18 additions & 4 deletions src/Pretzel.Logic/Templating/JekyllEngineBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<string, object> ProcessTemplate(PageContext pageContext, string path)
Expand All @@ -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;
}
}
}
5 changes: 3 additions & 2 deletions src/Pretzel.Logic/Templating/Razor/RazorSiteEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,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(@"---
Expand Down
28 changes: 28 additions & 0 deletions src/Pretzel.Tests/Templating/Jekyll/LiquidEngineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,34 @@ public void The_Output_Should_Have_The_Page_Layout()
}
}

public class Given_Page_Has_A_Layout_With_An_Alternative_Extension : BakingEnvironment<LiquidEngine>
{
private const string TemplateContents = "<html><body>{{ content }}</body></html>";
private const string PageContents = "---\r\n layout: default \r\n---\r\n\r\n## Hello World!\r\n{{ page.layout }}";
private const string ExpectedfileContents = "<html><body><h2>Hello World!</h2><p>default</p></body></html>";

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<IContentTransform>());
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<LiquidEngine>
{
private const string TemplateContents = "<html><body>{{ content }}</body></html>";
Expand Down

0 comments on commit b74b604

Please sign in to comment.