From 5fcaa5ad2dfb63591b07f2a02dc59027826c0e52 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sat, 2 Dec 2023 01:02:42 +0300 Subject: [PATCH] Address feedback --- src/OrchardCoreContrib.Liquid/Environment.cs | 12 ++++++++++ .../LiquidEnvironmentAccessor.cs | 5 ---- src/OrchardCoreContrib.Liquid/Startup.cs | 23 ++++++++----------- 3 files changed, 22 insertions(+), 18 deletions(-) create mode 100644 src/OrchardCoreContrib.Liquid/Environment.cs delete mode 100644 src/OrchardCoreContrib.Liquid/LiquidEnvironmentAccessor.cs diff --git a/src/OrchardCoreContrib.Liquid/Environment.cs b/src/OrchardCoreContrib.Liquid/Environment.cs new file mode 100644 index 0000000..e5668b4 --- /dev/null +++ b/src/OrchardCoreContrib.Liquid/Environment.cs @@ -0,0 +1,12 @@ +using Fluid.Values; + +namespace OrchardCoreContrib.Liquid; + +public class Environment +{ + public BooleanValue IsDevelopment { get; set; } + + public BooleanValue IsStaging { get; set; } + + public BooleanValue IsProduction { get; set; } +} diff --git a/src/OrchardCoreContrib.Liquid/LiquidEnvironmentAccessor.cs b/src/OrchardCoreContrib.Liquid/LiquidEnvironmentAccessor.cs deleted file mode 100644 index aecbb62..0000000 --- a/src/OrchardCoreContrib.Liquid/LiquidEnvironmentAccessor.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace OrchardCoreContrib.Liquid; - -public class LiquidEnvironmentAccessor -{ -} diff --git a/src/OrchardCoreContrib.Liquid/Startup.cs b/src/OrchardCoreContrib.Liquid/Startup.cs index dc6d66e..0e66b4c 100644 --- a/src/OrchardCoreContrib.Liquid/Startup.cs +++ b/src/OrchardCoreContrib.Liquid/Startup.cs @@ -16,21 +16,18 @@ public Startup(IHostEnvironment hostEnvironment) public override void ConfigureServices(IServiceCollection services) { - services.Configure(o => + var environment = new Environment { - o.Scope.SetValue("Environment", new ObjectValue(new LiquidEnvironmentAccessor())); - o.MemberAccessStrategy.Register((obj, name, context) => - { - FluidValue result = name switch - { - "IsDevelopment" => BooleanValue.Create(_hostEnvironment.IsDevelopment()), - "IsStaging" => BooleanValue.Create(_hostEnvironment.IsStaging()), - "IsProduction" => BooleanValue.Create(_hostEnvironment.IsProduction()), - _ => NilValue.Instance - }; + IsDevelopment = BooleanValue.Create(_hostEnvironment.IsDevelopment()), + IsStaging = BooleanValue.Create(_hostEnvironment.IsStaging()), + IsProduction = BooleanValue.Create(_hostEnvironment.IsProduction()) + }; - return result; - }); + services.Configure(options => + { + options.Scope.SetValue("Environment", new ObjectValue(environment)); + + options.MemberAccessStrategy.Register(); }); } }