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

Commit

Permalink
Fix CreateTag method not public
Browse files Browse the repository at this point in the history
And add tests
  • Loading branch information
Jérémie Bertrand committed Nov 9, 2015
1 parent 276934e commit 4d13480
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Pretzel.Logic/Extensibility/Extensions/PostUrlTag.cs
Expand Up @@ -61,7 +61,7 @@ public PostUrlTagFactory()
: base("PostUrl")
{ }

internal override ITag CreateTag()
public override ITag CreateTag()
{
return new PostUrlTag(SiteContext);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Pretzel.Logic/Extensibility/TagFactoryBase.cs
Expand Up @@ -29,7 +29,7 @@ public DotLiquid.Tag Create()
return (DotLiquid.Tag)CreateTag();
}

internal abstract ITag CreateTag();
public abstract ITag CreateTag();

internal void Initialize(SiteContext siteContext)
{
Expand Down
65 changes: 65 additions & 0 deletions src/Pretzel.Tests/Templating/Jekyll/LiquidEngineTests.cs
Expand Up @@ -2124,5 +2124,70 @@ public void Mkd_File_Should_Be_Rendered()
Assert.Equal("<h1>Title</h1>", FileSystem.File.ReadAllText(@"D:\Result\_site\2012\01\04\SomeFile.html"));
}
}
public class Given_Engine_Has_Custom_TagFactory : BakingEnvironment<LiquidEngine>
{
private const string ConfigContents = "---\r\n title: Site Title\r\n---";
private const string PageContent = "---\r\n \r\n---\r\n{% custom %}";
private const string ExpectedPageContents = "<p>custom tag: Site Title</p>";

public override LiquidEngine Given()
{
return new LiquidEngine();
}

public override void When()
{
FileSystem.AddFile(@"C:\website\_config.yml", new MockFileData(ConfigContents));
FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContent));
var generator = GetSiteContextGenerator(FileSystem);
var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false);
Subject.FileSystem = FileSystem;

Subject.TagFactories = new List<TagFactoryBase> { new CustomTagFactory() };

Subject.Process(context);
}

[Fact]
public void Page_should_contain_custom_tag()
{
Assert.Equal(ExpectedPageContents, FileSystem.File.ReadAllText(@"C:\website\_site\index.html").RemoveWhiteSpace());
}

public class CustomTag : DotLiquid.Tag, ITag
{
private SiteContext _siteContext;

public new string Name { get { return "Custom"; } }

public CustomTag(SiteContext siteContext)
{
_siteContext = siteContext;
}

public string Custom()
{
return string.Format("custom tag: {0}", _siteContext.Config["title"]);
}

public override void Render(DotLiquid.Context context, TextWriter result)
{
result.WriteLine(Custom());
}
}

public class CustomTagFactory : TagFactoryBase
{
public CustomTagFactory():base("Custom")
{

}

public override ITag CreateTag()
{
return new CustomTag(this.SiteContext);
}
}
}
}
}
66 changes: 66 additions & 0 deletions src/Pretzel.Tests/Templating/Razor/RazorEngineTests.cs
Expand Up @@ -309,4 +309,70 @@ public void Posts_Properly_Paginated()
FileSystem.File.ReadAllText(@"C:\website\_site\blog\page4\index.html").RemoveWhiteSpace());
}
}

public class Given_Engine_Has_Custom_TagFactory : BakingEnvironment<RazorSiteEngine>
{
private const string ConfigContents = "---\r\n title: Site Title\r\n---";
private const string PageContent = "---\r\n \r\n---\r\n@Tag.Custom()";
private const string ExpectedPageContents = "<p>custom tag: Site Title</p>";

public override RazorSiteEngine Given()
{
return new RazorSiteEngine();
}

public override void When()
{
FileSystem.AddFile(@"C:\website\_config.yml", new MockFileData(ConfigContents));
FileSystem.AddFile(@"C:\website\index.md", new MockFileData(PageContent));
var generator = new SiteContextGenerator(FileSystem, new LinkHelper());
var context = generator.BuildContext(@"C:\website\", @"C:\website\_site", false);
Subject.FileSystem = FileSystem;

Subject.TagFactories = new List<TagFactoryBase> { new CustomTagFactory() };

Subject.Process(context);
}

[Fact]
public void Page_should_contain_custom_tag()
{
Assert.Equal(ExpectedPageContents, FileSystem.File.ReadAllText(@"C:\website\_site\index.html").RemoveWhiteSpace());
}

public class CustomTag : DotLiquid.Tag, ITag
{
private SiteContext _siteContext;

public new string Name { get { return "Custom"; } }

public CustomTag(SiteContext siteContext)
{
_siteContext = siteContext;
}

public string Custom()
{
return string.Format("custom tag: {0}", _siteContext.Config["title"]);
}

public override void Render(DotLiquid.Context context, TextWriter result)
{
result.WriteLine(Custom());
}
}

public class CustomTagFactory : TagFactoryBase
{
public CustomTagFactory() : base("Custom")
{

}

public override ITag CreateTag()
{
return new CustomTag(this.SiteContext);
}
}
}
}
12 changes: 10 additions & 2 deletions src/Pretzel/Program.cs
@@ -1,7 +1,6 @@
using NDesk.Options;
using Pretzel.Commands;
using Pretzel.Logic.Commands;
using Pretzel.Logic.Extensibility;
using Pretzel.Logic.Extensions;
using System;
using System.ComponentModel.Composition;
Expand Down Expand Up @@ -134,7 +133,16 @@ private void AddScriptCs(AggregateCatalog mainCatalog, string pluginsPath)
var scriptCsCatalogMethod = factoryType.GetMethod("CreateScriptCsCatalog");
if (scriptCsCatalogMethod != null)
{
var catalog = (ComposablePartCatalog)scriptCsCatalogMethod.Invoke(null, new object[] { pluginsPath, new[] { typeof(DotLiquid.Tag), typeof(ITag) } });
var catalog = (ComposablePartCatalog)scriptCsCatalogMethod.Invoke(null, new object[]
{
pluginsPath,
new[]
{
typeof(DotLiquid.Tag),
typeof(Logic.Extensibility.ITag),
typeof(Logic.Templating.Context.SiteContext)
}
});
mainCatalog.Catalogs.Add(catalog);
}
else
Expand Down

0 comments on commit 4d13480

Please sign in to comment.