-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Startup.cs
107 lines (95 loc) · 4.28 KB
/
Startup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Text.Json.Dynamic;
using System.Text.Json.Nodes;
using Fluid;
using Fluid.Values;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Display.ContentDisplay;
using OrchardCore.Data.Migration;
using OrchardCore.DisplayManagement.Descriptors;
using OrchardCore.DisplayManagement.Liquid.Filters;
using OrchardCore.Indexing;
using OrchardCore.Liquid.Drivers;
using OrchardCore.Liquid.Filters;
using OrchardCore.Liquid.Handlers;
using OrchardCore.Liquid.Indexing;
using OrchardCore.Liquid.Models;
using OrchardCore.Liquid.Services;
using OrchardCore.Liquid.ViewModels;
using OrchardCore.Modules;
using OrchardCore.ResourceManagement;
namespace OrchardCore.Liquid
{
public class Startup : StartupBase
{
public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
{
app.UseMiddleware<ScriptsMiddleware>();
}
public override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<ILiquidTemplateManager, LiquidTemplateManager>();
services.Configure<TemplateOptions>(options =>
{
options.Filters.AddFilter("t", LiquidViewFilters.Localize);
options.Filters.AddFilter("html_class", LiquidViewFilters.HtmlClass);
options.Filters.AddFilter("shape_properties", LiquidViewFilters.ShapeProperties);
options.MemberAccessStrategy.Register<LiquidPartViewModel>();
// Used to provide a factory to return a value based on a property name that is unknown at registration time.
options.MemberAccessStrategy.Register<LiquidPropertyAccessor, FluidValue>((obj, name) => obj.GetValueAsync(name));
// When a property of a 'JsonObject' value is accessed, try to look into its properties.
options.MemberAccessStrategy.Register<JsonObject, object>((source, name) => source[name]);
// Convert JToken to FluidValue
options.ValueConverters.Add(x =>
{
return x switch
{
JsonObject o => new ObjectValue(o),
JsonDynamicObject o => new ObjectValue((JsonObject)o),
JsonValue o => o.GetObjectValue(),
DateTime d => new ObjectValue(d),
_ => null
};
});
options.Filters.AddFilter("json", JsonFilter.Json);
options.Filters.AddFilter("jsonparse", JsonParseFilter.JsonParse);
})
.AddLiquidFilter<LocalTimeZoneFilter>("local")
.AddLiquidFilter<UtcTimeZoneFilter>("utc")
.AddLiquidFilter<SlugifyFilter>("slugify")
.AddLiquidFilter<LiquidFilter>("liquid")
.AddLiquidFilter<ContentUrlFilter>("href")
.AddLiquidFilter<AbsoluteUrlFilter>("absolute_url")
.AddLiquidFilter<NewShapeFilter>("shape_new")
.AddLiquidFilter<ShapeRenderFilter>("shape_render")
.AddLiquidFilter<ShapeStringifyFilter>("shape_stringify");
services.AddTransient<IConfigureOptions<ResourceManagementOptions>, ResourceManagementOptionsConfiguration>();
}
}
[RequireFeatures("OrchardCore.Contents")]
public class LiquidPartStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
// Liquid Part
services.AddScoped<IShapeTableProvider, LiquidShapes>();
services.AddContentPart<LiquidPart>()
.UseDisplayDriver<LiquidPartDisplayDriver>()
.AddHandler<LiquidPartHandler>();
services.AddDataMigration<Migrations>();
services.AddScoped<IContentPartIndexHandler, LiquidPartIndexHandler>();
}
}
[RequireFeatures("OrchardCore.Shortcodes")]
public class ShortcodesStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddLiquidFilter<ShortcodeFilter>("shortcode");
}
}
}