Skip to content

Commit d1fdbdc

Browse files
committed
merge
2 parents a3fc1b7 + 0436540 commit d1fdbdc

File tree

8 files changed

+75
-187
lines changed

8 files changed

+75
-187
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: .NET build
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
11+
build:
12+
13+
runs-on: windows-latest
14+
15+
env:
16+
Solution_Name: RazorEngineCore.sln
17+
Test_Project_Path: RazorEngineCore.Tests
18+
Pack_Project_Path: RazorEngineCore
19+
Configuration: Release
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v2
24+
with:
25+
fetch-depth: 0
26+
27+
- name: Build
28+
run: dotnet build $env:Solution_Name --configuration=$env:Configuration
29+
30+
- name: Execute unit tests
31+
run: dotnet test $env:Test_Project_Path --configuration=$env:Configuration --no-build
32+
33+
- name: Pack
34+
run: dotnet pack $env:Pack_Project_Path --configuration=$env:Configuration --no-build -o artifacts -p:symbolPackageFormat=snupkg --include-symbols
35+
36+
- name: Store nupkg
37+
uses: actions/upload-artifact@v2
38+
with:
39+
name: Nuget packages
40+
path: |
41+
artifacts
42+

ExampleAppNet472/App.config

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 9 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,16 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="..\packages\Microsoft.CodeAnalysis.Analyzers.3.3.0\build\Microsoft.CodeAnalysis.Analyzers.props" Condition="Exists('..\packages\Microsoft.CodeAnalysis.Analyzers.3.3.0\build\Microsoft.CodeAnalysis.Analyzers.props')" />
4-
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
53
<PropertyGroup>
6-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
7-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
8-
<ProjectGuid>{D27C1578-BFF9-4469-9099-DAF64450BBBE}</ProjectGuid>
94
<OutputType>Exe</OutputType>
10-
<RootNamespace>ExampleFrameworkApp</RootNamespace>
11-
<AssemblyName>ExampleFrameworkApp</AssemblyName>
12-
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
13-
<FileAlignment>512</FileAlignment>
14-
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
15-
<Deterministic>true</Deterministic>
16-
<NuGetPackageImportStamp>
17-
</NuGetPackageImportStamp>
5+
<TargetFramework>net472</TargetFramework>
186
</PropertyGroup>
19-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
20-
<PlatformTarget>AnyCPU</PlatformTarget>
21-
<DebugSymbols>true</DebugSymbols>
22-
<DebugType>full</DebugType>
23-
<Optimize>false</Optimize>
24-
<OutputPath>bin\Debug\</OutputPath>
25-
<DefineConstants>DEBUG;TRACE</DefineConstants>
26-
<ErrorReport>prompt</ErrorReport>
27-
<WarningLevel>4</WarningLevel>
28-
</PropertyGroup>
29-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
30-
<PlatformTarget>AnyCPU</PlatformTarget>
31-
<DebugType>pdbonly</DebugType>
32-
<Optimize>true</Optimize>
33-
<OutputPath>bin\Release\</OutputPath>
34-
<DefineConstants>TRACE</DefineConstants>
35-
<ErrorReport>prompt</ErrorReport>
36-
<WarningLevel>4</WarningLevel>
37-
</PropertyGroup>
38-
<ItemGroup>
39-
<Reference Include="Microsoft.AspNetCore.Razor.Language, Version=5.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
40-
<HintPath>..\packages\Microsoft.AspNetCore.Razor.Language.5.0.3\lib\netstandard2.0\Microsoft.AspNetCore.Razor.Language.dll</HintPath>
41-
</Reference>
42-
<Reference Include="Microsoft.CodeAnalysis, Version=3.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
43-
<HintPath>..\packages\Microsoft.CodeAnalysis.Common.3.8.0\lib\netstandard2.0\Microsoft.CodeAnalysis.dll</HintPath>
44-
</Reference>
45-
<Reference Include="Microsoft.CodeAnalysis.CSharp, Version=3.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
46-
<HintPath>..\packages\Microsoft.CodeAnalysis.CSharp.3.8.0\lib\netstandard2.0\Microsoft.CodeAnalysis.CSharp.dll</HintPath>
47-
</Reference>
48-
<Reference Include="System" />
49-
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
50-
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
51-
</Reference>
52-
<Reference Include="System.Collections.Immutable, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
53-
<HintPath>..\packages\System.Collections.Immutable.5.0.0\lib\net461\System.Collections.Immutable.dll</HintPath>
54-
</Reference>
55-
<Reference Include="System.Core" />
56-
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
57-
<HintPath>..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
58-
</Reference>
59-
<Reference Include="System.Numerics" />
60-
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
61-
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
62-
</Reference>
63-
<Reference Include="System.Reflection.Metadata, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
64-
<HintPath>..\packages\System.Reflection.Metadata.5.0.0\lib\net461\System.Reflection.Metadata.dll</HintPath>
65-
</Reference>
66-
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
67-
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.7.1\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
68-
</Reference>
69-
<Reference Include="System.Text.Encoding.CodePages, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
70-
<HintPath>..\packages\System.Text.Encoding.CodePages.4.7.1\lib\net461\System.Text.Encoding.CodePages.dll</HintPath>
71-
</Reference>
72-
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
73-
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
74-
</Reference>
75-
<Reference Include="System.Xml.Linq" />
76-
<Reference Include="System.Data.DataSetExtensions" />
77-
<Reference Include="Microsoft.CSharp" />
78-
<Reference Include="System.Data" />
79-
<Reference Include="System.Net.Http" />
80-
<Reference Include="System.Xml" />
81-
</ItemGroup>
82-
<ItemGroup>
83-
<Compile Include="Program.cs" />
84-
<Compile Include="Properties\AssemblyInfo.cs" />
85-
</ItemGroup>
86-
<ItemGroup>
87-
<None Include="App.config" />
88-
<None Include="packages.config" />
89-
</ItemGroup>
7+
908
<ItemGroup>
91-
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.3.3.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll" />
92-
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.3.3.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll" />
9+
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
9310
</ItemGroup>
11+
9412
<ItemGroup>
95-
<ProjectReference Include="..\RazorEngineCore\RazorEngineCore.csproj">
96-
<Project>{1e21186e-49a5-433a-abad-18ced1aa2494}</Project>
97-
<Name>RazorEngineCore</Name>
98-
</ProjectReference>
13+
<ProjectReference Include="..\RazorEngineCore\RazorEngineCore.csproj" />
9914
</ItemGroup>
100-
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
101-
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
102-
<PropertyGroup>
103-
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
104-
</PropertyGroup>
105-
<Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.Analyzers.3.3.0\build\Microsoft.CodeAnalysis.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.Analyzers.3.3.0\build\Microsoft.CodeAnalysis.Analyzers.props'))" />
106-
<Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.Analyzers.3.3.0\build\Microsoft.CodeAnalysis.Analyzers.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.Analyzers.3.3.0\build\Microsoft.CodeAnalysis.Analyzers.targets'))" />
107-
</Target>
108-
<Import Project="..\packages\Microsoft.CodeAnalysis.Analyzers.3.3.0\build\Microsoft.CodeAnalysis.Analyzers.targets" Condition="Exists('..\packages\Microsoft.CodeAnalysis.Analyzers.3.3.0\build\Microsoft.CodeAnalysis.Analyzers.targets')" />
109-
</Project>
15+
16+
</Project>

ExampleAppNet472/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 36 deletions
This file was deleted.

ExampleAppNet472/packages.config

Lines changed: 0 additions & 15 deletions
This file was deleted.

Pack.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
dotnet build -c Release
22
dotnet test
3-
dotnet pack -c Release -o artifacts RazorEngineCore\RazorEngineCore.csproj
3+
dotnet pack -c Release -o artifacts RazorEngineCore\RazorEngineCore.csproj -p:symbolPackageFormat=snupkg --include-symbols
44
dotnet nuget push artifacts\RazorEngineCore.2021.7.1.nupkg --source https://www.nuget.org/api/v2/package -k KEY

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Install-Package RazorEngineCore
2323
* [CodeProject: Building String Razor Template Engine with Bare Hands](https://www.codeproject.com/Articles/5260233/Building-String-Razor-Template-Engine-with-Bare-Ha)
2424

2525
## Wiki
26+
* [Package comparison: RazorEngineCore / RazorLight / RazorEngine.NetCore](https://github.com/adoconnection/RazorEngineCore/wiki/Package-comparison)
2627
* [Strongly typed model](https://github.com/adoconnection/RazorEngineCore/wiki/Strongly-typed-model)
2728
* [@Include and @Layout](https://github.com/adoconnection/RazorEngineCore/wiki/@Include-and-@Layout)
2829
* [@Raw](https://github.com/adoconnection/RazorEngineCore/wiki/@Raw)
@@ -33,6 +34,18 @@ Install-Package RazorEngineCore
3334

3435
## Extensions
3536
* [wdcossey/RazorEngineCore.Extensions](https://github.com/wdcossey/RazorEngineCore.Extensions)
37+
- HTML values encoded by default (See [issue #65](https://github.com/adoconnection/RazorEngineCore/issues/65) and [@Raw](https://github.com/adoconnection/RazorEngineCore/wiki/@Raw))
38+
- Template precompiling
39+
- Direct model usage without RazorEngineTemplateBase
40+
```cs
41+
template.Run(object model = null)
42+
template.RunAsync(object model = null)
43+
template.Run<TModel>(TModel model = null)
44+
template.RunAsync<TModel>(TModel model = null)
45+
```
46+
## :boom: HTML Safety
47+
RazorEngineCore is not HTML safe by default. \
48+
It can be easily turned on: see [#65](https://github.com/adoconnection/RazorEngineCore/issues/65) and [@Raw](https://github.com/adoconnection/RazorEngineCore/wiki/@Raw)
3649

3750
## Examples
3851

@@ -235,3 +248,6 @@ This package is inspired by [Simon Mourier SO post](https://stackoverflow.com/a/
235248
* 2020.2.3
236249
* Html attribute rendering fix
237250
* Html attribute rendering tests
251+
252+
## Supported by
253+
<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_square.svg" />

RazorEngineCore/RazorEngine.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ public class RazorEngine : IRazorEngine
1717
public IRazorEngineCompiledTemplate<T> Compile<T>(string content, Action<IRazorEngineCompilationOptionsBuilder> builderAction = null) where T : IRazorEngineTemplate
1818
{
1919
IRazorEngineCompilationOptionsBuilder compilationOptionsBuilder = new RazorEngineCompilationOptionsBuilder();
20-
20+
2121
compilationOptionsBuilder.AddAssemblyReference(typeof(T).Assembly);
2222
compilationOptionsBuilder.Inherits(typeof(T));
2323

2424
builderAction?.Invoke(compilationOptionsBuilder);
2525

2626
MemoryStream memoryStream = this.CreateAndCompileToStream(content, compilationOptionsBuilder.Options);
27-
27+
2828
return new RazorEngineCompiledTemplate<T>(memoryStream);
2929
}
3030

@@ -37,7 +37,7 @@ public IRazorEngineCompiledTemplate Compile(string content, Action<IRazorEngineC
3737
{
3838
IRazorEngineCompilationOptionsBuilder compilationOptionsBuilder = new RazorEngineCompilationOptionsBuilder();
3939
compilationOptionsBuilder.Inherits(typeof(RazorEngineTemplateBase));
40-
40+
4141
builderAction?.Invoke(compilationOptionsBuilder);
4242

4343
MemoryStream memoryStream = this.CreateAndCompileToStream(content, compilationOptionsBuilder.Options);
@@ -49,8 +49,8 @@ public Task<IRazorEngineCompiledTemplate> CompileAsync(string content, Action<IR
4949
{
5050
return Task.Factory.StartNew(() => this.Compile(content: content, builderAction: builderAction));
5151
}
52-
53-
private MemoryStream CreateAndCompileToStream(string templateSource, RazorEngineCompilationOptions options)
52+
53+
protected virtual MemoryStream CreateAndCompileToStream(string templateSource, RazorEngineCompilationOptions options)
5454
{
5555
templateSource = this.WriteDirectives(templateSource, options);
5656

@@ -65,7 +65,7 @@ private MemoryStream CreateAndCompileToStream(string templateSource, RazorEngine
6565
string fileName = Path.GetRandomFileName();
6666

6767
RazorSourceDocument document = RazorSourceDocument.Create(templateSource, fileName);
68-
68+
6969
RazorCodeDocument codeDocument = engine.Process(
7070
document,
7171
null,
@@ -123,7 +123,7 @@ private MemoryStream CreateAndCompileToStream(string templateSource, RazorEngine
123123
return memoryStream;
124124
}
125125

126-
private string WriteDirectives(string content, RazorEngineCompilationOptions options)
126+
protected virtual string WriteDirectives(string content, RazorEngineCompilationOptions options)
127127
{
128128
StringBuilder stringBuilder = new StringBuilder();
129129
stringBuilder.AppendLine($"@inherits {options.Inherits}");

0 commit comments

Comments
 (0)