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

Commit

Permalink
Replace RazorEngine with RazorEngine.NetCore (#351)
Browse files Browse the repository at this point in the history
* feat: use RazorEngine.NetCore instead of RazorEngine
* fix: use RazorEngine.Core.Pretzel
  • Loading branch information
biohazard999 authored and laedit committed Oct 21, 2019
1 parent 48729e0 commit a5912a6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 30 deletions.
5 changes: 2 additions & 3 deletions src/Pretzel.Logic/Pretzel.Logic.csproj
Expand Up @@ -37,10 +37,9 @@
<PackageReference Include="dotless.Core" Version="1.6.7" />
<PackageReference Include="DotLiquid" Version="2.0.314" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.12" />
<PackageReference Include="Microsoft.AspNet.Razor" Version="3.2.7" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.Extensions" Version="2.2.0" />
<PackageReference Include="NUglify" Version="1.5.13" />
<PackageReference Include="RazorEngine" Version="3.10.0" />
<PackageReference Include="RazorEngine.NetCore.Pretzel" Version="2.2.6" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="7.16.0.8981">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
56 changes: 29 additions & 27 deletions src/Pretzel.Logic/Templating/Razor/RazorSiteEngine.cs
Expand Up @@ -10,6 +10,7 @@
using Pretzel.Logic.Extensibility;
using System.Collections.Generic;
using System.Composition;
using Microsoft.AspNetCore.Mvc.Razor.Extensions;

namespace Pretzel.Logic.Templating.Razor
{
Expand All @@ -27,41 +28,41 @@ public override void Initialize()
{
}

private class TagComparer : IEqualityComparer<ITag>
{
public bool Equals(ITag x, ITag y)
{
if (x == null || y == null)
{
return false;
}

return x.Name == y.Name;
}

public int GetHashCode(ITag obj)
{
return obj.Name.GetHashCode();
}
}

protected override void PreProcess()
private class TagComparer : IEqualityComparer<ITag>
{
public bool Equals(ITag x, ITag y)
{
if (x == null || y == null)
{
return false;
}

return x.Name == y.Name;
}

public int GetHashCode(ITag obj)
{
return obj.Name.GetHashCode();
}
}

protected override void PreProcess()
{
includesPath = Path.Combine(Context.SourceFolder, "_includes");

if (Tags != null)
{
var toAdd = Tags.Except(_allTags, new TagComparer()).ToList();
_allTags.AddRange(toAdd);
var toAdd = Tags.Except(_allTags, new TagComparer()).ToList();
_allTags.AddRange(toAdd);
}

if (TagFactories != null)
{
var toAdd = TagFactories.Select(factory =>
{
factory.Initialize(Context);
return factory.CreateTag();
}).Except(_allTags, new TagComparer()).ToList();
var toAdd = TagFactories.Select(factory =>
{
factory.Initialize(Context);
return factory.CreateTag();
}).Except(_allTags, new TagComparer()).ToList();

_allTags.AddRange(toAdd);
}
Expand All @@ -79,7 +80,8 @@ protected override string RenderTemplate(string content, PageContext pageData)
TemplateManager = new IncludesResolver(FileSystem, includesPath),
BaseTemplateType = typeof(ExtensibleTemplate<>),
DisableTempFileLocking = true,
CachingProvider = new DefaultCachingProvider(t => { })
CachingProvider = new DefaultCachingProvider(t => { }),
ConfigureCompilerBuilder = builder => ModelDirective.Register(builder)
};
serviceConfiguration.Activator = new ExtensibleActivator(serviceConfiguration.Activator, Filters, _allTags);

Expand Down

0 comments on commit a5912a6

Please sign in to comment.