Skip to content

Commit

Permalink
配置调整 ,移除过期配置项
Browse files Browse the repository at this point in the history
  • Loading branch information
jiniannet committed Jul 26, 2021
1 parent ef49c58 commit 86ee1b4
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 62 deletions.
37 changes: 36 additions & 1 deletion src/JinianNet.JNTemplate/Configuration/EngineConfig.cs
Expand Up @@ -5,12 +5,14 @@
using JinianNet.JNTemplate.Resources;
using System;
using System.Collections.Generic;
using System.Text;

namespace JinianNet.JNTemplate.Configuration
{
/// <summary>
/// The default config of the engine.
/// </summary>
public class EngineConfig : Runtime.RuntimeOptions, IConfig
public class EngineConfig : IConfig
{
/// <summary>
/// Initializes a new instance of the <see cref="EngineConfig"/> class
Expand All @@ -29,5 +31,38 @@ public static EngineConfig CreateDefault()
{
return new EngineConfig();
}

/// <inheritdoc />
public bool DisableeLogogram { get; set; } = false;
/// <inheritdoc />
public string TagPrefix { get; set; } = "${";

/// <inheritdoc />
public string TagSuffix { get; set; } = "}";

/// <inheritdoc />
public char TagFlag { get; set; } = '$';

/// <inheritdoc />
public IDictionary<string, object> GlobalData { get; set; } = new Dictionary<string, object>();
/// <inheritdoc />
public Encoding Encoding { set; get; } = Encoding.UTF8;

/// <inheritdoc />
public List<string> ResourceDirectories { get; set; } = new List<string>();

/// <inheritdoc />
public bool EnableCompile { get; } = true;

/// <inheritdoc />
public bool EnableTemplateCache { get; set; } = true;

/// <inheritdoc />
public bool ThrowExceptions { get; set; } = true;

/// <inheritdoc />
public TypeDetect TypeDetectPattern { get; set; } = TypeDetect.Standard;
/// <inheritdoc />
public OutMode OutMode { get; set; } = OutMode.None;
}
}
35 changes: 6 additions & 29 deletions src/JinianNet.JNTemplate/Configuration/IConfig.cs
Expand Up @@ -17,24 +17,6 @@ namespace JinianNet.JNTemplate.Configuration
/// </summary>
public interface IConfig
{
/// <summary>
/// Gets or sets the charset of the engine.
/// </summary>
[Obsolete("please use Encoding")]
string Charset { get; set; }

/// <summary>
/// Gets or sets whether strip white-space.
/// </summary>
[Obsolete("please use OutMode")]
bool StripWhiteSpace { get; set; }

/// <summary>
/// IgnoreCase
/// </summary>
[Obsolete]
bool IgnoreCase { get; set; }

/// <summary>
/// Gets or sets whether disablee logogram .
/// </summary>
Expand All @@ -54,11 +36,6 @@ public interface IConfig
/// </summary>
char TagFlag { get; set; }

/// <summary>
/// Gets or sets the global data of the engine.
/// </summary>
IVariableScope Data { get; }

/// <summary>
/// Gets or sets the <see cref="Encoding"/> of the engine.
/// </summary>
Expand All @@ -68,7 +45,7 @@ public interface IConfig
/// Gets or sets the global resource directories of the engine.
/// </summary>
/// <value></value>
List<string> ResourceDirectories { get; }
List<string> ResourceDirectories { get; set; }

/// <summary>
/// Enable or disenable the compile mode.
Expand All @@ -85,11 +62,6 @@ public interface IConfig
/// </summary>
bool ThrowExceptions { get; set; }

// /// <summary>
// /// Gets or sets whether strip white-space.
// /// </summary>
//bool StripWhiteSpace { get; set; }

/// <summary>
/// Gets or sets the detect patterns.
/// </summary>
Expand All @@ -98,5 +70,10 @@ public interface IConfig
/// Gets or sets the output mode.
/// </summary>
OutMode OutMode { get; set; }

/// <summary>
/// Gets or sets the global data of the engine.
/// </summary>
IDictionary<string, object> GlobalData { get; }
}
}
2 changes: 1 addition & 1 deletion src/JinianNet.JNTemplate/Const.cs
Expand Up @@ -15,7 +15,7 @@ public class Const
/// <summary>
/// Version
/// </summary>
public const string Version = "2.2.1";
public const string Version = "2.2.2";
internal const string KEY_FOREACH = "foreach";
internal const string KEY_IF = "if";
internal const string KEY_ELSEIF = "elseif";
Expand Down
22 changes: 1 addition & 21 deletions src/JinianNet.JNTemplate/Engine.cs
Expand Up @@ -71,31 +71,11 @@ public static void Configure(Action<Runtime.IOptions, IVariableScope> action)
/// Configuration engine which <see cref="Runtime.IOptions"/>.
/// </summary>
/// <param name="option">The <see cref="Runtime.IOptions"/>.</param>
public static void Configure(Runtime.IOptions option)
public static void Configure(IConfig option)
{
Current.Configure(option);
}


/// <summary>
/// Configuration engine which <see cref="Runtime.IOptions"/>.
/// </summary>
/// <param name="option">The <see cref="Runtime.IOptions"/>.</param>
/// <param name="scope">The global <see cref="IVariableScope"/>.</param>
[Obsolete("please use Configure(Action<IOptions>)")]
public static void Configure(Runtime.IOptions option, IVariableScope scope)
{
if(scope!=null && scope.Count > 0)
{
var keys = scope.Keys;
foreach(var key in keys)
{
option.Data?.Set(key, scope[key], scope.GetType(key));
}
}
Current.Configure(option);
}

/// <summary>
/// Compile a template with a given file
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/JinianNet.JNTemplate/IEngine.cs
Expand Up @@ -36,7 +36,7 @@ public interface IEngine
/// </summary>
/// <param name="option">The <see cref="IOptions"/>.</param>
/// <returns>The <see cref="TemplatingEngine"/>.</returns>
IEngine Configure(IOptions option);
IEngine Configure(IConfig option);

/// <summary>
/// Compile a template with a given file
Expand Down
6 changes: 3 additions & 3 deletions src/JinianNet.JNTemplate/JinianNet.JNTemplate.csproj
Expand Up @@ -6,7 +6,7 @@
<RootNamespace>JinianNet.JNTemplate</RootNamespace>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>2.2.1</Version>
<Version>2.2.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.2.1.2</FileVersion>
<AssemblyVersion>2.2.1.0</AssemblyVersion>
<FileVersion>2.2.2.0</FileVersion>
<AssemblyVersion>2.2.2.0</AssemblyVersion>
<DelaySign>false</DelaySign>
</PropertyGroup>

Expand Down
63 changes: 61 additions & 2 deletions src/JinianNet.JNTemplate/Runtime/IOptions.cs
Expand Up @@ -4,14 +4,73 @@
********************************************************************************/

using JinianNet.JNTemplate.Configuration;
using System.Collections.Generic;
using System.Text;

namespace JinianNet.JNTemplate.Runtime
{
/// <summary>
/// Represents an global options.
/// </summary>
public interface IOptions : IConfig
public interface IOptions
{

/// <summary>
/// Gets or sets the global data of the engine.
/// </summary>
IVariableScope Data { get; }

/// <summary>
/// Gets or sets whether disablee logogram .
/// </summary>
bool DisableeLogogram { get; set; }
/// <summary>
/// Gets or sets the tag prefix .
/// </summary>
string TagPrefix { get; set; }

/// <summary>
/// Gets or sets the tag suffix.
/// </summary>
string TagSuffix { get; set; }

/// <summary>
/// Gets or sets the tag flag.
/// </summary>
char TagFlag { get; set; }

/// <summary>
/// Gets or sets the <see cref="Encoding"/> of the engine.
/// </summary>
Encoding Encoding { set; get; }

/// <summary>
/// Gets or sets the global resource directories of the engine.
/// </summary>
/// <value></value>
List<string> ResourceDirectories { get; }

/// <summary>
/// Enable or disenable the compile mode.
/// </summary>
bool EnableCompile { get; }

/// <summary>
/// Enable or disenable the cache.
/// </summary>
bool EnableTemplateCache { get; set; }

/// <summary>
/// Gets or sets whether throw exceptions.
/// </summary>
bool ThrowExceptions { get; set; }

/// <summary>
/// Gets or sets the detect patterns.
/// </summary>
TypeDetect TypeDetectPattern { get; set; }
/// <summary>
/// Gets or sets the output mode.
/// </summary>
OutMode OutMode { get; set; }
}
}
18 changes: 14 additions & 4 deletions src/JinianNet.JNTemplate/TemplatingEngine.cs
Expand Up @@ -71,7 +71,7 @@ public IEngine Configure(Action<IOptions> action)
}

/// <inheritdoc />
public IEngine Configure(IOptions option)
public IEngine Configure(IConfig option)
{
Options.DisableeLogogram = option.DisableeLogogram;
Options.TagPrefix = option.TagPrefix;
Expand All @@ -96,10 +96,20 @@ public IEngine Configure(IOptions option)
{
Options.EnableCompile = option.EnableCompile;
}
if((option.Data!=null && option.Data.Count > 0)
|| Options.Data.Count == 0)
if(option.GlobalData != null && option.GlobalData.Count > 0)
{
Options.Data = option.Data;
foreach(var kv in option.GlobalData)
{
if (kv.Value == null)
{
continue;
}
Options.Data.Set(kv.Key,kv.Value,kv.Value.GetType());
}
}
if(Options.TypeDetectPattern == TypeDetect.None && Options.EnableCompile)
{
Options.TypeDetectPattern = TypeDetect.Standard;
}
return this;
}
Expand Down

0 comments on commit 86ee1b4

Please sign in to comment.