Skip to content

Commit

Permalink
V2.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jiniannet committed Dec 5, 2023
1 parent feace26 commit 0369ce4
Show file tree
Hide file tree
Showing 13 changed files with 220 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>TRACE;NETCOREAPP</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
16 changes: 16 additions & 0 deletions src/JinianNet.JNTemplate.Test/LogicTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using JinianNet.JNTemplate;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using Xunit;

Expand Down Expand Up @@ -437,5 +438,20 @@ public void TestIfOnes()
var render = template.Render(); ;
Assert.Equal("88.8", render);
}


/// <summary>
/// fixs #I8CNOA
/// </summary>
[Fact]
public void TestIfWithDecimal()
{
var templateContent = "${if(num>0)}Yes${else}No${end}";
var template = Engine.CreateTemplate(templateContent);
decimal num = 1;
template.Set("num", num);
var render = template.Render();
Assert.Equal("Yes", render);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ public static void LoadVariable(this ILGenerator il, Type type, int index)
/// <param name="type">The type.</param>
public static void EmitEquals(this ILGenerator il, Type type)
{
var equals = type.GetMethodInfo("Equals", new Type[] { type });
var equals = type.GetMethodInfo("op_Equality", new Type[] { type });
if (equals == null)
equals = type.GetMethodInfo("Equals", new Type[] { type });
//var ps = equals.GetParameters();
//if (ps.Length == 1
// && ps[0].ParameterType != type)
Expand Down
2 changes: 2 additions & 0 deletions src/JinianNet.JNTemplate/CodeCompilation/TypeGuesser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ public static bool IsPrimitive(Type type)
/// <returns></returns>
public static bool CanUseEqual(Type type)
{
if (type.FullName == "System.Decimal")
return false;
return IsNumber(type)
|| type.FullName == "System.Boolean"
|| type.IsEnum;
Expand Down
2 changes: 1 addition & 1 deletion src/JinianNet.JNTemplate/Const.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Const
/// <summary>
/// Version
/// </summary>
public const string Version = "2.2.5";
public const string Version = "2.4.2";
internal const string KEY_FOREACH = "foreach";
internal const string KEY_IF = "if";
internal const string KEY_ELSEIF = "elseif";
Expand Down
15 changes: 14 additions & 1 deletion src/JinianNet.JNTemplate/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using JinianNet.JNTemplate.Configuration;
using JinianNet.JNTemplate.CodeCompilation;
using System.Runtime.CompilerServices;

namespace JinianNet.JNTemplate
{
Expand All @@ -15,6 +16,7 @@ public sealed class Engine
{
private static volatile object state = new object();
private static IEngine engine;
private static string engineVersion;

/// <summary>
/// Gets or sets the engine instance.
Expand Down Expand Up @@ -42,7 +44,18 @@ public static IEngine Current
/// <summary>
/// The engine version.
/// </summary>
public static string Version => Const.Version;
public static string Version
{
get
{
if (string.IsNullOrEmpty(engineVersion))
{
var ver = typeof(Engine).Assembly.GetName().Version;
engineVersion = $"{ver.Major}.{ver.Minor}.{ver.Build}";
}
return engineVersion;
}
}

/// <summary>
///
Expand Down
32 changes: 28 additions & 4 deletions src/JinianNet.JNTemplate/JinianNet.JNTemplate.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp2.1;netcoreapp3.1;net20;net35;net40;net45;net46;net5.0;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp2.1;netcoreapp3.1;net20;net35;net40;net45;net46;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<AssemblyName>JinianNet.JNTemplate</AssemblyName>
<RootNamespace>JinianNet.JNTemplate</RootNamespace>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>2.4.1</Version>
<Version>2.4.2</Version>
<Authors>JinianNet.com</Authors>
<Company>JinianNet.com</Company>
<Product>JNTemplate</Product>
Expand All @@ -25,8 +25,8 @@
<PostBuildEvent></PostBuildEvent>
<AssemblyOriginatorKeyFile>jiniannet.snk</AssemblyOriginatorKeyFile>
<PackageLicenseFile>License.txt</PackageLicenseFile>
<FileVersion>2.4.1.0</FileVersion>
<AssemblyVersion>2.4.1.0</AssemblyVersion>
<FileVersion>2.4.2.0</FileVersion>
<AssemblyVersion>2.4.2.0</AssemblyVersion>
<DelaySign>false</DelaySign>
</PropertyGroup>

Expand Down Expand Up @@ -101,6 +101,30 @@
<DefineConstants Condition="'$(TargetFramework)' == 'net8.0'">TRACE;RELEASE;NET8;NET</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0|AnyCPU'">
<WarningLevel>7</WarningLevel>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0|AnyCPU'">
<WarningLevel>7</WarningLevel>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.1|AnyCPU'">
<WarningLevel>2</WarningLevel>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.1|AnyCPU'">
<WarningLevel>2</WarningLevel>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.0|AnyCPU'">
<WarningLevel>2</WarningLevel>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.0|AnyCPU'">
<WarningLevel>2</WarningLevel>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Reflection.Emit" Version="4.7.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.7.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/JinianNet.JNTemplate/Nodes/ITag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public interface ITag
bool Previous { get; set; }

/// <summary>
///
/// Gets or sets the next tag output mode
/// </summary>
bool Next { get; set; }
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/JinianNet.JNTemplate/Nodes/TagExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static string ToString(this TextTag tag, OutMode mode)
int len = StartsWithNewLine(text);
if (len > 0)
{
if (string.IsNullOrEmpty(text.Trim()))
if (text.Length <= len)
{
return string.Empty;
}
Expand Down
16 changes: 16 additions & 0 deletions src/JinianNet.JNTemplate/Resources/IResourceReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/********************************************************************************
Copyright (c) jiniannet (http://www.jiniannet.com). All rights reserved.
Licensed under the MIT license. See licence.txt file in the project root for full license information.
********************************************************************************/
using System;

namespace JinianNet.JNTemplate.Resources
{
/// <summary>
///
/// </summary>
public interface IResourceReader : IReader
{

}
}
19 changes: 19 additions & 0 deletions src/JinianNet.JNTemplate/Resources/ResourceChangedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/********************************************************************************
Copyright (c) jiniannet (http://www.jiniannet.com). All rights reserved.
Licensed under the MIT license. See licence.txt file in the project root for full license information.
********************************************************************************/
using System;

namespace JinianNet.JNTemplate.Resources
{
/// <summary>
///
/// </summary>
public class ResourceChangedEventArgs : EventArgs
{
/// <summary>
/// the path of the resources
/// </summary>
public string FullPath { get; set; }
}
}
33 changes: 33 additions & 0 deletions src/JinianNet.JNTemplate/Resources/ResourceManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/********************************************************************************
Copyright (c) jiniannet (http://www.jiniannet.com). All rights reserved.
Licensed under the MIT license. See licence.txt file in the project root for full license information.
********************************************************************************/
using JinianNet.JNTemplate.Hosting;
using System;
using System.Collections;
using System.Collections.Generic;

namespace JinianNet.JNTemplate.Resources
{
/// <summary>
/// 表示资源管理器,其可在运行时提供对于模板资源的便利访问
/// </summary>
public class ResourceManager : List<string>, ICollection<string>, IEnumerable<string>
{
/// <summary>
///
/// </summary>
public bool EnableWatch { get; set; }
//private List<string> resources;
private IHostEnvironment environment;
/// <summary>
///
/// </summary>
/// <param name="e"></param>
public ResourceManager(IHostEnvironment e)
{
environment = e;
}

}
}
82 changes: 82 additions & 0 deletions src/JinianNet.JNTemplate/Resources/TemplateReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/********************************************************************************
Copyright (c) jiniannet (http://www.jiniannet.com). All rights reserved.
Licensed under the MIT license. See licence.txt file in the project root for full license information.
********************************************************************************/
using System;
using System.IO;
using System.Threading;
#if !NF35 && !NF20
using System.Threading.Tasks;
#endif

namespace JinianNet.JNTemplate.Resources
{
/// <summary>
///
/// </summary>
public class TemplateReader : IResourceReader
{
private string resourcePath;
private string content;
private bool isComplete;

/// <summary>
///
/// </summary>
/// <param name="path"></param>
public TemplateReader(string path)
{
this.resourcePath = path;
this.isComplete = false;
}

/// <inheritdoc />
public string ReadToEnd(Context context)
{
if (!isComplete)
{
var res = context.Load(this.resourcePath);
if (res != null)
{
content = res.Content;
}
isComplete = true;
}
return content;
}

#region Task based Async APIs
#if !NF40 && !NF35 && !NF20
/// <inheritdoc />
#if NF45
public Task<string> ReadToEndAsync(Context context)
{
return Task.FromResult(ReadToEnd(context));
}
#else
public async Task<string> ReadToEndAsync(Context context)
{
if (!isComplete)
{
var res = await context.LoadAsync(this.resourcePath);
if (res != null)
{
content = res.Content;
}
isComplete = true;
}
return content;
}
#endif
#endif
#endregion


/// <inheritdoc />
public override int GetHashCode()
{
return resourcePath?.GetHashCode() ?? 0;
}
}
}

0 comments on commit 0369ce4

Please sign in to comment.