Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamco committed Dec 1, 2023
1 parent eb1105b commit 5fcaa5a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
12 changes: 12 additions & 0 deletions src/OrchardCoreContrib.Liquid/Environment.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
5 changes: 0 additions & 5 deletions src/OrchardCoreContrib.Liquid/LiquidEnvironmentAccessor.cs

This file was deleted.

23 changes: 10 additions & 13 deletions src/OrchardCoreContrib.Liquid/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,18 @@ public Startup(IHostEnvironment hostEnvironment)

public override void ConfigureServices(IServiceCollection services)
{
services.Configure<TemplateOptions>(o =>
var environment = new Environment
{
o.Scope.SetValue("Environment", new ObjectValue(new LiquidEnvironmentAccessor()));
o.MemberAccessStrategy.Register<LiquidEnvironmentAccessor, FluidValue>((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<TemplateOptions>(options =>
{
options.Scope.SetValue("Environment", new ObjectValue(environment));
options.MemberAccessStrategy.Register<Environment>();
});
}
}

0 comments on commit 5fcaa5a

Please sign in to comment.