Skip to content

Commit

Permalink
Liquid.Core Services (#16973)
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamco authored Jan 26, 2025
1 parent deccae0 commit 13cda4d
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 42 deletions.
16 changes: 16 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.Liquid/Manifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@
Author = ManifestConstants.OrchardCoreTeam,
Website = ManifestConstants.OrchardCoreWebsite,
Version = ManifestConstants.OrchardCoreVersion,
Category = "Content Management"
)]

[assembly: Feature(
Id = "OrchardCore.Liquid",
Name = "Liquid",
Description = "The liquid module enables content items to have liquid syntax.",
Dependencies = ["OrchardCore.Liquid.Core"],
Category = "Content Management"
)]

[assembly: Feature(
Id = "OrchardCore.Liquid.Core",
Name = "Liquid Core Services",
Description = "Provides liquid core services.",
EnabledByDependencyOnly = true,
IsAlwaysEnabled = true,
Category = "Content Management"
)]
44 changes: 42 additions & 2 deletions src/OrchardCore.Modules/OrchardCore.Liquid/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder ro

public override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<ILiquidTemplateManager, LiquidTemplateManager>();

services.Configure<TemplateOptions>(options =>
{
options.Filters.AddFilter("t", LiquidViewFilters.Localize);
Expand Down Expand Up @@ -82,6 +80,17 @@ public override void ConfigureServices(IServiceCollection services)
}
}

[Feature("OrchardCore.Liquid.Core")]
public sealed class LiquidStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<ILiquidTemplateManager, LiquidTemplateManager>();

services.AddLiquidCoreServices();
}
}

[RequireFeatures("OrchardCore.Contents")]
public sealed class LiquidPartStartup : StartupBase
{
Expand All @@ -106,3 +115,34 @@ public override void ConfigureServices(IServiceCollection services)
services.AddLiquidFilter<ShortcodeFilter>("shortcode");
}
}

[RequireFeatures("OrchardCore.Resources")]
public sealed class ResourcesStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddLiquidFilter<AppendVersionFilter>("append_version");
services.AddLiquidFilter<ResourceUrlFilter>("resource_url");
}
}

[RequireFeatures("OrchardCore.Html")]
public sealed class HtmlStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddLiquidFilter<SanitizeHtmlFilter>("sanitize_html");
}
}

[RequireFeatures("OrchardCore.Localization")]
public sealed class localizationStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
#pragma warning disable CS0618 // Type or member is obsolete
// Deprecated, remove in a future version.
services.AddLiquidFilter<SupportedCulturesFilter>("supported_cultures");
#pragma warning restore CS0618 // Type or member is obsolete
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static OrchardCoreBuilder AddOrchardCms(this IServiceCollection services)
.AddScripting()

.AddTheming()
.AddLiquidViews()
.AddGlobalFeatures("OrchardCore.Liquid.Core")
.AddCaching();

// OrchardCoreBuilder is not available in OrchardCore.ResourceManagement as it has to
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Fluid;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.AspNetCore.Mvc.Razor.Compilation;
using Microsoft.Extensions.Options;
using OrchardCore.DisplayManagement.Descriptors.ShapeTemplateStrategy;
using OrchardCore.DisplayManagement.Liquid;
using OrchardCore.DisplayManagement.Liquid.TagHelpers;
using OrchardCore.DisplayManagement.Liquid.Tags;
using OrchardCore.DisplayManagement.Razor;

namespace Microsoft.Extensions.DependencyInjection;

public static class LiquidCoreServices
{
public static IServiceCollection AddLiquidCoreServices(this IServiceCollection services)
{
services.AddSingleton<LiquidViewParser>();
services.AddSingleton<IAnchorTag, AnchorTag>();

services.AddTransient<IConfigureOptions<TemplateOptions>, TemplateOptionsFileProviderSetup>();

services.AddTransient<IConfigureOptions<LiquidViewOptions>, LiquidViewOptionsSetup>();

services.AddTransient<IConfigureOptions<ShapeTemplateOptions>, LiquidShapeTemplateOptionsSetup>();

services.AddSingleton<IApplicationFeatureProvider<ViewsFeature>, LiquidViewsFeatureProvider>();
services.AddScoped<IRazorViewExtensionProvider, LiquidViewExtensionProvider>();
services.AddSingleton<LiquidTagHelperFactory>();

services.AddSingleton<IConfigureOptions<TemplateOptions>, TemplateOptionsConfigurations>();

return services;
}
}
Original file line number Diff line number Diff line change
@@ -1,51 +1,14 @@
using Fluid;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.AspNetCore.Mvc.Razor.Compilation;
using Microsoft.Extensions.Options;
using OrchardCore.DisplayManagement.Descriptors.ShapeTemplateStrategy;
using OrchardCore.DisplayManagement.Liquid;
using OrchardCore.DisplayManagement.Liquid.Filters;
using OrchardCore.DisplayManagement.Liquid.TagHelpers;
using OrchardCore.DisplayManagement.Liquid.Tags;
using OrchardCore.DisplayManagement.Razor;
using OrchardCore.Liquid;

namespace Microsoft.Extensions.DependencyInjection;

public static class OrchardCoreBuilderExtensions
{
/// <summary>
/// Adds tenant level services for managing liquid view template files.
/// </summary>
[Obsolete("This class is deprecated and will be removed in the upcoming major release.")]
public static OrchardCoreBuilder AddLiquidViews(this OrchardCoreBuilder builder)
{
builder.ConfigureServices(services =>
{
services.AddSingleton<LiquidViewParser>();
services.AddSingleton<IAnchorTag, AnchorTag>();

services.AddTransient<IConfigureOptions<TemplateOptions>, TemplateOptionsFileProviderSetup>();

services.AddTransient<IConfigureOptions<LiquidViewOptions>, LiquidViewOptionsSetup>();

services.AddTransient<IConfigureOptions<ShapeTemplateOptions>, LiquidShapeTemplateOptionsSetup>();

services.AddSingleton<IApplicationFeatureProvider<ViewsFeature>, LiquidViewsFeatureProvider>();
services.AddScoped<IRazorViewExtensionProvider, LiquidViewExtensionProvider>();
services.AddSingleton<LiquidTagHelperFactory>();

services.AddSingleton<IConfigureOptions<TemplateOptions>, TemplateOptionsConfigurations>();


#pragma warning disable CS0618 // Type or member is obsolete
services.AddLiquidFilter<AppendVersionFilter>("append_version")
.AddLiquidFilter<ResourceUrlFilter>("resource_url")
.AddLiquidFilter<SanitizeHtmlFilter>("sanitize_html")

// Deprecated, remove in a future version.
.AddLiquidFilter<SupportedCulturesFilter>("supported_cultures");
#pragma warning restore CS0618 // Type or member is obsolete
});
builder.ConfigureServices(services => services.AddLiquidCoreServices());

return builder;
}
Expand Down

0 comments on commit 13cda4d

Please sign in to comment.