diff --git a/src/Luban.Job.Cfg/Source/RenderExtension.cs b/src/Luban.Job.Cfg/Source/RenderExtension.cs index b828059..105211b 100644 --- a/src/Luban.Job.Cfg/Source/RenderExtension.cs +++ b/src/Luban.Job.Cfg/Source/RenderExtension.cs @@ -1,6 +1,7 @@ using Luban.Job.Cfg.Datas; using Luban.Job.Cfg.Defs; using Luban.Job.Cfg.Utils; +using Luban.Job.Common.Utils; using Scriban; using System.Collections.Generic; @@ -10,7 +11,7 @@ namespace Luban.Job.Cfg { public static string RenderCode(this Template template, object model, Dictionary extraModels = null) { - var ctx = new TemplateContext(); + var ctx = TemplateUtil.CreateDefaultTemplateContext(); var env = new TTypeTemplateExtends { ["x"] = model, @@ -29,8 +30,7 @@ namespace Luban.Job.Cfg public static string RenderDatas(this Template template, DefTable table, List exportDatas, Dictionary extraModels = null) { - var ctx = new TemplateContext(); - + var ctx = TemplateUtil.CreateDefaultTemplateContext(); var env = new DTypeTemplateExtends { ["table"] = table, @@ -51,8 +51,7 @@ namespace Luban.Job.Cfg public static string RenderData(this Template template, DefTable table, DBean data, Dictionary extraModels = null) { - var ctx = new TemplateContext(); - + var ctx = TemplateUtil.CreateDefaultTemplateContext(); var env = new DTypeTemplateExtends { ["table"] = table, diff --git a/src/Luban.Job.Common/Source/Utils/TemplateUtil.cs b/src/Luban.Job.Common/Source/Utils/TemplateUtil.cs new file mode 100644 index 0000000..a73bf66 --- /dev/null +++ b/src/Luban.Job.Common/Source/Utils/TemplateUtil.cs @@ -0,0 +1,21 @@ +using Scriban; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Luban.Job.Common.Utils +{ + public static class TemplateUtil + { + public static TemplateContext CreateDefaultTemplateContext() + { + return new TemplateContext() + { + LoopLimit = 0, + NewLine = "\n", + }; + } + } +} diff --git a/src/Luban.Job.Db/Source/RenderExtension.cs b/src/Luban.Job.Db/Source/RenderExtension.cs index 51b9db6..fd542d5 100644 --- a/src/Luban.Job.Db/Source/RenderExtension.cs +++ b/src/Luban.Job.Db/Source/RenderExtension.cs @@ -1,3 +1,4 @@ +using Luban.Job.Common.Utils; using Luban.Job.Db.Defs; using Scriban; using System.Collections.Generic; @@ -8,7 +9,7 @@ namespace Luban.Job.Db { public static string RenderCode(this Template template, object model, Dictionary extraModels = null) { - var ctx = new TemplateContext(); + var ctx = TemplateUtil.CreateDefaultTemplateContext(); var env = new TTypeTemplateExtends { ["x"] = model diff --git a/src/Luban.Job.Proto/Source/RenderExtension.cs b/src/Luban.Job.Proto/Source/RenderExtension.cs index a167392..92ed82a 100644 --- a/src/Luban.Job.Proto/Source/RenderExtension.cs +++ b/src/Luban.Job.Proto/Source/RenderExtension.cs @@ -1,3 +1,4 @@ +using Luban.Job.Common.Utils; using Luban.Job.Proto.Defs; using Scriban; using System.Collections.Generic; @@ -8,7 +9,7 @@ namespace Luban.Job.Proto { public static string RenderCode(this Template template, object model, Dictionary extraModels = null) { - var ctx = new TemplateContext(); + var ctx = TemplateUtil.CreateDefaultTemplateContext(); var env = new TTypeTemplateExtends { ["x"] = model