From 3cd2629f8bb1bbaf07f0e29978d9394263ca2b94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20M=C3=AD=C5=A1ek?= Date: Mon, 23 Jan 2023 14:54:54 +0100 Subject: [PATCH] AddWordPressShortcodesFromViews() - not implemented --- .../Internal/ViewsAsShortcodesPlugin.cs | 34 +++++++++++++++++++ .../ServiceCollectionExtensions.cs | 22 ++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 PeachPied.WordPress.AspNetCore/Internal/ViewsAsShortcodesPlugin.cs diff --git a/PeachPied.WordPress.AspNetCore/Internal/ViewsAsShortcodesPlugin.cs b/PeachPied.WordPress.AspNetCore/Internal/ViewsAsShortcodesPlugin.cs new file mode 100644 index 00000000..f989d9f0 --- /dev/null +++ b/PeachPied.WordPress.AspNetCore/Internal/ViewsAsShortcodesPlugin.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc.ViewComponents; +using PeachPied.WordPress.Standard; + +namespace PeachPied.WordPress.AspNetCore.Internal +{ + internal sealed class ViewsAsShortcodesPlugin : IWpPlugin, IWpPluginProvider // TODO + { + readonly IViewComponentDescriptorCollectionProvider _viewsProvider; + + public ViewsAsShortcodesPlugin(IViewComponentDescriptorCollectionProvider viewsProvider) + { + _viewsProvider = viewsProvider; + } + + ValueTask IWpPlugin.ConfigureAsync(WpApp app, CancellationToken token) + { + if (_viewsProvider != null) + { + foreach (var item in _viewsProvider.ViewComponents.Items) + { + + } + } + + return ValueTask.CompletedTask; + } + + IEnumerable IWpPluginProvider.GetPlugins(IServiceProvider provider, string wpRootPath) => new[] { this }; + } +} diff --git a/PeachPied.WordPress.AspNetCore/ServiceCollectionExtensions.cs b/PeachPied.WordPress.AspNetCore/ServiceCollectionExtensions.cs index 8f259e49..fa874764 100644 --- a/PeachPied.WordPress.AspNetCore/ServiceCollectionExtensions.cs +++ b/PeachPied.WordPress.AspNetCore/ServiceCollectionExtensions.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.DependencyInjection; using PeachPied.WordPress.AspNetCore; +using PeachPied.WordPress.AspNetCore.Internal; using PeachPied.WordPress.Standard; using System; @@ -32,5 +33,26 @@ public static IServiceCollection AddWordPress(this IServiceCollection services, // return services; } + + ///// + ///// Registers all shared views as WordPress shortcodes correspondingly. + ///// + ///// Same as configuring WordPress with for each shared view. + //public static IServiceCollection AddWordPressShortcodesFromViews(this IServiceCollection services) + //{ + // if (services == null) + // { + // throw new ArgumentNullException(nameof(services)); + // } + + // services.Add(new ServiceDescriptor( + // typeof(IWpPluginProvider), + // typeof(ViewsAsShortcodesPlugin), + // ServiceLifetime.Transient + // )); + + // // + // return services; + //} } }