diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 73c6e280..46faaff3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,7 @@ name: CI on: push: branches: [ master ] - + jobs: build: name: Build @@ -30,14 +30,13 @@ jobs: os: [ macos-latest, ubuntu-latest, windows-2019 ] steps: - uses: actions/checkout@master - - name: Setup dotnet 2.1 - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 2.1.x - - name: Setup dotnet 3.1 + - name: Setup dotnet uses: actions/setup-dotnet@v1 with: - dotnet-version: 3.1.x + dotnet-version: | + 2.1.x + 3.1.x + 6.0.x - name: Clean package cache as a temporary workaround for https://github.com/actions/setup-dotnet/issues/155 working-directory: ./source run: dotnet clean -c Release && dotnet nuget locals all --clear @@ -52,14 +51,13 @@ jobs: - uses: actions/checkout@v2 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - name: Setup dotnet 2.1 - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 2.1.x - - name: Setup dotnet 3.1 + - name: Setup dotnet uses: actions/setup-dotnet@v1 with: - dotnet-version: 3.1.x + dotnet-version: | + 2.1.x + 3.1.x + 6.0.x - uses: actions/setup-java@v4 with: java-version: '21' # The JDK version to make available on the path. @@ -97,7 +95,7 @@ jobs: .\.sonar\scanner\dotnet-sonarscanner begin /k:"Handlebars-Net_Handlebars.Net" /o:"handlebars-net" /d:sonar.login="${{ env.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="**/*.opencover.xml" /d:sonar.cs.vstest.reportsPaths="**/*.trx" /d:sonar.coverage.exclusions="**/*.md;source/Handlebars.Benchmark/**/*.*" /d:sonar.cpd.exclusions="source/Handlebars/Iterators/**/*.*" dotnet build source/Handlebars.sln -c Release .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.login="${{ env.SONAR_TOKEN }}" - + benchmark: name: Run Benchmark.Net runs-on: ubuntu-latest @@ -105,7 +103,10 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-dotnet@v1 with: - dotnet-version: 3.1.x + dotnet-version: | + 2.1.x + 3.1.x + 6.0.x - name: Clean package cache as a temporary workaround for https://github.com/actions/setup-dotnet/issues/155 working-directory: ./source run: dotnet clean -c Release && dotnet nuget locals all --clear @@ -136,8 +137,8 @@ jobs: uses: actions/upload-artifact@v2 with: name: Benchmark - path: source/Handlebars.Benchmark/BenchmarkDotNet.Artifacts/results/ - + path: source/Handlebars.Benchmark/BenchmarkDotNet.Artifacts/results/ + update_release_draft: name: Release Drafter runs-on: ubuntu-latest diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 3ad79439..25301f4b 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -6,21 +6,24 @@ on: jobs: build: - name: Build + name: Build runs-on: windows-2019 steps: - uses: actions/checkout@master - name: Setup dotnet uses: actions/setup-dotnet@v1 with: - dotnet-version: 3.1.x + dotnet-version: | + 2.1.x + 3.1.x + 6.0.x - name: Clean package cache as a temporary workaround for https://github.com/actions/setup-dotnet/issues/155 working-directory: ./source run: dotnet clean -c Release && dotnet nuget locals all --clear - name: Build working-directory: ./source run: dotnet build -c Release - + test: name: Tests on ${{ matrix.os }} needs: [ build ] @@ -30,36 +33,34 @@ jobs: os: [ macos-latest, ubuntu-latest, windows-2019 ] steps: - uses: actions/checkout@master - - name: Setup dotnet 2.1 - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 2.1.x - - name: Setup dotnet 3.1 + - name: Setup dotnet uses: actions/setup-dotnet@v1 with: - dotnet-version: 3.1.x + dotnet-version: | + 2.1.x + 3.1.x + 6.0.x - name: Clean package cache as a temporary workaround for https://github.com/actions/setup-dotnet/issues/155 working-directory: ./source run: dotnet clean -c Release && dotnet nuget locals all --clear - name: Test working-directory: ./source run: dotnet test --logger:trx --logger:GitHubActions - + sonar-pr: name: SonarCloud runs-on: windows-2019 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v2 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - name: Setup dotnet 2.1 - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 2.1.x - - name: Setup dotnet 3.1 + - name: Setup dotnet uses: actions/setup-dotnet@v1 with: - dotnet-version: 3.1.x + dotnet-version: | + 2.1.x + 3.1.x + 6.0.x - uses: actions/setup-java@v4 with: java-version: '21' # The JDK version to make available on the path. @@ -105,7 +106,10 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-dotnet@v1 with: - dotnet-version: 3.1.x + dotnet-version: | + 2.1.x + 3.1.x + 6.0.x - name: Clean package cache as a temporary workaround for https://github.com/actions/setup-dotnet/issues/155 working-directory: ./source run: dotnet clean -c Release && dotnet nuget locals all --clear @@ -132,7 +136,7 @@ jobs: comment-on-alert: true fail-on-alert: false alert-comment-cc-users: '@zjklee' - + - name: Upload Artifacts uses: actions/upload-artifact@v2 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f8fca10a..338ea23b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,7 +21,10 @@ jobs: - name: Setup dotnet uses: actions/setup-dotnet@v1 with: - dotnet-version: 3.1.x + dotnet-version: | + 2.1.x + 3.1.x + 6.0.x - name: Clean package cache as a temporary workaround for https://github.com/actions/setup-dotnet/issues/155 working-directory: ./source diff --git a/source/Handlebars.Test/DynamicTests.cs b/source/Handlebars.Test/DynamicTests.cs index e5c75f3b..b11fc6d8 100644 --- a/source/Handlebars.Test/DynamicTests.cs +++ b/source/Handlebars.Test/DynamicTests.cs @@ -22,7 +22,7 @@ public class EnvGenerator : IEnumerable IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } - + [Fact] public void DynamicObjectBasicTest() { @@ -36,7 +36,7 @@ public void DynamicObjectBasicTest() Assert.Equal("Foo: 1\nBar: hello world", output); } - + [Fact] public void DynamicObjectBasicIterationTest() { @@ -106,7 +106,7 @@ public void JsonTestArrays(IHandlebars handlebars){ Assert.Equal("Key1Val1Key2Val2", output); } - + [Theory] [ClassData(typeof(EnvGenerator))] public void JsonTestArrayCount(IHandlebars handlebars) @@ -121,7 +121,7 @@ public void JsonTestArrayCount(IHandlebars handlebars) Assert.Equal("2", output); } - + [Theory] [ClassData(typeof(EnvGenerator))] public void JsonTestObjects(IHandlebars handlebars){ @@ -150,7 +150,7 @@ public void JObjectTest(IHandlebars handlebars) { Assert.Equal("", output); } - + [Theory] [ClassData(typeof(EnvGenerator))] public void WithParentIndexJsonNet(IHandlebars handlebars) @@ -174,7 +174,7 @@ public void WithParentIndexJsonNet(IHandlebars handlebars) {{/each}} {{/each}} {{/each}}"; - + var template = handlebars.Compile( source ); var data = new { @@ -281,13 +281,13 @@ public void WithParentIndexJsonNet(IHandlebars handlebars) index=[1:1:1] first=[False:False:False] last=[True:True:True]"; - + Func makeFlat = text => text.Replace( " ", "" ).Replace( "\n", "" ).Replace( "\r", "" ); Assert.Equal( makeFlat( expected ), makeFlat( result ) ); } -#if !netstandard +#if NET452 || NET46 || NET461 || NET472 [Fact] public void SystemJsonTestArrays() diff --git a/source/Handlebars.Test/Handlebars.Test.csproj b/source/Handlebars.Test/Handlebars.Test.csproj index a06a07ea..7205360e 100644 --- a/source/Handlebars.Test/Handlebars.Test.csproj +++ b/source/Handlebars.Test/Handlebars.Test.csproj @@ -1,7 +1,7 @@ - + - netcoreapp3.1 + netcoreapp3.1;net6 $(TargetFrameworks);net452;net46;net461;net472 6BA232A6-8C4D-4C7D-BD75-1844FE9774AF HandlebarsDotNet.Test @@ -9,33 +9,9 @@ false false true - - - 0618;1701 - - $(DefineConstants);netFramework - - - $(DefineConstants);netFramework - - - $(DefineConstants);netFramework - - - $(DefineConstants);netFramework - - - - $(DefineConstants);netcoreapp;netstandard - - - - $(DefineConstants);netcoreapp;netstandard - - @@ -52,7 +28,7 @@ - + @@ -60,18 +36,18 @@ - - + + - + - + diff --git a/source/Handlebars/Collections/ImmutableStack.cs b/source/Handlebars/Collections/ImmutableStack.cs index 54adb899..2401390b 100644 --- a/source/Handlebars/Collections/ImmutableStack.cs +++ b/source/Handlebars/Collections/ImmutableStack.cs @@ -4,19 +4,19 @@ namespace HandlebarsDotNet.Collections { -#if NET451 || NET452 +#if NET451 [Serializable] #endif internal readonly struct ImmutableStack { private readonly Node _container; - + [MethodImpl(MethodImplOptions.AggressiveInlining)] private ImmutableStack(T value, Node parent) :this(Node.Create(value, parent)) { } - + [MethodImpl(MethodImplOptions.AggressiveInlining)] private ImmutableStack(Node container) => _container = container; @@ -26,8 +26,8 @@ private ImmutableStack(T value, Node parent) [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Peek() { - return _container == null - ? default + return _container == null + ? default : _container.Value; } @@ -39,20 +39,20 @@ public ImmutableStack Pop(out T value) value = default; return this; } - + value = _container.Value; var parent = _container.Parent; _container.Dispose(); return new ImmutableStack(parent); } - -#if NET451 || NET452 + +#if NET451 [Serializable] #endif private sealed class Node : IDisposable { private static readonly InternalObjectPool Pool = new InternalObjectPool(new Policy()); - + public Node Parent; public T Value; @@ -63,9 +63,9 @@ public static Node Create(T value = default, Node parent = null) item.Parent = parent; return item; } - + private Node() { } - + private struct Policy : IInternalObjectPoolPolicy { public Node Create() => new Node(); diff --git a/source/Handlebars/Handlebars.csproj b/source/Handlebars/Handlebars.csproj index a8f0b5bd..df5c44d4 100644 --- a/source/Handlebars/Handlebars.csproj +++ b/source/Handlebars/Handlebars.csproj @@ -3,30 +3,11 @@ Handlebars 9822C7B8-7E51-42BC-9A49-72A10491B202 - netstandard1.3;netstandard2.0;netstandard2.1 - $(TargetFrameworks);net451;net452;net46 + netstandard1.3;netstandard2.0;netstandard2.1;net6 + $(TargetFrameworks);net451 2.0.0 HandlebarsDotNet true - - - - $(DefineConstants);netstandard;netstandard1_3 - - - $(DefineConstants);netstandard - - - $(DefineConstants);NET451 - - - $(DefineConstants);NET452 - - - $(DefineConstants);NET46 - - - Rex Morgan Copyright © 2014-2020 Rex Morgan Blistering-fast Handlebars.js templates in your .NET application. @@ -53,8 +34,8 @@ - - + + @@ -65,24 +46,17 @@ - + - - - - - + - - - - + diff --git a/source/Handlebars/IO/EncodedTextWriter.cs b/source/Handlebars/IO/EncodedTextWriter.cs index e70926be..8bb0f102 100644 --- a/source/Handlebars/IO/EncodedTextWriter.cs +++ b/source/Handlebars/IO/EncodedTextWriter.cs @@ -20,24 +20,24 @@ public bool SuppressEncoding { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => !_encoder.Enabled; - + [MethodImpl(MethodImplOptions.AggressiveInlining)] set => _encoder.Enabled = !value; } - + [MethodImpl(MethodImplOptions.AggressiveInlining)] public EncodedTextWriter( TextWriter writer, - ITextEncoder encoder, - IFormatterProvider formatterProvider, + ITextEncoder encoder, + IFormatterProvider formatterProvider, bool suppressEncoding = false) { UnderlyingWriter = writer; _formatterProvider = formatterProvider; - _encoder = encoder != null - ? TextEncoderWrapper.Create(encoder) + _encoder = encoder != null + ? TextEncoderWrapper.Create(encoder) : TextEncoderWrapper.Null; - + SuppressEncoding = suppressEncoding; } @@ -52,7 +52,7 @@ public void Write(string value, bool encode) _encoder.Encode(value, UnderlyingWriter); return; } - + UnderlyingWriter.Write(value); } @@ -70,7 +70,7 @@ public void Write(StringBuilder value, bool encode = true) UnderlyingWriter.Write(value[i]); } } - + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Write(Substring value, bool encode = true) { @@ -85,7 +85,7 @@ public void Write(Substring value, bool encode = true) UnderlyingWriter.Write(value[i]); } } - + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Write(T value, bool encode) where T: IEnumerator { @@ -100,7 +100,7 @@ public void Write(T value, bool encode) where T: IEnumerator UnderlyingWriter.Write(value.Current); } } - + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Write(string value) => Write(value, true); @@ -119,26 +119,26 @@ public void Write(T value) switch (value) { case null: - case string v when string.IsNullOrEmpty(v): + case string v when string.IsNullOrEmpty(v): case StringBuilder st when st.Length == 0: case Substring substring when substring.Length == 0: return; - + case string v: Write(v, true); return; case StringBuilder v: Write(v, true); return; - case Substring v: Write(v, true); return; - + case Substring v: Write(v, true); return; + default: WriteFormatted(value); return; } } - + [MethodImpl(MethodImplOptions.AggressiveInlining)] private void WriteFormatted(T value) { var type = typeof(T); -#if netstandard1_3 +#if NETSTANDARD1_3 if (type.GetTypeInfo().IsClass) type = value.GetType(); #else if (type.IsClass) type = value.GetType(); @@ -155,11 +155,11 @@ public Encoding Encoding [MethodImpl(MethodImplOptions.AggressiveInlining)] get => UnderlyingWriter.Encoding; } - + public void Dispose() => _encoder.Dispose(); - + public override string ToString() => UnderlyingWriter.ToString(); - + private static class Throw { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/source/Handlebars/Polyfills/AsyncLocal.cs b/source/Handlebars/Polyfills/AsyncLocal.cs index fe3a0903..66726133 100644 --- a/source/Handlebars/Polyfills/AsyncLocal.cs +++ b/source/Handlebars/Polyfills/AsyncLocal.cs @@ -1,4 +1,4 @@ -#if NET451 || NET452 +#if NET451 using System; using System.Runtime.CompilerServices; using System.Runtime.Remoting.Messaging; @@ -8,12 +8,12 @@ namespace HandlebarsDotNet.Polyfills public sealed class AsyncLocal { private const string Slot = "__AsyncLocalSlot"; - + public T Value { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => CallContext.LogicalGetData(Slot) is Container container - ? container.Value + get => CallContext.LogicalGetData(Slot) is Container container + ? container.Value : default; [MethodImpl(MethodImplOptions.AggressiveInlining)]