Skip to content

Commit

Permalink
Implement the RazorLight.Precompile tool (#492)
Browse files Browse the repository at this point in the history
* Suppress most of the compile time warnings.

* Expose the NormalizeKey logic to the outside.

* Implement the precompile command of the RazorLight.Precompile tool.

* Add unit tests for the precompile command of the RazorLight.Precompile tool.

* Implement the render command of the RazorLight.Precompile tool.

* Add unit tests for the render command of the RazorLight.Precompile tool.

* Add optional rendering ability to the precompile command

Co-authored-by: Kharitonov, Mark <mark.kharitonov@ceridian.com>
  • Loading branch information
MarkKharitonov and Kharitonov, Mark committed Oct 10, 2022
1 parent 732fc86 commit c7f97d6
Show file tree
Hide file tree
Showing 44 changed files with 1,657 additions and 609 deletions.
183 changes: 95 additions & 88 deletions RazorLight.sln
Original file line number Diff line number Diff line change
@@ -1,88 +1,95 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29609.76
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{25F57564-58FD-4FD2-8CDA-98261E5BEEEC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{CDB1D407-71F7-44D6-8B35-F0013D1717A6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorLight", "src\RazorLight\RazorLight.csproj", "{CA780663-2714-43B0-89BC-BEB26BC5405A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sandbox", "sandbox", "{D8281EA5-1C64-4C9F-9537-967D685C1918}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorLight.Sandbox", "sandbox\RazorLight.Sandbox\RazorLight.Sandbox.csproj", "{DC81E072-5571-4E4A-A7EC-4122BF4A012E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorLight.Tests", "tests\RazorLight.Tests\RazorLight.Tests.csproj", "{63EE1F3F-C71E-48DA-8135-9E602D6B7206}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{61D04B29-43F8-4FE3-A12E-BB16743BFB65}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Samples.EntityFrameworkProject", "samples\RazorLight.Samples\Samples.EntityFrameworkProject.csproj", "{C9B26DF6-F8E6-481A-B497-C8999641A99D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorLight.Precompile", "src\RazorLight.Precompile\RazorLight.Precompile.csproj", "{AD9A02F6-8078-4DFF-AFA6-4DE8674D5C76}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "External", "External", "{634B4E56-928A-4132-AB3F-F2DD43756350}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
LICENSE = LICENSE
README.md = README.md
README.source.md = README.source.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{DF8F9896-63C0-43AC-8834-1D13AA095928}"
ProjectSection(SolutionItems) = preProject
Directory.Build.props = Directory.Build.props
.github\workflows\dotnet.yml = .github\workflows\dotnet.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Publish", "Publish", "{03C519A7-C5B1-4421-893B-D2995D4A92BC}"
ProjectSection(SolutionItems) = preProject
makeNuget.cmd = makeNuget.cmd
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{EC25D85F-CCCC-43E1-AACD-2D710C1B760B}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CA780663-2714-43B0-89BC-BEB26BC5405A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CA780663-2714-43B0-89BC-BEB26BC5405A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CA780663-2714-43B0-89BC-BEB26BC5405A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CA780663-2714-43B0-89BC-BEB26BC5405A}.Release|Any CPU.Build.0 = Release|Any CPU
{DC81E072-5571-4E4A-A7EC-4122BF4A012E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DC81E072-5571-4E4A-A7EC-4122BF4A012E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DC81E072-5571-4E4A-A7EC-4122BF4A012E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DC81E072-5571-4E4A-A7EC-4122BF4A012E}.Release|Any CPU.Build.0 = Release|Any CPU
{63EE1F3F-C71E-48DA-8135-9E602D6B7206}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{63EE1F3F-C71E-48DA-8135-9E602D6B7206}.Debug|Any CPU.Build.0 = Debug|Any CPU
{63EE1F3F-C71E-48DA-8135-9E602D6B7206}.Release|Any CPU.ActiveCfg = Release|Any CPU
{63EE1F3F-C71E-48DA-8135-9E602D6B7206}.Release|Any CPU.Build.0 = Release|Any CPU
{C9B26DF6-F8E6-481A-B497-C8999641A99D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C9B26DF6-F8E6-481A-B497-C8999641A99D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9B26DF6-F8E6-481A-B497-C8999641A99D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9B26DF6-F8E6-481A-B497-C8999641A99D}.Release|Any CPU.Build.0 = Release|Any CPU
{AD9A02F6-8078-4DFF-AFA6-4DE8674D5C76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD9A02F6-8078-4DFF-AFA6-4DE8674D5C76}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD9A02F6-8078-4DFF-AFA6-4DE8674D5C76}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD9A02F6-8078-4DFF-AFA6-4DE8674D5C76}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{CA780663-2714-43B0-89BC-BEB26BC5405A} = {25F57564-58FD-4FD2-8CDA-98261E5BEEEC}
{DC81E072-5571-4E4A-A7EC-4122BF4A012E} = {D8281EA5-1C64-4C9F-9537-967D685C1918}
{63EE1F3F-C71E-48DA-8135-9E602D6B7206} = {CDB1D407-71F7-44D6-8B35-F0013D1717A6}
{C9B26DF6-F8E6-481A-B497-C8999641A99D} = {61D04B29-43F8-4FE3-A12E-BB16743BFB65}
{AD9A02F6-8078-4DFF-AFA6-4DE8674D5C76} = {25F57564-58FD-4FD2-8CDA-98261E5BEEEC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {590C5541-E5A7-41ED-AFC7-D4A52E594191}
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32616.157
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{25F57564-58FD-4FD2-8CDA-98261E5BEEEC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{CDB1D407-71F7-44D6-8B35-F0013D1717A6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorLight", "src\RazorLight\RazorLight.csproj", "{CA780663-2714-43B0-89BC-BEB26BC5405A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sandbox", "sandbox", "{D8281EA5-1C64-4C9F-9537-967D685C1918}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorLight.Sandbox", "sandbox\RazorLight.Sandbox\RazorLight.Sandbox.csproj", "{DC81E072-5571-4E4A-A7EC-4122BF4A012E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorLight.Tests", "tests\RazorLight.Tests\RazorLight.Tests.csproj", "{63EE1F3F-C71E-48DA-8135-9E602D6B7206}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{61D04B29-43F8-4FE3-A12E-BB16743BFB65}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Samples.EntityFrameworkProject", "samples\RazorLight.Samples\Samples.EntityFrameworkProject.csproj", "{C9B26DF6-F8E6-481A-B497-C8999641A99D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorLight.Precompile", "src\RazorLight.Precompile\RazorLight.Precompile.csproj", "{AD9A02F6-8078-4DFF-AFA6-4DE8674D5C76}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "External", "External", "{634B4E56-928A-4132-AB3F-F2DD43756350}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
LICENSE = LICENSE
README.md = README.md
README.source.md = README.source.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{DF8F9896-63C0-43AC-8834-1D13AA095928}"
ProjectSection(SolutionItems) = preProject
Directory.Build.props = Directory.Build.props
.github\workflows\dotnet.yml = .github\workflows\dotnet.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Publish", "Publish", "{03C519A7-C5B1-4421-893B-D2995D4A92BC}"
ProjectSection(SolutionItems) = preProject
makeNuget.cmd = makeNuget.cmd
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{EC25D85F-CCCC-43E1-AACD-2D710C1B760B}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RazorLight.Precompile.Tests", "tests\RazorLight.Precompile.Tests\RazorLight.Precompile.Tests.csproj", "{C9BA26CD-C20E-493C-A55A-C5498778184B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CA780663-2714-43B0-89BC-BEB26BC5405A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CA780663-2714-43B0-89BC-BEB26BC5405A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CA780663-2714-43B0-89BC-BEB26BC5405A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CA780663-2714-43B0-89BC-BEB26BC5405A}.Release|Any CPU.Build.0 = Release|Any CPU
{DC81E072-5571-4E4A-A7EC-4122BF4A012E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DC81E072-5571-4E4A-A7EC-4122BF4A012E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DC81E072-5571-4E4A-A7EC-4122BF4A012E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DC81E072-5571-4E4A-A7EC-4122BF4A012E}.Release|Any CPU.Build.0 = Release|Any CPU
{63EE1F3F-C71E-48DA-8135-9E602D6B7206}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{63EE1F3F-C71E-48DA-8135-9E602D6B7206}.Debug|Any CPU.Build.0 = Debug|Any CPU
{63EE1F3F-C71E-48DA-8135-9E602D6B7206}.Release|Any CPU.ActiveCfg = Release|Any CPU
{63EE1F3F-C71E-48DA-8135-9E602D6B7206}.Release|Any CPU.Build.0 = Release|Any CPU
{C9B26DF6-F8E6-481A-B497-C8999641A99D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C9B26DF6-F8E6-481A-B497-C8999641A99D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9B26DF6-F8E6-481A-B497-C8999641A99D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9B26DF6-F8E6-481A-B497-C8999641A99D}.Release|Any CPU.Build.0 = Release|Any CPU
{AD9A02F6-8078-4DFF-AFA6-4DE8674D5C76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD9A02F6-8078-4DFF-AFA6-4DE8674D5C76}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD9A02F6-8078-4DFF-AFA6-4DE8674D5C76}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD9A02F6-8078-4DFF-AFA6-4DE8674D5C76}.Release|Any CPU.Build.0 = Release|Any CPU
{C9BA26CD-C20E-493C-A55A-C5498778184B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C9BA26CD-C20E-493C-A55A-C5498778184B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9BA26CD-C20E-493C-A55A-C5498778184B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9BA26CD-C20E-493C-A55A-C5498778184B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{CA780663-2714-43B0-89BC-BEB26BC5405A} = {25F57564-58FD-4FD2-8CDA-98261E5BEEEC}
{DC81E072-5571-4E4A-A7EC-4122BF4A012E} = {D8281EA5-1C64-4C9F-9537-967D685C1918}
{63EE1F3F-C71E-48DA-8135-9E602D6B7206} = {CDB1D407-71F7-44D6-8B35-F0013D1717A6}
{C9B26DF6-F8E6-481A-B497-C8999641A99D} = {61D04B29-43F8-4FE3-A12E-BB16743BFB65}
{AD9A02F6-8078-4DFF-AFA6-4DE8674D5C76} = {25F57564-58FD-4FD2-8CDA-98261E5BEEEC}
{C9BA26CD-C20E-493C-A55A-C5498778184B} = {CDB1D407-71F7-44D6-8B35-F0013D1717A6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {590C5541-E5A7-41ED-AFC7-D4A52E594191}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<!-- This is what currently determines the version number. -->
<PropertyGroup>
<Version>2.1.0</Version>
<Version>2.1.1</Version>
</PropertyGroup>

</Project>
21 changes: 0 additions & 21 deletions src/RazorLight.Precompile/AssemblyMetadataGenerator.cs

This file was deleted.

53 changes: 0 additions & 53 deletions src/RazorLight.Precompile/CompilationOptions.cs

This file was deleted.

40 changes: 40 additions & 0 deletions src/RazorLight.Precompile/JsonModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;

namespace RazorLight.Precompile
{
public class JsonModel : DynamicObject
{
private readonly Dictionary<string, object> m_properties = new();

public static object New(JToken jsonToken)
{
return jsonToken switch
{
JObject o => new JsonModel(o),
JArray a => a.Select(New).ToList(),
JValue v => v.Value,
_ => jsonToken,
};
}

public JsonModel(JObject o)
{
foreach (var (key, value) in o)
{
m_properties[key] = New(value);
}
}

public override bool TryGetMember(GetMemberBinder binder, out object result)
{
if (!m_properties.TryGetValue(binder.Name, out result))
{
result = null;
}
return true;
}
}
}
77 changes: 0 additions & 77 deletions src/RazorLight.Precompile/PrecompilationApplication.cs

This file was deleted.

Loading

0 comments on commit c7f97d6

Please sign in to comment.