From 16e4fe2452fba6cf509e365c774ddc3aa81b3335 Mon Sep 17 00:00:00 2001 From: walon Date: Fri, 10 Feb 2023 14:37:07 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E4=BF=AE=E5=A4=8D=E4=BD=BF=E7=94=A8Scr?= =?UTF-8?q?iban=E5=AF=BC=E5=87=BA=E5=A4=A7=E5=9E=8B=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E5=9E=8B=E6=95=B0=E6=8D=AE=E6=97=B6=E5=8F=91=E7=94=9F=E8=B6=85?= =?UTF-8?q?=E5=87=BA=E6=9C=80=E5=A4=A7=E8=BF=AD=E4=BB=A3=E6=AC=A1=E6=95=B0?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Luban.Job.Cfg/Source/RenderExtension.cs | 9 ++++---- .../Source/Utils/TemplateUtil.cs | 21 +++++++++++++++++++ src/Luban.Job.Db/Source/RenderExtension.cs | 3 ++- src/Luban.Job.Proto/Source/RenderExtension.cs | 3 ++- 4 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 src/Luban.Job.Common/Source/Utils/TemplateUtil.cs 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